#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 */
scalar_t__ foo();
int main(void) {
  int a = -100;
  int b = 2;
  int c = 3;
  int d = 4;
  while (d) {
    if (foo())
      a += b;
    else
      a += c;
    b += 1;
    c += 5;
    d = d + a;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffff9c,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0x3,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118d <main+0x7d>
mov    $0x0,%al
call   1030 <foo@plt>
cmp    $0x0,%rax
je     1164 <main+0x54>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    116d <main+0x5d>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    113b <main+0x2b>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffff9c,%ebx
mov    $0x2,%r14d
mov    $0x3,%ebp
mov    $0x4,%r15d
jmp    113e <main+0x2e>
nop
add    %ecx,%ebx
add    $0x1,%r14d
add    $0x5,%ebp
add    %ebx,%r15d
je     1151 <main+0x41>
xor    %eax,%eax
call   1030 <foo@plt>
mov    %ebp,%ecx
test   %rax,%rax
je     1130 <main+0x20>
mov    %r14d,%ecx
jmp    1130 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 -100, i32* %2
store i32 2, i32* %3
store i32 3, i32* %4
store i32 4, i32* %5
br label %6
6: ; preds = %20, %0
%7 = load i32, i32* %5
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = call i64 (...) @foo()
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = add nsw i32 %14, %13
store i32 %15, i32* %2
br label %20
16: ; preds = %9
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = add nsw i32 %18, %17
store i32 %19, i32* %2
br label %20
20: ; preds = %16, %12
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 5
store i32 %24, i32* %4
%25 = load i32, i32* %5
%26 = load i32, i32* %2
%27 = add nsw i32 %25, %26
store i32 %27, i32* %5
br label %6
28: ; preds = %6
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 4, %0 ], [ %12, %1 ]
%3 = phi i32 [ 3, %0 ], [ %11, %1 ]
%4 = phi i32 [ 2, %0 ], [ %10, %1 ]
%5 = phi i32 [ -100, %0 ], [ %9, %1 ]
%6 = tail call i64 (...) @foo()
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i32 %3, i32 %4
%9 = add nsw i32 %8, %5
%10 = add nuw nsw i32 %4, 1
%11 = add nuw nsw i32 %3, 5
%12 = add nsw i32 %9, %2
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %1
14: ; preds = %1
ret i32 0
}