#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 i, a, b;
  if (foo())
    return 0;
  for (i = 0, a = 0, b = 0; i < 3; i++, a++) {
    if (foo())
      break;
    if (b += a)
      a = 0;
  }
  if (!a)
    return 2;
  b += a;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <foo@plt>
cmp    $0x0,%rax
je     113c <main+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    11cc <main+0xbc>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a6 <main+0x96>
mov    $0x0,%al
call   1030 <foo@plt>
cmp    $0x0,%rax
je     1171 <main+0x61>
jmp    11a6 <main+0x96>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     118a <main+0x7a>
movl   $0x0,-0xc(%rbp)
jmp    118f <main+0x7f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1151 <main+0x41>
cmpl   $0x0,-0xc(%rbp)
jne    11bc <main+0xac>
movl   $0x2,-0x4(%rbp)
jmp    11cc <main+0xbc>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <foo@plt>
test   %rax,%rax
jne    114a <main+0x3a>
xor    %eax,%eax
call   1030 <foo@plt>
mov    $0x2,%ebx
test   %rax,%rax
jne    114a <main+0x3a>
xor    %eax,%eax
call   1030 <foo@plt>
mov    $0x0,%ebx
test   %rax,%rax
jne    114a <main+0x3a>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <foo@plt>
mov    %ebx,%eax
pop    %rbx
ret

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

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