#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 EOF;
scalar_t__ feof(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int /*<<< orphan*/ stdin;
int main() {
  int sum = 0;
  int res;
  int in;
  for (;;) {
    res = scanf("%d", &in);
    if (res == EOF) {
      if (feof(stdin)) {
        break;
      } else {
        printf("Error occurred\n");
        return 1;
      }
    } else {
      sum = sum + in;
    }
  }
  printf("sum is: %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%eax
jne    11a2 <main+0x72>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     1188 <main+0x58>
jmp    11b0 <main+0x80>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <main+0x98>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <main+0x16>
mov    -0x8(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x2e81(%rip),%rbp
xor    %ebx,%ebx
cmp    0x0(%rbp),%eax
je     1194 <main+0x54>
xor    %ebx,%ebx
lea    0xe91(%rip),%r14
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    0x4(%rsp),%ebx
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
cmp    0x0(%rbp),%eax
jne    1180 <main+0x40>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1050 <feof@plt>
test   %rax,%rax
je     11bb <main+0x7b>
lea    0xe55(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11cc <main+0x8c>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@EOF = global i32 0
@stdin = global i32 0
@.str.2 = [12 x i8] c"sum is: %d\0A\00"
@str = [15 x i8] c"Error occurred\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %13
6: ; preds = %13, %0
%7 = phi i32 [ 0, %0 ], [ %16, %13 ]
%8 = load i32, i32* @stdin
%9 = call i64 @feof(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %6
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %22
13: ; preds = %0, %13
%14 = phi i32 [ %16, %13 ], [ 0, %0 ]
%15 = load i32, i32* %1
%16 = add nsw i32 %15, %14
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %6, label %13
20: ; preds = %6
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %7)
br label %22
22: ; preds = %20, %11
%23 = phi i32 [ 0, %20 ], [ 1, %11 ]
ret i32 %23
}