#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__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sum(int *, int);
int main() {
  int n, m, j, i;
  int *array;
  printf("Enter number of elements: ");
  scanf("%d", &n);
  array = (int *)malloc(sizeof(int) * n);
  for (j = 0; j < n; j++) {
    printf("> ");
    scanf("%d", &m);
    array[j] = m;
  }
  for (i = 0; i < n; i++)
    printf("%d%s", array[i], i == n - 1 ? "\n" : " ");
  printf("%s%d\n", "Sum: ", sum(array, n));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11cd <main+0x8d>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe73(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1187 <main+0x47>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1224 <main+0xe4>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
lea    0xe35(%rip),%rdx
lea    0xe28(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d4 <main+0x94>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <sum@plt>
mov    %eax,%edx
lea    0xded(%rip),%rdi
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    0x8(%rsp),%esi
test   %esi,%esi
jle    121c <main+0xdc>
lea    0xe90(%rip),%r14
lea    0xe86(%rip),%r15
lea    0xc(%rsp),%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
movslq 0x8(%rsp),%rsi
cmp    %rsi,%rbx
jl     11a0 <main+0x60>
test   %esi,%esi
jle    121c <main+0xdc>
lea    0xe53(%rip),%r15
lea    0xe52(%rip),%r12
lea    0xe3c(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,4),%eax
add    $0xffffffff,%esi
cmp    %rsi,%rbx
mov    %r12,%rdx
cmove  %r15,%rdx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rsi
cmp    %rsi,%rbx
jl     11f0 <main+0xb0>
mov    %r13,%rdi
call   1040 <sum@plt>
lea    0xdfb(%rip),%rdi
lea    0xdfa(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"> \00"
@.str.3 = [5 x i8] c"%d%s\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [6 x i8] c"%s%d\0A\00"
@.str.7 = [6 x i8] c"Sum: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = mul i64 4, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %6
store i32 0, i32* %4
br label %15
15: ; preds = %27, %0
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%22 = load i32, i32* %3
%23 = load i32*, i32** %6
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 %22, i32* %26
br label %27
27: ; preds = %19
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %15
30: ; preds = %15
store i32 0, i32* %5
br label %31
31: ; preds = %48, %30
%32 = load i32, i32* %5
%33 = load i32, i32* %2
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %51
35: ; preds = %31
%36 = load i32*, i32** %6
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %5
%42 = load i32, i32* %2
%43 = sub nsw i32 %42, 1
%44 = icmp eq i32 %41, %43
%45 = zext i1 %44 to i64
%46 = select i1 %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %40, i8* %46)
br label %48
48: ; preds = %35
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %31
51: ; preds = %31
%52 = load i32*, i32** %6
%53 = load i32, i32* %2
%54 = call i32 @sum(i32* %52, i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"> \00"
@.str.3 = [5 x i8] c"%d%s\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [6 x i8] c"%s%d\0A\00"
@.str.7 = [6 x i8] c"Sum: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = shl i32 %7, 2
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %15, label %39
13: ; preds = %15
%14 = icmp sgt i32 %22, 0
br i1 %14, label %25, label %39
15: ; preds = %0, %15
%16 = phi i64 [ %21, %15 ], [ 0, %0 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
%20 = getelementptr inbounds i32, i32* %10, i64 %16
store i32 %19, i32* %20
%21 = add nuw nsw i64 %16, 1
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %15, label %13
25: ; preds = %13, %25
%26 = phi i64 [ %35, %25 ], [ 0, %13 ]
%27 = phi i32 [ %36, %25 ], [ %22, %13 ]
%28 = getelementptr inbounds i32, i32* %10, i64 %26
%29 = load i32, i32* %28
%30 = add nsw i32 %27, -1
%31 = zext i32 %30 to i64
%32 = icmp eq i64 %26, %31
%33 = select i1 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %29, i8* %33)
%35 = add nuw nsw i64 %26, 1
%36 = load i32, i32* %1
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %25, label %39
39: ; preds = %25, %0, %13
%40 = phi i32 [ %22, %13 ], [ %11, %0 ], [ %36, %25 ]
%41 = call i32 @sum(i32* %10, i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %41)
ret i32 0
}