#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int x = 100;
  int i = 1;
  printf("First loop\n");
  while (x > 0) {
    i = 2 * i;
    x = x - i;
  }
  printf("x = %d, i = %d\n", x, i);
  printf("\nSecond (infinite) loop...");
  fflush(stdout);
  while (1) {
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1173 <main+0x53>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <main+0x32>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
jmp    11a3 <main+0x83>

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xef3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x64,%esi
mov    $0x1,%edx
nopw   0x0(%rax,%rax,1)
add    %edx,%edx
sub    %edx,%esi
jg     1150 <main+0x20>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    1180 <main+0x50>

LLVM IR (-O0):
@.str = [12 x i8] c"First loop\0A\00"
@.str.1 = [16 x i8] c"x = %d, i = %d\0A\00"
@.str.2 = [27 x i8] c"\0ASecond (infinite) loop...\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 100, i32* %6
store i32 1, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %12, %2
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i32, i32* %7
%14 = mul nsw i32 2, %13
store i32 %14, i32* %7
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = sub nsw i32 %15, %16
store i32 %17, i32* %6
br label %9
18: ; preds = %9
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
br label %25
25: ; preds = %18, %25
br label %25
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"x = %d, i = %d\0A\00"
@.str.2 = [27 x i8] c"\0ASecond (infinite) loop...\00"
@stdout = global i32 0
@str = [11 x i8] c"First loop\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %2, %4
%5 = phi i32 [ 1, %2 ], [ %7, %4 ]
%6 = phi i32 [ 100, %2 ], [ %8, %4 ]
%7 = shl nsw i32 %5, 1
%8 = sub nsw i32 %6, %7
%9 = icmp sgt i32 %8, 0
br i1 %9, label %4, label %10
10: ; preds = %4
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %7)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @stdout
%14 = tail call i32 @fflush(i32 %13)
br label %15
15: ; preds = %15, %10
br label %15
}