#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__ EOF;
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int *realloc(int *, int);
scalar_t__ scanf(char *, int *);
int main() {
  int *array;
  int size = 10;
  int i = 0, sum = 0;
  array = malloc(sizeof(int) * 10);
  while (scanf("%d", (array + i)) != EOF) {
    sum += *(array + i);
    if (i == size - 1) {
      size *= 2;
      array = realloc(array, size);
    }
    i++;
  }
  free(array);
  printf("%d\n\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe68(%rip),%rdi
call   1070 <scanf@plt>
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%rax
je     11f6 <main+0xa6>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11e8 <main+0x98>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1182 <main+0x32>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%esi
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
lea    0xe91(%rip),%rdi
mov    %rax,%rsi
call   1070 <scanf@plt>
mov    0x2e6a(%rip),%rcx
xor    %r15d,%r15d
cmp    (%rcx),%rax
jne    11b1 <main+0x61>
mov    %rbp,%r12
mov    %r12,%rdi
call   1030 <free@plt>
lea    0xe6b(%rip),%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%ebx
xor    %r13d,%r13d
mov    $0x4,%r14d
xor    %r15d,%r15d
mov    %rbp,%r12
jmp    11f7 <main+0xa7>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
lea    (%r12,%r14,1),%rbp
lea    0xe21(%rip),%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
add    $0x4,%r14
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%rax
je     1189 <main+0x39>
add    0x0(%rbp),%r15d
lea    -0x1(%rbx),%eax
cmp    %rax,%r13
jne    11d0 <main+0x80>
add    %ebx,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
call   1060 <realloc@plt>
mov    %rax,%r12
jmp    11d0 <main+0x80>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.1 = [5 x i8] c"%d\0A\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 40)
%2 = tail call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%3 = load i64, i64* @EOF
%4 = icmp eq i64 %2, %3
br i1 %4, label %27, label %5
5: ; preds = %0, %19
%6 = phi i64 [ %22, %19 ], [ 0, %0 ]
%7 = phi i32* [ %23, %19 ], [ %1, %0 ]
%8 = phi i32 [ %12, %19 ], [ 0, %0 ]
%9 = phi i32 [ %21, %19 ], [ 10, %0 ]
%10 = phi i32* [ %20, %19 ], [ %1, %0 ]
%11 = load i32, i32* %7
%12 = add nsw i32 %11, %8
%13 = add nsw i32 %9, -1
%14 = zext i32 %13 to i64
%15 = icmp eq i64 %6, %14
br i1 %15, label %16, label %19
16: ; preds = %5
%17 = shl nsw i32 %9, 1
%18 = tail call i32* @realloc(i32* %10, i32 %17)
br label %19
19: ; preds = %16, %5
%20 = phi i32* [ %18, %16 ], [ %10, %5 ]
%21 = phi i32 [ %17, %16 ], [ %9, %5 ]
%22 = add nuw i64 %6, 1
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = tail call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %23)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %5
27: ; preds = %19, %0
%28 = phi i32* [ %1, %0 ], [ %20, %19 ]
%29 = phi i32 [ 0, %0 ], [ %12, %19 ]
%30 = tail call i32 @free(i32* %28)
%31 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %29)
ret i32 0
}