#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*/ printf(char *, int);
int main() {
  int i, j, k;
  int sum = 0;
  int factor = 1;
  int sum2 = 0;
  for (i = 0; i <= 100; i++) {
    sum = sum + i;
  }
  printf("for:sum = %d\n", sum);
  j = 10;
  while (j > 0) {
    factor = factor * j;
    j--;
  }
  printf("while:factor = %d\n", factor);
  k = 100;
  do {
    if (k / 2 == (k + 1) / 2) {
      sum2 = sum2 + k;
    }
    k--;
  } while (k > 0);
  printf("do while:sum2 = %d\n", sum2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jg     115c <main+0x4c>
mov    -0x14(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113b <main+0x2b>
mov    -0x14(%rbp),%esi
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
movl   $0xa,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1194 <main+0x84>
mov    -0x18(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1172 <main+0x62>
mov    -0x18(%rbp),%esi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
movl   $0x64,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jne    11dc <main+0xcc>
mov    -0x1c(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     11aa <main+0x9a>
mov    -0x1c(%rbp),%esi
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0x13ba,%esi
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
mov    $0x375f00,%esi
call   1030 <printf@plt>
lea    0xee7(%rip),%rdi
mov    $0x9f6,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"for:sum = %d\0A\00"
@.str.1 = [19 x i8] c"while:factor = %d\0A\00"
@.str.2 = [20 x i8] c"do while:sum2 = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 1, i32* %6
store i32 0, i32* %7
store i32 0, i32* %2
br label %8
8: ; preds = %15, %0
%9 = load i32, i32* %2
%10 = icmp sle i32 %9, 100
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* %5
%13 = load i32, i32* %2
%14 = add nsw i32 %12, %13
store i32 %14, i32* %5
br label %15
15: ; preds = %11
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %8
18: ; preds = %8
%19 = load i32, i32* %5
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 10, i32* %3
br label %21
21: ; preds = %24, %18
%22 = load i32, i32* %3
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* %6
%26 = load i32, i32* %3
%27 = mul nsw i32 %25, %26
store i32 %27, i32* %6
%28 = load i32, i32* %3
%29 = add nsw i32 %28, -1
store i32 %29, i32* %3
br label %21
30: ; preds = %21
%31 = load i32, i32* %6
%32 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %31)
store i32 100, i32* %4
br label %33
33: ; preds = %47, %30
%34 = load i32, i32* %4
%35 = sdiv i32 %34, 2
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
%38 = sdiv i32 %37, 2
%39 = icmp eq i32 %35, %38
br i1 %39, label %40, label %44
40: ; preds = %33
%41 = load i32, i32* %7
%42 = load i32, i32* %4
%43 = add nsw i32 %41, %42
store i32 %43, i32* %7
br label %44
44: ; preds = %40, %33
%45 = load i32, i32* %4
%46 = add nsw i32 %45, -1
store i32 %46, i32* %4
br label %47
47: ; preds = %44
%48 = load i32, i32* %4
%49 = icmp sgt i32 %48, 0
br i1 %49, label %33, label %50
50: ; preds = %47
%51 = load i32, i32* %7
%52 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"for:sum = %d\0A\00"
@.str.1 = [19 x i8] c"while:factor = %d\0A\00"
@.str.2 = [20 x i8] c"do while:sum2 = %d\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 5050)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 3628800)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 2550)
ret i32 0
}