#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 *alloca(int);
int iterate(int bound) {
  int *bound_ref = alloca(sizeof(int));
  int *i = alloca(sizeof(int));
  int *sum = alloca(sizeof(int));
  *bound_ref = bound;
  *sum = 0;
  for (*i = 0; *i < *bound_ref; (*i)++) {
    *sum += *i;
  }
  return *sum;
}


x86 assembly (clang, -O0):
<iterate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1192 <iterate+0x82>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1162 <iterate+0x52>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iterate>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %ebp,(%r14)
movl   $0x0,(%rax)
movl   $0x0,(%rbx)
cmpl   $0x0,(%r14)
jle    116e <iterate+0x5e>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ecx,(%rax)
mov    (%rbx),%ecx
add    $0x1,%ecx
mov    %ecx,(%rbx)
cmp    (%r14),%ecx
jl     1160 <iterate+0x50>
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @iterate(i32 %0) {
%2 = tail call i32* @alloca(i32 4)
%3 = tail call i32* @alloca(i32 4)
%4 = tail call i32* @alloca(i32 4)
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %3
%5 = load i32, i32* %2
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %1, %7
%8 = phi i32 [ %12, %7 ], [ 0, %1 ]
%9 = load i32, i32* %4
%10 = add nsw i32 %9, %8
store i32 %10, i32* %4
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %7, label %15
15: ; preds = %7, %1
%16 = load i32, i32* %4
ret i32 %16
}