#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ block(char *);
int /*<<< orphan*/ emitln(char *, ...);
int /*<<< orphan*/ expression();
char getName();
int /*<<< orphan*/ match(char);
int /*<<< orphan*/ newLabel(char *);
int /*<<< orphan*/ postLabel(char *, char *);
void doFor() {
  char label1[10];
  char label2[10];
  char label3[10];
  char name;
  match('f');
  newLabel(label1);
  newLabel(label2);
  newLabel(label3);
  name = getName();
  match('=');
  emitln("#FOR");
  expression();
  emitln("MOV\t%%eax,%c", name);
  expression();
  emitln("PUSH\t%%eax\t#Put upper limit on stack");
  emitln("JMP\t%s", label2);
  postLabel(label1, "#beginning of FOR block");
  block(label3);
  match('e');
  emitln("LEAL\t%c,%%eax", name);
  emitln("INCL\t(%%eax)");
  emitln("MOV\t(%%eax),%%eax");
  postLabel(label2, "#test at ENDFOR");
  emitln("CMP\t(%%esp),%%eax");
  emitln("JLE\t%s", label1);
  postLabel(label3, "#break address for FOR loop");
  emitln("ADDL\t$4,%%esp #Get upper limit off of stack");
  emitln("#ENDFOR");
}


x86 assembly (clang, -O0):
<doFor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x66,%edi
call   1070 <match@plt>
lea    -0xa(%rbp),%rdi
call   1050 <newLabel@plt>
lea    -0x14(%rbp),%rdi
call   1050 <newLabel@plt>
lea    -0x1e(%rbp),%rdi
call   1050 <newLabel@plt>
mov    $0x0,%al
call   1080 <getName@plt>
mov    %al,-0x1f(%rbp)
mov    $0x3d,%edi
call   1070 <match@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
mov    $0x0,%al
call   1060 <expression@plt>
movsbl -0x1f(%rbp),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
mov    $0x0,%al
call   1060 <expression@plt>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
lea    -0x14(%rbp),%rsi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
lea    -0xa(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1040 <postLabel@plt>
lea    -0x1e(%rbp),%rdi
call   1090 <block@plt>
mov    $0x65,%edi
call   1070 <match@plt>
movsbl -0x1f(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
lea    -0x14(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1040 <postLabel@plt>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
lea    -0xa(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
lea    -0x1e(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1040 <postLabel@plt>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <emitln@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doFor>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    $0x66,%edi
call   1070 <match@plt>
lea    0x16(%rsp),%r14
mov    %r14,%rdi
call   1050 <newLabel@plt>
lea    0xc(%rsp),%r12
mov    %r12,%rdi
call   1050 <newLabel@plt>
lea    0x2(%rsp),%r15
mov    %r15,%rdi
call   1050 <newLabel@plt>
xor    %eax,%eax
call   1080 <getName@plt>
mov    %eax,%ebx
mov    $0x3d,%edi
call   1070 <match@plt>
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1030 <emitln@plt>
xor    %eax,%eax
call   1060 <expression@plt>
movsbl %bl,%ebp
lea    0xe26(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <emitln@plt>
xor    %eax,%eax
call   1060 <expression@plt>
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
call   1030 <emitln@plt>
lea    0xe33(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <emitln@plt>
lea    0xe29(%rip),%rsi
mov    %r14,%rdi
call   1040 <postLabel@plt>
mov    %r15,%rdi
call   1090 <block@plt>
mov    $0x65,%edi
call   1070 <match@plt>
lea    0xe20(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <emitln@plt>
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1030 <emitln@plt>
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1030 <emitln@plt>
lea    0xe21(%rip),%rsi
mov    %r12,%rdi
call   1040 <postLabel@plt>
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1030 <emitln@plt>
lea    0xe26(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <emitln@plt>
lea    0xe1c(%rip),%rsi
mov    %r15,%rdi
call   1040 <postLabel@plt>
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1030 <emitln@plt>
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1030 <emitln@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"#FOR\00"
@.str.1 = [13 x i8] c"MOV\09%%eax,%c\00"
@.str.2 = [37 x i8] c"PUSH\09%%eax\09#Put upper limit on stack\00"
@.str.3 = [7 x i8] c"JMP\09%s\00"
@.str.4 = [24 x i8] c"#beginning of FOR block\00"
@.str.5 = [14 x i8] c"LEAL\09%c,%%eax\00"
@.str.6 = [13 x i8] c"INCL\09(%%eax)\00"
@.str.7 = [18 x i8] c"MOV\09(%%eax),%%eax\00"
@.str.8 = [16 x i8] c"#test at ENDFOR\00"
@.str.9 = [18 x i8] c"CMP\09(%%esp),%%eax\00"
@.str.10 = [7 x i8] c"JLE\09%s\00"
@.str.11 = [28 x i8] c"#break address for FOR loop\00"
@.str.12 = [44 x i8] c"ADDL\09$4,%%esp #Get upper limit off of stack\00"
@.str.13 = [8 x i8] c"#ENDFOR\00"
define void @doFor() {
%1 = alloca [10 x i8]
%2 = alloca [10 x i8]
%3 = alloca [10 x i8]
%4 = alloca i8
%5 = call i32 @match(i8 signext 102)
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%7 = call i32 @newLabel(i8* %6)
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%9 = call i32 @newLabel(i8* %8)
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%11 = call i32 @newLabel(i8* %10)
%12 = call signext i8 (...) @getName()
store i8 %12, i8* %4
%13 = call i32 @match(i8 signext 61)
%14 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (...) @expression()
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = call i32 (...) @expression()
%20 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%22 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%24 = call i32 @postLabel(i8* %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%26 = call i32 @block(i8* %25)
%27 = call i32 @match(i8 signext 101)
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%34 = call i32 @postLabel(i8* %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%35 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%37 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%39 = call i32 @postLabel(i8* %38, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0))
%40 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0))
%41 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"#FOR\00"
@.str.1 = [13 x i8] c"MOV\09%%eax,%c\00"
@.str.2 = [37 x i8] c"PUSH\09%%eax\09#Put upper limit on stack\00"
@.str.3 = [7 x i8] c"JMP\09%s\00"
@.str.4 = [24 x i8] c"#beginning of FOR block\00"
@.str.5 = [14 x i8] c"LEAL\09%c,%%eax\00"
@.str.6 = [13 x i8] c"INCL\09(%%eax)\00"
@.str.7 = [18 x i8] c"MOV\09(%%eax),%%eax\00"
@.str.8 = [16 x i8] c"#test at ENDFOR\00"
@.str.9 = [18 x i8] c"CMP\09(%%esp),%%eax\00"
@.str.10 = [7 x i8] c"JLE\09%s\00"
@.str.11 = [28 x i8] c"#break address for FOR loop\00"
@.str.12 = [44 x i8] c"ADDL\09$4,%%esp #Get upper limit off of stack\00"
@.str.13 = [8 x i8] c"#ENDFOR\00"
define void @doFor() {
%1 = alloca [10 x i8]
%2 = alloca [10 x i8]
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @match(i8 signext 102)
%8 = call i32 @newLabel(i8* %4)
%9 = call i32 @newLabel(i8* %5)
%10 = call i32 @newLabel(i8* %6)
%11 = call signext i8 (...) @getName()
%12 = call i32 @match(i8 signext 61)
%13 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (...) @expression()
%15 = sext i8 %11 to i32
%16 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 (...) @expression()
%18 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%20 = call i32 @postLabel(i8* %4, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @block(i8* %6)
%22 = call i32 @match(i8 signext 101)
%23 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %15)
%24 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%25 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%26 = call i32 @postLabel(i8* %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%27 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%28 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8* %4)
%29 = call i32 @postLabel(i8* %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0))
%30 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0))
%31 = call i32 (i8*, ...) @emitln(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0))
ret void
}