#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*/ print_int(int);
int /*<<< orphan*/ print_string(char *);
void main(void) {
  int x;
  print_string("should get: 123\ngot: ");
  for (x = 1; x < 4; x = x + 1)
    print_int(x);
  print_string("\n\n");
  print_string("should get: 4321\ngot: ");
  for (; x > 0; x = x - 1) {
    print_int(x);
  }
  print_string("\n\n");
  print_string("should get: 123\ngot: ");
  for (x = 1; x < 4;) {
    print_int(x);
    x = x + 1;
  }
  print_string("\n\n");
  print_string("should get: 1234\ngot: ");
  for (x = 1;; x = x + 1) {
    print_int(x);
    if (x == 4)
      return;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1030 <print_string@plt>
movl   $0x1,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
jge    115b <main+0x3b>
mov    -0x4(%rbp),%edi
call   1040 <print_int@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    113b <main+0x1b>
lea    0xeb4(%rip),%rdi
call   1030 <print_string@plt>
lea    0xeab(%rip),%rdi
call   1030 <print_string@plt>
cmpl   $0x0,-0x4(%rbp)
jle    1193 <main+0x73>
mov    -0x4(%rbp),%edi
call   1040 <print_int@plt>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1173 <main+0x53>
lea    0xe7c(%rip),%rdi
call   1030 <print_string@plt>
lea    0xe5a(%rip),%rdi
call   1030 <print_string@plt>
movl   $0x1,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
jge    11d2 <main+0xb2>
mov    -0x4(%rbp),%edi
call   1040 <print_int@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11b2 <main+0x92>
lea    0xe3d(%rip),%rdi
call   1030 <print_string@plt>
lea    0xe4b(%rip),%rdi
call   1030 <print_string@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <print_int@plt>
cmpl   $0x4,-0x4(%rbp)
jne    1209 <main+0xe9>
add    $0x10,%rsp
pop    %rbp
ret
jmp    120e <main+0xee>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <main+0xd1>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%r14
mov    %r14,%rdi
call   1030 <print_string@plt>
mov    $0x1,%edi
call   1040 <print_int@plt>
mov    $0x2,%edi
call   1040 <print_int@plt>
mov    $0x3,%edi
call   1040 <print_int@plt>
lea    0xebe(%rip),%rbx
mov    %rbx,%rdi
call   1030 <print_string@plt>
lea    0xeb2(%rip),%rdi
call   1030 <print_string@plt>
mov    $0x4,%edi
call   1040 <print_int@plt>
mov    $0x3,%edi
call   1040 <print_int@plt>
mov    $0x2,%edi
call   1040 <print_int@plt>
mov    $0x1,%edi
call   1040 <print_int@plt>
mov    %rbx,%rdi
call   1030 <print_string@plt>
mov    %r14,%rdi
call   1030 <print_string@plt>
mov    $0x1,%edi
call   1040 <print_int@plt>
mov    $0x2,%edi
call   1040 <print_int@plt>
mov    $0x3,%edi
call   1040 <print_int@plt>
mov    %rbx,%rdi
call   1030 <print_string@plt>
lea    0xe5f(%rip),%rdi
call   1030 <print_string@plt>
mov    $0x1,%edi
call   1040 <print_int@plt>
mov    $0x2,%edi
call   1040 <print_int@plt>
mov    $0x3,%edi
call   1040 <print_int@plt>
mov    $0x4,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <print_int@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"should get: 123\0Agot: \00"
@.str.1 = [3 x i8] c"\0A\0A\00"
@.str.2 = [23 x i8] c"should get: 4321\0Agot: \00"
@.str.3 = [23 x i8] c"should get: 1234\0Agot: \00"
define void @main() {
%1 = alloca i32
%2 = call i32 @print_string(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %3
3: ; preds = %9, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 4
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = load i32, i32* %1
%8 = call i32 @print_int(i32 %7)
br label %9
9: ; preds = %6
%10 = load i32, i32* %1
%11 = add nsw i32 %10, 1
store i32 %11, i32* %1
br label %3
12: ; preds = %3
%13 = call i32 @print_string(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @print_string(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %21, %12
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32, i32* %1
%20 = call i32 @print_int(i32 %19)
br label %21
21: ; preds = %18
%22 = load i32, i32* %1
%23 = sub nsw i32 %22, 1
store i32 %23, i32* %1
br label %15
24: ; preds = %15
%25 = call i32 @print_string(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @print_string(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %27
27: ; preds = %30, %24
%28 = load i32, i32* %1
%29 = icmp slt i32 %28, 4
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* %1
%32 = call i32 @print_int(i32 %31)
%33 = load i32, i32* %1
%34 = add nsw i32 %33, 1
store i32 %34, i32* %1
br label %27
35: ; preds = %27
%36 = call i32 @print_string(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @print_string(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %38
38: ; preds = %45, %35
%39 = load i32, i32* %1
%40 = call i32 @print_int(i32 %39)
%41 = load i32, i32* %1
%42 = icmp eq i32 %41, 4
br i1 %42, label %43, label %44
43: ; preds = %38
ret void
44: ; preds = %38
br label %45
45: ; preds = %44
%46 = load i32, i32* %1
%47 = add nsw i32 %46, 1
store i32 %47, i32* %1
br label %38
}

LLVM IR (-O2):
@.str = [22 x i8] c"should get: 123\0Agot: \00"
@.str.1 = [3 x i8] c"\0A\0A\00"
@.str.2 = [23 x i8] c"should get: 4321\0Agot: \00"
@.str.3 = [23 x i8] c"should get: 1234\0Agot: \00"
define void @main() {
%1 = tail call i32 @print_string(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @print_int(i32 1)
%3 = tail call i32 @print_int(i32 2)
%4 = tail call i32 @print_int(i32 3)
%5 = tail call i32 @print_string(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @print_string(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @print_int(i32 4)
%8 = tail call i32 @print_int(i32 3)
%9 = tail call i32 @print_int(i32 2)
%10 = tail call i32 @print_int(i32 1)
%11 = tail call i32 @print_string(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @print_string(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @print_int(i32 1)
%14 = tail call i32 @print_int(i32 2)
%15 = tail call i32 @print_int(i32 3)
%16 = tail call i32 @print_string(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @print_string(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 @print_int(i32 1)
%19 = tail call i32 @print_int(i32 2)
%20 = tail call i32 @print_int(i32 3)
%21 = tail call i32 @print_int(i32 4)
ret void
}