Difference: CS255Part2 (6 vs. 7)

Revision 72008-02-07 - XiaomingGu

Line: 1 to 1
 
META TOPICPARENT name="ProjectHome"
  • Reverse all printf, scanf, and __builtin_puts statements in a basic block. If there are k such statements in a basic block, the first statement will be switched with the last statement, the second statement will be switched with the (k-1)th statement, and so on.
  • If the statement is a conditional branch in the form of if cond goto L1; else goto L2, interchange the two branches to if cond goto L2; else goto L1. Alternatively, you can change it to if (not cond) goto L1; else goto L2.
Line: 29 to 29
 }
Deleted:
<
<
Gimple tree before cs255 pass

main ()
{
  int b;
  int a;

<bb 2>:
  __builtin_puts (&"Input two integers for comparison"[0]);
  scanf (&"%d"[0], &a);
  scanf (&"%d"[0], &b);
  printf (&"a is %d\n"[0], a);
  printf (&"b is %d\n"[0], b);
  if (a > b) goto <L0>; else goto <L1>;

<L0>:;
  __builtin_puts (&"a is greater than b"[0]);
  goto <bb 5> (<L2>);

<L1>:;
  __builtin_puts (&"a is no greater than b"[0]);

<L2>:;
  return;

}

Gimple tree after cs255 pass

main ()
{
  int b;
  int a;

<bb 2>:
  __builtin_puts (&"Input two integers for comparison"[0]);
  printf (&"b is %d\n"[0], b);
  printf (&"a is %d\n"[0], a);
  scanf (&"%d"[0], &b);
  scanf (&"%d"[0], &a);
  if (a <= b) goto <L1>; else goto <L0>;

<L0>:;
  __builtin_puts (&"a is greater than b"[0]);
  goto <bb 5> (<L2>);

<L1>:;
  __builtin_puts (&"a is no greater than b"[0]);

<L2>:;
  return;

}
  Program 2: loop.c
Line: 101 to 44
 }
Deleted:
<
<
Gimple tree before cs255 pass

main ()
{
  int n;
  int s;
  int i;
  int n.0;

<bb 2>:
  __builtin_puts (&"Input an integer for sum"[0]);
  scanf (&"%d"[0], &n);
  n.0 = n;
  if (n.0 >= 0) goto <L13>; else goto <L14>;

<L14>:;
  s = 0;
  goto <bb 4> (<L2>);

<L13>:;
  i = 0;
  s = 0;

<L0>:;
  s = s + i;
  i = i + 1;
  if (i != (int) ((unsigned int) n.0 + 1)) goto <L0>; else goto <L2>;

<L2>:;
  printf (&"The sum from 1 to %d is %d\n"[0], n.0, s);
  return;

}

Gimple tree after cs255 pass

main ()
{
  int n;
  int s;
  int i;
  int n.0;

<bb 2>:
  __builtin_puts (&"Input an integer for sum"[0]);
  scanf (&"%d"[0], &n);
  n.0 = n;
  if (n.0 < 0) goto <L14>; else goto <L13>;

<L14>:;
  s = 0;
  goto <bb 4> (<L2>);

<L13>:;
  i = 0;
  s = 0;

<L0>:;
  s = s + i;
  i = i - 1;
  if (i == (int) ((unsigned int) n.0 + 1)) goto <L2>; else goto <L0>;

<L2>:;
  printf (&"The sum from 1 to %d is %d\n"[0], n.0, s);
  return;

}
  -- XiaomingGu - 02 Feb 2008
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding URCS? Send feedback