#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 /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int simple_array_sum(int *, int);
int main() {
  int *data, n, i;
  scanf("%d", &n);
  if (n <= 0)
    return -1;
  data = malloc(sizeof(int) * n);
  if (!data)
    return -2;
  for (i = 0; i < n; i++)
    scanf("%d", &data[i]);
  printf("%d\n", simple_array_sum(data, n));
  free(data);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x0,-0x14(%rbp)
jg     1185 <main+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <main+0xc5>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11af <main+0x5f>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1215 <main+0xc5>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11eb <main+0x9b>
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe28(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b6 <main+0x66>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <simple_array_sum@plt>
mov    %eax,%esi
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    11cf <main+0x7f>
shl    $0x2,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11d6 <main+0x86>
mov    %rax,%r14
xor    %r12d,%r12d
lea    0xe75(%rip),%r15
mov    %rax,%rbx
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%r12
movslq 0x4(%rsp),%rsi
add    $0x4,%rbx
cmp    %rsi,%r12
jl     1190 <main+0x40>
mov    %r14,%rdi
call   1040 <simple_array_sum@plt>
lea    0xe47(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11db <main+0x8b>
mov    $0xffffffff,%eax
jmp    11db <main+0x8b>
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = load i32, i32* %3
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %39
9: ; preds = %0
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 4, %11
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %2
%15 = load i32*, i32** %2
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %9
store i32 -2, i32* %1
br label %39
18: ; preds = %9
store i32 0, i32* %4
br label %19
19: ; preds = %29, %18
%20 = load i32, i32* %4
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i32*, i32** %2
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %27)
br label %29
29: ; preds = %23
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %19
32: ; preds = %19
%33 = load i32*, i32** %2
%34 = load i32, i32* %3
%35 = call i32 @simple_array_sum(i32* %33, i32 %34)
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = load i32*, i32** %2
%38 = call i32 @free(i32* %37)
store i32 0, i32* %1
br label %39
39: ; preds = %32, %17, %8
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 1
br i1 %5, label %22, label %6
6: ; preds = %0
%7 = shl i32 %4, 2
%8 = call i32* @malloc(i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %22, label %10
10: ; preds = %6, %10
%11 = phi i64 [ %14, %10 ], [ 0, %6 ]
%12 = getelementptr inbounds i32, i32* %8, i64 %11
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %12)
%14 = add nuw nsw i64 %11, 1
%15 = load i32, i32* %1
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %10, label %18
18: ; preds = %10
%19 = call i32 @simple_array_sum(i32* %8, i32 %15)
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 @free(i32* %8)
br label %22
22: ; preds = %6, %0, %18
%23 = phi i32 [ 0, %18 ], [ -1, %0 ], [ -2, %6 ]
ret i32 %23
}