#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int n, suma = 0, result;
  FILE *f;
  f = fopen("numeros.txt", "rt");
  if (f == NULL) {
    printf("Error abriendo archivo");
    return 1;
  } else {
    result = fscanf(f, "%d", &n);
    while (n != 0 && result && !feof(f)) {
      suma += n;
      result = fscanf(f, "%d", &n);
    }
    fclose(f);
    printf("La suma es: %d", suma);
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <main+0x52>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1241 <main+0xf1>
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
je     11eb <main+0x9b>
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x19(%rbp)
je     11eb <main+0x9b>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11fb <main+0xab>
jmp    1220 <main+0xd0>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe23(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,-0x10(%rbp)
jmp    11b9 <main+0x69>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
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   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9d(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1203 <main+0xb3>
mov    %rax,%rbx
lea    0xeb0(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
xor    %r14d,%r14d
mov    $0x0,%ebp
test   %eax,%eax
je     11e9 <main+0x99>
cmpl   $0x0,0xc(%rsp)
mov    $0x0,%ebp
je     11e9 <main+0x99>
xor    %ebp,%ebp
lea    0xe82(%rip),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11e9 <main+0x99>
add    0xc(%rsp),%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
test   %eax,%eax
je     11e9 <main+0x99>
cmpl   $0x0,0xc(%rsp)
jne    11c0 <main+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe2e(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1217 <main+0xc7>
lea    0xe05(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"numeros.txt\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [23 x i8] c"Error abriendo archivo\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [15 x i8] c"La suma es: %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %38
11: ; preds = %0
%12 = load i32*, i32** %5
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
store i32 %13, i32* %4
br label %14
14: ; preds = %27, %11
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32*, i32** %5
%22 = call i32 @feof(i32* %21)
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br label %25
25: ; preds = %20, %17, %14
%26 = phi i1 [ false, %17 ], [ false, %14 ], [ %24, %20 ]
br i1 %26, label %27, label %33
27: ; preds = %25
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = add nsw i32 %29, %28
store i32 %30, i32* %3
%31 = load i32*, i32** %5
%32 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
store i32 %32, i32* %4
br label %14
33: ; preds = %25
%34 = load i32*, i32** %5
%35 = call i32 @fclose(i32* %34)
%36 = load i32, i32* %3
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %36)
store i32 0, i32* %1
br label %38
38: ; preds = %33, %9
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [12 x i8] c"numeros.txt\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [23 x i8] c"Error abriendo archivo\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [15 x i8] c"La suma es: %d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %29
7: ; preds = %0
%8 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = icmp ne i32 %9, 0
%11 = icmp ne i32 %8, 0
%12 = and i1 %11, %10
br i1 %12, label %13, label %25
13: ; preds = %7, %17
%14 = phi i32 [ %19, %17 ], [ 0, %7 ]
%15 = call i32 @feof(i32* %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i32, i32* %1
%19 = add nsw i32 %18, %14
%20 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%21 = load i32, i32* %1
%22 = icmp ne i32 %21, 0
%23 = icmp ne i32 %20, 0
%24 = and i1 %23, %22
br i1 %24, label %13, label %25
25: ; preds = %13, %17, %7
%26 = phi i32 [ 0, %7 ], [ %19, %17 ], [ %14, %13 ]
%27 = call i32 @fclose(i32* %3)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %29
29: ; preds = %25, %5
%30 = phi i32 [ 1, %5 ], [ 0, %25 ]
ret i32 %30
}