Flow of Control

Before getting into flow of control issues, one of the statements in our grammar looks like:
input ( arglist );
Q1: If x and y are integer variables, what is the result of running the following program segment if 1 and 2 are entered at the keyboard?
main ()
{
  int x, y;

  input (&x, &y);
  output (x, y);
}

 1  27   0   0   0   0   0   0
2 22 0 4 0 0 0 0
2 26 3 1 0 0 3 3
2 26 3 2 0 0 3 4
2 20 4 4 0 0 0 0
2 20 4 3 0 0 0 0
2 24 0 2 0 0 0 0
2 20 4 2 0 0 0 0
2 20 4 1 0 0 0 0
2 25 0 2 0 0 0 0
2 26 0 0 0 0 1 0
2 23 0 0 0 0 0 0
1 21 0 0 0 0 0 1
1 28 0 0 0 0 0 0
1
0

Q2: How do things change if the input statement becomes input (x, y);

Q3: What is short-circuit code?

Q4: Does gcc use short-circuit code?

Q5: What would be the result from running each of the following C programs? Why?

/* gcc version */
#include <stdio.h>
main()
{
  int i = 0,j = 0;
  if (i && j && (j = j + 1))
    i++;
  printf ("%d %d\n", i, j);
}

/* pcc version */
main()
{
  int i = 0,j = 0;
  if (i && j && (j = j + 1))
    i++;
  output (i, j);
}
What about compiling the following?
 
/* pcc version */
main()
{
  int i = 0,j = 0;
  if (i && j && (j = j + 1))
    i++;
  output (i, j);
}
Let's take a look at the code generation and production/semantic action rules for the following flow-of-control statements on pp. 492-3: We don't have while statements, but we do have for statements. The flow-of-control for a for is not that different. Consider:
main()
{
  int i, sum = 0;
  for (i = 0; i <= 5; i = i + 1)
  {
    sum = sum + i;
  }
  output (i, sum);
}
 1  27   0   0   0   0   0   0
 2  22   0   5   0   0   0   0
 2  26   2   1   0   0   3   2
 2  26   2   1   0   0   3   1
 2  12   4   1   2   2   0   7
 2  26   0   0   0   0   3   3
 2  19   0   0   0   0   0   8
 2  26   0   1   0   0   3   3
 2  18   4   3   0   0   0  16
 2  19   0   0   0   0   0  13
 2   1   4   1   2   3   3   4
 2  26   4   4   0   0   3   1
 2  19   0   0   0   0   0   4
 2   1   4   2   4   1   3   5
 2  26   4   5   0   0   3   2
 2  19   0   0   0   0   0  10
 2  20   4   2   0   0   0   0
 2  20   4   1   0   0   0   0
 2  25   0   2   0   0   0   0
 2  26   0   0   0   0   1   0
 2  23   0   0   0   0   0   0
 1  21   0   0   0   0   0   1
 1  28   0   0   0   0   0   0
4
0
0
5
1

/* gcc version */
#include <stdio.h>
main()
{
  int i, sum = 0;
  for (i = 0; i <= 5; i = i + 1)
  {
    sum = sum + i;
  }
  printf ("%d %d\n", i, sum);
}

        .file   "z.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "%d %d\n"
        .text
.globl main
        .type   main, @function
main:
        pushl   %ebp
        xorl    %edx, %edx
        movl    %esp, %ebp
        xorl    %eax, %eax
.L5:
        addl    %eax, %edx
        incl    %eax
        cmpl    $5, %eax
        jle     .L5
        pushl   %edx
        pushl   $6
        pushl   $.LC0
        call    printf
        leave
        ret
        .size   main, .-main
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)"