#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 argc, char const *argv[]) {
  int a, b, s = 0;
  while (scanf("%d", &a) > 0 && a != 0) {
    s = 0;
    while (a--) {
      scanf("%d", &b);
      s += b;
    }
    printf("%d\n", s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xebc(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1d(%rbp)
jle    1169 <main+0x49>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1179 <main+0x59>
jmp    11c6 <main+0xa6>
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11b2 <main+0x92>
lea    0xe65(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <main+0x60>
mov    -0x1c(%rbp),%esi
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
jmp    113d <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecd(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
test   %rax,%rax
jle    11b8 <main+0x98>
mov    0x8(%rsp),%eax
test   %eax,%eax
je     11b8 <main+0x98>
lea    0xeaf(%rip),%rbx
lea    0xc(%rsp),%r14
lea    0xea6(%rip),%r15
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%eax
mov    %eax,0x8(%rsp)
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
add    0xc(%rsp),%ebp
subl   $0x1,0x8(%rsp)
jae    1180 <main+0x60>
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
test   %rax,%rax
jle    11b8 <main+0x98>
mov    0x8(%rsp),%eax
test   %eax,%eax
jne    1170 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %9
9: ; preds = %27, %2
%10 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %12, %9
%16 = phi i1 [ false, %9 ], [ %14, %12 ]
br i1 %16, label %17, label %30
17: ; preds = %15
store i32 0, i32* %8
br label %18
18: ; preds = %22, %17
%19 = load i32, i32* %6
%20 = add nsw i32 %19, -1
store i32 %20, i32* %6
%21 = icmp ne i32 %19, 0
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = add nsw i32 %25, %24
store i32 %26, i32* %8
br label %18
27: ; preds = %18
%28 = load i32, i32* %8
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %9
30: ; preds = %15
ret i32 0
}

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