#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*/ printf(char *, int);
scalar_t__ scanf(char *, int *);
int main() {
  int a, b, sum, n, i;
  while (scanf("%d", &n)) {
    if (n == 0)
      return 0;
    sum = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &a);
      sum = sum + a;
    }
    printf("%d\n", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x0,%rax
je     11b4 <main+0x94>
cmpl   $0x0,-0x14(%rbp)
jne    115f <main+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11bb <main+0x9b>
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11a0 <main+0x80>
lea    0xe80(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116d <main+0x4d>
mov    -0x10(%rbp),%esi
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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
lea    0xece(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11b3 <main+0x93>
mov    (%rsp),%eax
test   %eax,%eax
je     11b3 <main+0x93>
lea    0xeb6(%rip),%r14
lea    0xeac(%rip),%r13
mov    %rsp,%r15
lea    0x4(%rsp),%r12
nopl   0x0(%rax)
test   %eax,%eax
jle    1190 <main+0x70>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
add    0x4(%rsp),%ebp
add    $0x1,%ebx
cmp    (%rsp),%ebx
jl     1170 <main+0x50>
jmp    1192 <main+0x72>
nopl   0x0(%rax)
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11b3 <main+0x93>
mov    (%rsp),%eax
test   %eax,%eax
jne    1160 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %27, %0
%8 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %30
10: ; preds = %7
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 0, i32* %1
br label %31
14: ; preds = %10
store i32 0, i32* %4
store i32 1, i32* %6
br label %15
15: ; preds = %24, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %5
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%21 = load i32, i32* %4
%22 = load i32, i32* %2
%23 = add nsw i32 %21, %22
store i32 %23, i32* %4
br label %24
24: ; preds = %19
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %15
27: ; preds = %15
%28 = load i32, i32* %4
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %7
30: ; preds = %7
store i32 0, i32* %1
br label %31
31: ; preds = %30, %13
%32 = load i32, i32* %1
ret i32 %32
}

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 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = icmp eq i64 %5, 0
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 0
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %30, label %10
10: ; preds = %0, %22
%11 = phi i32 [ %27, %22 ], [ %7, %0 ]
%12 = icmp slt i32 %11, 1
br i1 %12, label %22, label %13
13: ; preds = %10, %13
%14 = phi i32 [ %19, %13 ], [ 1, %10 ]
%15 = phi i32 [ %18, %13 ], [ 0, %10 ]
%16 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%17 = load i32, i32* %1
%18 = add nsw i32 %17, %15
%19 = add nuw nsw i32 %14, 1
%20 = load i32, i32* %2
%21 = icmp slt i32 %14, %20
br i1 %21, label %13, label %22
22: ; preds = %13, %10
%23 = phi i32 [ 0, %10 ], [ %18, %13 ]
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%26 = icmp eq i64 %25, 0
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 0
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %30, label %10
30: ; preds = %22, %0
ret i32 0
}