#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 /*<<< orphan*/ free(int *);
int *malloc(int);
int main() {
  int *arr = malloc(sizeof(int) * 5);
  volatile int i;
  int sum = 0;
  for (i = 0; i < 5; i++) {
    arr[i] = i;
  }
  for (i = 0; i < 5; i++) {
    sum += arr[i];
  }
  free(arr);
  return sum;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    $0x5,%eax
jge    1175 <main+0x55>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <main+0x2b>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    $0x5,%eax
jge    11a9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117c <main+0x5c>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x14,%edi
call   1040 <malloc@plt>
movl   $0x0,0xc(%rsp)
mov    0xc(%rsp),%ecx
cmp    $0x4,%ecx
jg     115a <main+0x3a>
mov    0xc(%rsp),%ecx
movslq 0xc(%rsp),%rdx
mov    %ecx,(%rax,%rdx,4)
addl   $0x1,0xc(%rsp)
mov    0xc(%rsp),%ecx
cmp    $0x5,%ecx
jl     1140 <main+0x20>
movl   $0x0,0xc(%rsp)
mov    0xc(%rsp),%ecx
xor    %ebx,%ebx
cmp    $0x4,%ecx
jg     1186 <main+0x66>
xor    %ebx,%ebx
nop
movslq 0xc(%rsp),%rcx
add    (%rax,%rcx,4),%ebx
addl   $0x1,0xc(%rsp)
mov    0xc(%rsp),%ecx
cmp    $0x5,%ecx
jl     1170 <main+0x50>
mov    %rax,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
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 i32* @malloc(i32 20)
store i32* %5, i32** %2
store i32 0, i32* %4
store volatile i32 0, i32* %3
br label %6
6: ; preds = %15, %0
%7 = load volatile i32, i32* %3
%8 = icmp slt i32 %7, 5
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = load volatile i32, i32* %3
%11 = load i32*, i32** %2
%12 = load volatile i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
store i32 %10, i32* %14
br label %15
15: ; preds = %9
%16 = load volatile i32, i32* %3
%17 = add nsw i32 %16, 1
store volatile i32 %17, i32* %3
br label %6
18: ; preds = %6
store volatile i32 0, i32* %3
br label %19
19: ; preds = %30, %18
%20 = load volatile i32, i32* %3
%21 = icmp slt i32 %20, 5
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = load i32*, i32** %2
%24 = load volatile i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = load i32, i32* %4
%29 = add nsw i32 %28, %27
store i32 %29, i32* %4
br label %30
30: ; preds = %22
%31 = load volatile i32, i32* %3
%32 = add nsw i32 %31, 1
store volatile i32 %32, i32* %3
br label %19
33: ; preds = %19
%34 = load i32*, i32** %2
%35 = call i32 @free(i32* %34)
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32
%2 = tail call i32* @malloc(i32 20)
%3 = bitcast i32* %1 to i8*
store volatile i32 0, i32* %1
%4 = load volatile i32, i32* %1
%5 = icmp slt i32 %4, 5
br i1 %5, label %6, label %15
6: ; preds = %0, %6
%7 = load volatile i32, i32* %1
%8 = load volatile i32, i32* %1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %2, i64 %9
store i32 %7, i32* %10
%11 = load volatile i32, i32* %1
%12 = add nsw i32 %11, 1
store volatile i32 %12, i32* %1
%13 = load volatile i32, i32* %1
%14 = icmp slt i32 %13, 5
br i1 %14, label %6, label %15
15: ; preds = %6, %0
store volatile i32 0, i32* %1
%16 = load volatile i32, i32* %1
%17 = icmp slt i32 %16, 5
br i1 %17, label %18, label %29
18: ; preds = %15, %18
%19 = phi i32 [ %24, %18 ], [ 0, %15 ]
%20 = load volatile i32, i32* %1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %2, i64 %21
%23 = load i32, i32* %22
%24 = add nsw i32 %23, %19
%25 = load volatile i32, i32* %1
%26 = add nsw i32 %25, 1
store volatile i32 %26, i32* %1
%27 = load volatile i32, i32* %1
%28 = icmp slt i32 %27, 5
br i1 %28, label %18, label %29
29: ; preds = %18, %15
%30 = phi i32 [ 0, %15 ], [ %24, %18 ]
%31 = tail call i32 @free(i32* %2)
ret i32 %30
}