#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__ fgets_unlocked(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdin;
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(void) {
  int sum = 0;
  char line[128];
  while (fgets_unlocked(line, 128, stdin))
    sum += strtol(line, NULL, 0);
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1050 <fgets_unlocked@plt>
cmp    $0x0,%rax
je     1191 <main+0x61>
lea    -0x90(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
jmp    1149 <main+0x19>
mov    -0x8(%rbp),%esi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x2ea5(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x80,%esi
call   1050 <fgets_unlocked@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1183 <main+0x53>
mov    %rsp,%r14
nopl   (%rax)
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
add    %eax,%ebx
mov    (%r15),%edx
mov    %r14,%rdi
mov    $0x80,%esi
call   1050 <fgets_unlocked@plt>
test   %rax,%rax
jne    1160 <main+0x30>
lea    0xe76(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
br label %4
4: ; preds = %9, %0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i64 @fgets_unlocked(i8* %5, i32 128, i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %4
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%11 = call i64 @strtol(i8* %10, i32* null, i32 0)
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = add nsw i64 %13, %11
%15 = trunc i64 %14 to i32
store i32 %15, i32* %2
br label %4
16: ; preds = %4
%17 = load i32, i32* %2
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i64 @fgets_unlocked(i8* %2, i32 128, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %0, %6
%7 = phi i32 [ %10, %6 ], [ 0, %0 ]
%8 = call i64 @strtol(i8* nocapture %2, i32* null, i32 0)
%9 = trunc i64 %8 to i32
%10 = add i32 %7, %9
%11 = load i32, i32* @stdin
%12 = call i64 @fgets_unlocked(i8* %2, i32 128, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6, %0
%15 = phi i32 [ 0, %0 ], [ %10, %6 ]
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
ret i32 0
}