#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*/ printf(char *, int);
scalar_t__ scanf(char *, int *);
int sum(int *, int);
int main() {
  int all, i, n, in[10000];
  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d", &in[i]);
    }
    printf("%d\n", sum(in, n));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%rax
je     11d2 <main+0xa2>
cmpl   $0x0,-0x10(%rbp)
jne    1171 <main+0x41>
jmp    11d2 <main+0xa2>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b0 <main+0x80>
movslq -0xc(%rbp),%rax
lea    -0x9c50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe63(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <main+0x48>
lea    -0x9c50(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <sum@plt>
mov    %eax,%esi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
jmp    1142 <main+0x12>
xor    %eax,%eax
add    $0x9c50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9c58,%rsp
lea    0xeb8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%rax
je     11ee <main+0xbe>
mov    0xc(%rsp),%esi
test   %esi,%esi
je     11ee <main+0xbe>
lea    0x10(%rsp),%r14
lea    0xe86(%rip),%r13
lea    0xe82(%rip),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
test   %esi,%esi
jle    11bd <main+0x8d>
mov    %r14,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rsi
add    $0x4,%rbx
cmp    %rsi,%rbp
jl     11a0 <main+0x70>
mov    %r14,%rdi
call   1040 <sum@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0x2e07(%rip),%rcx
cmp    (%rcx),%rax
je     11ee <main+0xbe>
mov    0xc(%rsp),%esi
test   %esi,%esi
jne    1190 <main+0x60>
xor    %eax,%eax
add    $0x9c58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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