#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 EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int sum(int, int *);
int main(void) {
  int size;
  printf("Give di size of the array: ");
  scanf("%d", &size);
  int vec[size];
  for (int i = 0; i < size; i++)
    vec[i] = i;
  printf("The sum of each array element is: %d\n", sum(size, vec));
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b3 <main+0x83>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%edx
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118b <main+0x5b>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edi
call   1040 <sum@plt>
mov    %eax,%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xf4e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf5c(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    %rsp,%r14
mov    -0x14(%rbp),%eax
mov    %rsp,%rsi
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rsi
mov    %rsi,%rsp
mov    -0x14(%rbp),%edi
test   %edi,%edi
jle    12ec <main+0x1bc>
cmp    $0x8,%edi
jae    118b <main+0x5b>
xor    %eax,%eax
jmp    12e0 <main+0x1b0>
mov    %edi,%eax
and    $0xfffffff8,%eax
lea    -0x8(%rax),%rbx
mov    %rbx,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
mov    %edx,%ecx
and    $0x3,%ecx
cmp    $0x18,%rbx
jae    11b9 <main+0x89>
movdqa 0xe4e(%rip),%xmm0
xor    %ebx,%ebx
jmp    1288 <main+0x158>
and    $0xfffffffffffffffc,%rdx
movdqa 0xe3b(%rip),%xmm0
xor    %ebx,%ebx
movdqa 0xe40(%rip),%xmm8
movdqa 0xe47(%rip),%xmm9
movdqa 0xe4e(%rip),%xmm10
movdqa 0xe56(%rip),%xmm4
movdqa 0xe5e(%rip),%xmm5
movdqa 0xe66(%rip),%xmm6
movdqa 0xe6e(%rip),%xmm7
movdqa 0xe76(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm2
paddd  %xmm8,%xmm2
movdqa %xmm0,(%rsi,%rbx,4)
movdqa %xmm2,0x10(%rsi,%rbx,4)
movdqa %xmm0,%xmm2
paddd  %xmm9,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm10,%xmm3
movdqa %xmm2,0x20(%rsi,%rbx,4)
movdqa %xmm3,0x30(%rsi,%rbx,4)
movdqa %xmm0,%xmm2
paddd  %xmm4,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm5,%xmm3
movdqa %xmm2,0x40(%rsi,%rbx,4)
movdqa %xmm3,0x50(%rsi,%rbx,4)
movdqa %xmm0,%xmm2
paddd  %xmm6,%xmm2
movdqa %xmm0,%xmm3
paddd  %xmm7,%xmm3
movdqa %xmm2,0x60(%rsi,%rbx,4)
movdqa %xmm3,0x70(%rsi,%rbx,4)
add    $0x20,%rbx
paddd  %xmm1,%xmm0
add    $0xfffffffffffffffc,%rdx
jne    1210 <main+0xe0>
test   %rcx,%rcx
je     12d0 <main+0x1a0>
lea    (%rsi,%rbx,4),%rdx
add    $0x10,%rdx
shl    $0x5,%rcx
xor    %ebx,%ebx
movdqa 0xd6d(%rip),%xmm1
movdqa 0xd75(%rip),%xmm2
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm3
paddd  %xmm1,%xmm3
movdqa %xmm0,-0x10(%rdx,%rbx,1)
movdqa %xmm3,(%rdx,%rbx,1)
paddd  %xmm2,%xmm0
add    $0x20,%rbx
cmp    %rbx,%rcx
jne    12b0 <main+0x180>
cmp    %rdi,%rax
je     12ec <main+0x1bc>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,(%rsi,%rax,4)
add    $0x1,%rax
cmp    %rax,%rdi
jne    12e0 <main+0x1b0>
call   1040 <sum@plt>
lea    0xdb7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2cd8(%rip),%rax
mov    (%rax),%eax
mov    %r14,%rsp
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Give di size of the array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"The sum of each array element is: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i32, i64 %9
store i64 %9, i64* %4
store i32 0, i32* %5
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %5
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32, i32* %5
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %11, i64 %19
store i32 %17, i32* %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %12
24: ; preds = %12
%25 = load i32, i32* %2
%26 = call i32 @sum(i32 %25, i32* %11)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @EXIT_SUCCESS
store i32 %28, i32* %1
%29 = load i8*, i8** %3
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [28 x i8] c"Give di size of the array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"The sum of each array element is: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
%8 = alloca i32, i64 %6
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %78
11: ; preds = %0
%12 = zext i32 %9 to i64
%13 = icmp ult i32 %9, 8
br i1 %13, label %76, label %14
14: ; preds = %11
%15 = and i64 %12, 4294967288
%16 = add nsw i64 %15, -8
%17 = lshr exact i64 %16, 3
%18 = add nuw nsw i64 %17, 1
%19 = and i64 %18, 3
%20 = icmp ult i64 %16, 24
br i1 %20, label %57, label %21
21: ; preds = %14
%22 = and i64 %18, 4611686018427387900
br label %23
23: ; preds = %23, %21
%24 = phi i64 [ 0, %21 ], [ %53, %23 ]
%25 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %21 ], [ %54, %23 ]
%26 = phi i64 [ 0, %21 ], [ %55, %23 ]
%27 = add <4 x i32> %25, <i32 4, i32 4, i32 4, i32 4>
%28 = getelementptr inbounds i32, i32* %8, i64 %24
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> %25, <4 x i32>* %29
%30 = getelementptr inbounds i32, i32* %28, i64 4
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> %27, <4 x i32>* %31
%32 = or i64 %24, 8
%33 = add <4 x i32> %25, <i32 8, i32 8, i32 8, i32 8>
%34 = add <4 x i32> %25, <i32 12, i32 12, i32 12, i32 12>
%35 = getelementptr inbounds i32, i32* %8, i64 %32
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> %33, <4 x i32>* %36
%37 = getelementptr inbounds i32, i32* %35, i64 4
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> %34, <4 x i32>* %38
%39 = or i64 %24, 16
%40 = add <4 x i32> %25, <i32 16, i32 16, i32 16, i32 16>
%41 = add <4 x i32> %25, <i32 20, i32 20, i32 20, i32 20>
%42 = getelementptr inbounds i32, i32* %8, i64 %39
%43 = bitcast i32* %42 to <4 x i32>*
store <4 x i32> %40, <4 x i32>* %43
%44 = getelementptr inbounds i32, i32* %42, i64 4
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> %41, <4 x i32>* %45
%46 = or i64 %24, 24
%47 = add <4 x i32> %25, <i32 24, i32 24, i32 24, i32 24>
%48 = add <4 x i32> %25, <i32 28, i32 28, i32 28, i32 28>
%49 = getelementptr inbounds i32, i32* %8, i64 %46
%50 = bitcast i32* %49 to <4 x i32>*
store <4 x i32> %47, <4 x i32>* %50
%51 = getelementptr inbounds i32, i32* %49, i64 4
%52 = bitcast i32* %51 to <4 x i32>*
store <4 x i32> %48, <4 x i32>* %52
%53 = add nuw i64 %24, 32
%54 = add <4 x i32> %25, <i32 32, i32 32, i32 32, i32 32>
%55 = add i64 %26, 4
%56 = icmp eq i64 %55, %22
br i1 %56, label %57, label %23
57: ; preds = %23, %14
%58 = phi i64 [ 0, %14 ], [ %53, %23 ]
%59 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %14 ], [ %54, %23 ]
%60 = icmp eq i64 %19, 0
br i1 %60, label %74, label %61
61: ; preds = %57, %61
%62 = phi i64 [ %70, %61 ], [ %58, %57 ]
%63 = phi <4 x i32> [ %71, %61 ], [ %59, %57 ]
%64 = phi i64 [ %72, %61 ], [ 0, %57 ]
%65 = add <4 x i32> %63, <i32 4, i32 4, i32 4, i32 4>
%66 = getelementptr inbounds i32, i32* %8, i64 %62
%67 = bitcast i32* %66 to <4 x i32>*
store <4 x i32> %63, <4 x i32>* %67
%68 = getelementptr inbounds i32, i32* %66, i64 4
%69 = bitcast i32* %68 to <4 x i32>*
store <4 x i32> %65, <4 x i32>* %69
%70 = add nuw i64 %62, 8
%71 = add <4 x i32> %63, <i32 8, i32 8, i32 8, i32 8>
%72 = add i64 %64, 1
%73 = icmp eq i64 %72, %19
br i1 %73, label %74, label %61
74: ; preds = %61, %57
%75 = icmp eq i64 %15, %12
br i1 %75, label %78, label %76
76: ; preds = %11, %74
%77 = phi i64 [ 0, %11 ], [ %15, %74 ]
br label %82
78: ; preds = %82, %74, %0
%79 = call i32 @sum(i32 %9, i32* %8)
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %79)
%81 = load i32, i32* @EXIT_SUCCESS
ret i32 %81
82: ; preds = %76, %82
%83 = phi i64 [ %86, %82 ], [ %77, %76 ]
%84 = getelementptr inbounds i32, i32* %8, i64 %83
%85 = trunc i64 %83 to i32
store i32 %85, i32* %84
%86 = add nuw nsw i64 %83, 1
%87 = icmp eq i64 %86, %12
br i1 %87, label %78, label %82
}