#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__ child1();
scalar_t__ child2();
scalar_t__ child3();
int foo1() {
  int a = 0;
  int ii;
  for (ii = 0; ii < 3; ++ii) {
    a += child1();
    a += child2();
    a += child3();
  }
  return a;
}


x86 assembly (clang, -O0):
<foo1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119a <foo1+0x6a>
mov    $0x0,%al
call   1030 <child1@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1050 <child2@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1040 <child3@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 <foo1+0x16>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define i32 @foo1() {
%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, 3
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = call i64 (...) @child1()
%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 (...) @child2()
%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 (...) @child3()
%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 @foo1() {
%1 = tail call i64 (...) @child1()
%2 = trunc i64 %1 to i32
%3 = tail call i64 (...) @child2()
%4 = trunc i64 %3 to i32
%5 = add i32 %2, %4
%6 = tail call i64 (...) @child3()
%7 = trunc i64 %6 to i32
%8 = add i32 %5, %7
%9 = tail call i64 (...) @child1()
%10 = trunc i64 %9 to i32
%11 = add i32 %8, %10
%12 = tail call i64 (...) @child2()
%13 = trunc i64 %12 to i32
%14 = add i32 %11, %13
%15 = tail call i64 (...) @child3()
%16 = trunc i64 %15 to i32
%17 = add i32 %14, %16
%18 = tail call i64 (...) @child1()
%19 = trunc i64 %18 to i32
%20 = add i32 %17, %19
%21 = tail call i64 (...) @child2()
%22 = trunc i64 %21 to i32
%23 = add i32 %20, %22
%24 = tail call i64 (...) @child3()
%25 = trunc i64 %24 to i32
%26 = add i32 %23, %25
ret i32 %26
}