#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int x, n, k;
  double soma;
  FILE *entrada;
  entrada = fopen("FIBONACCI.txt", "r");
  if (entrada == NULL) {
    printf("\nNão encontrei arquivo\n");
    exit(EXIT_FAILURE);
  }
  soma = n = 0;
  while (1) {
    k = fscanf(entrada, "%d", &x);
    if (k != 1)
      break;
    soma += x;
    n += 1;
  }
  fclose(entrada);
  printf("A média dos números é %f\n", soma / n);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119d <main+0x4d>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe72(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
je     11d2 <main+0x82>
jmp    11ef <main+0x9f>
cvtsi2sdl -0x8(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ac <main+0x5c>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xe1f(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe8f(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1230 <main+0xd0>
mov    %rax,%rbx
lea    0xe80(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
cmp    $0x1,%eax
jne    11f6 <main+0x96>
xorpd  %xmm1,%xmm1
xor    %ebp,%ebp
lea    0xe59(%rip),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rsp),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <fscanf@plt>
movsd  0x10(%rsp),%xmm1
cmp    $0x1,%eax
je     11c0 <main+0x60>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe04(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf9(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"FIBONACCI.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"\0AN\C3\A3o encontrei arquivo\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [29 x i8] c"A m\C3\A9dia dos n\C3\BAmeros \C3\A9 %f\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca i32*
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %6
%8 = load i32*, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
store i32 0, i32* %3
store double 0.000000e+00, double* %5
br label %15
15: ; preds = %14, %21
%16 = load i32*, i32** %6
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %15
br label %28
21: ; preds = %15
%22 = load i32, i32* %2
%23 = sitofp i32 %22 to double
%24 = load double, double* %5
%25 = fadd double %24, %23
store double %25, double* %5
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %15
28: ; preds = %20
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
%31 = load double, double* %5
%32 = load i32, i32* %3
%33 = sitofp i32 %32 to double
%34 = fdiv double %31, %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), double %34)
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}

LLVM IR (-O2):
@.str = [14 x i8] c"FIBONACCI.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [29 x i8] c"A m\C3\A9dia dos n\C3\BAmeros \C3\A9 %f\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [24 x i8] c"\0AN\C3\A3o encontrei arquivo\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %12, label %23
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %5, %12
%13 = phi i32 [ %18, %12 ], [ 0, %5 ]
%14 = phi double [ %17, %12 ], [ 0.000000e+00, %5 ]
%15 = load i32, i32* %1
%16 = sitofp i32 %15 to double
%17 = fadd double %14, %16
%18 = add nuw nsw i32 %13, 1
%19 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%20 = icmp eq i32 %19, 1
br i1 %20, label %12, label %21
21: ; preds = %12
%22 = sitofp i32 %18 to double
br label %23
23: ; preds = %21, %5
%24 = phi double [ 0.000000e+00, %5 ], [ %17, %21 ]
%25 = phi double [ 0.000000e+00, %5 ], [ %22, %21 ]
%26 = call i32 @fclose(i32* %3)
%27 = fdiv double %24, %25
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), double %27)
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}