#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__ child3();
scalar_t__ child4();
scalar_t__ child5();
int foo2() {
  int a = 0;
  int ii;
  for (ii = 0; ii < 2; ++ii) {
    a += child3();
    a += child4();
    a += child5();
  }
  return a;
}


x86 assembly (clang, -O0):
<foo2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119a <foo2+0x6a>
mov    $0x0,%al
call   1040 <child3@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1050 <child4@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <child5@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <foo2+0x16>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo2>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <child3@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <child4@plt>
mov    %rax,%rbx
add    %r14d,%ebx
xor    %eax,%eax
call   1030 <child5@plt>
mov    %rax,%r14
add    %ebx,%r14d
xor    %eax,%eax
call   1040 <child3@plt>
mov    %rax,%rbx
add    %r14d,%ebx
xor    %eax,%eax
call   1050 <child4@plt>
mov    %rax,%r14
add    %ebx,%r14d
xor    %eax,%eax
call   1030 <child5@plt>
add    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @foo2() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %22, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 2
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = call i64 (...) @child3()
%8 = load i32, i32* %1
%9 = sext i32 %8 to i64
%10 = add nsw i64 %9, %7
%11 = trunc i64 %10 to i32
store i32 %11, i32* %1
%12 = call i64 (...) @child4()
%13 = load i32, i32* %1
%14 = sext i32 %13 to i64
%15 = add nsw i64 %14, %12
%16 = trunc i64 %15 to i32
store i32 %16, i32* %1
%17 = call i64 (...) @child5()
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, %17
%21 = trunc i64 %20 to i32
store i32 %21, i32* %1
br label %22
22: ; preds = %6
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %3
25: ; preds = %3
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
define i32 @foo2() {
%1 = tail call i64 (...) @child3()
%2 = trunc i64 %1 to i32
%3 = tail call i64 (...) @child4()
%4 = trunc i64 %3 to i32
%5 = add i32 %2, %4
%6 = tail call i64 (...) @child5()
%7 = trunc i64 %6 to i32
%8 = add i32 %5, %7
%9 = tail call i64 (...) @child3()
%10 = trunc i64 %9 to i32
%11 = add i32 %8, %10
%12 = tail call i64 (...) @child4()
%13 = trunc i64 %12 to i32
%14 = add i32 %11, %13
%15 = tail call i64 (...) @child5()
%16 = trunc i64 %15 to i32
%17 = add i32 %14, %16
ret i32 %17
}