#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 fclose(int /*<<< orphan*/ *);
int feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ printf(char *, float, ...);
int main() {
  FILE *datos;
  float dato, suma, promedio, cantidad;
  datos = fopen("medicion.txt", "r");
  suma = 0;
  cantidad = 0;
  while (feof(datos) == 0) {
    dato = 0;
    fscanf(datos, "%f", &dato);
    if (feof(datos) == 1 && dato == 0) {
      break;
    }
    printf("Leí %2.2f\n", dato);
    suma = suma + dato;
    cantidad = cantidad + 1;
  }
  printf("La suma de todos los datos leidos es %2.2f. El promedio, %2.2f.\n",
         suma, suma / cantidad);
  return fclose(datos);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9e(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
jne    121b <main+0xcb>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe68(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x1,%eax
jne    11e2 <main+0x92>
movss  -0x14(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11e2 <main+0x92>
jp     11e2 <main+0x92>
jmp    121b <main+0xcb>
movss  -0x14(%rbp),%xmm0
lea    0xe28(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x18(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xdf4(%rip),%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
jmp    1186 <main+0x36>
movss  -0x18(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
divss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xded(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xea6(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
test   %eax,%eax
jne    1230 <main+0xe0>
lea    0xe7d(%rip),%r14
lea    0x14(%rsp),%r15
lea    0xe74(%rip),%r12
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xorps  %xmm0,%xmm0
movss  %xmm0,0x10(%rsp)
jmp    11fc <main+0xac>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x10(%rsp),%xmm0
addss  0x14(%rsp),%xmm0
movss  %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
addss  0xe16(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1230 <main+0xe0>
movl   $0x0,0x14(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
movss  0x14(%rsp),%xmm0
cmp    $0x1,%eax
jne    11c0 <main+0x70>
ucomiss 0xdd8(%rip),%xmm0
jne    11c0 <main+0x70>
jp     11c0 <main+0x70>
movss  0x10(%rsp),%xmm0
movaps %xmm0,%xmm1
divss  0xc(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xddc(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"medicion.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [12 x i8] c"Le\C3\AD %2.2f\0A\00"
@.str.4 = [65 x i8] c"La suma de todos los datos leidos es %2.2f. El promedio, %2.2f.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 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** %2
store float 0.000000e+00, float* %4
store float 0.000000e+00, float* %6
br label %8
8: ; preds = %22, %0
%9 = load i32*, i32** %2
%10 = call i32 @feof(i32* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %30
12: ; preds = %8
store float 0.000000e+00, float* %3
%13 = load i32*, i32** %2
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %3)
%15 = load i32*, i32** %2
%16 = call i32 @feof(i32* %15)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load float, float* %3
%20 = fcmp oeq float %19, 0.000000e+00
br i1 %20, label %21, label %22
21: ; preds = %18
br label %30
22: ; preds = %18, %12
%23 = load float, float* %3
%24 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), float %23)
%25 = load float, float* %4
%26 = load float, float* %3
%27 = fadd float %25, %26
store float %27, float* %4
%28 = load float, float* %6
%29 = fadd float %28, 1.000000e+00
store float %29, float* %6
br label %8
30: ; preds = %21, %8
%31 = load float, float* %4
%32 = load float, float* %4
%33 = load float, float* %6
%34 = fdiv float %32, %33
%35 = fpext float %34 to double
%36 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), float %31, double %35)
%37 = load i32*, i32** %2
%38 = call i32 @fclose(i32* %37)
ret i32 %38
}

LLVM IR (-O2):
@.str = [13 x i8] c"medicion.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [12 x i8] c"Le\C3\AD %2.2f\0A\00"
@.str.4 = [65 x i8] c"La suma de todos los datos leidos es %2.2f. El promedio, %2.2f.\0A\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @feof(i32* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %22
6: ; preds = %0, %15
%7 = phi float [ %19, %15 ], [ 0.000000e+00, %0 ]
%8 = phi float [ %18, %15 ], [ 0.000000e+00, %0 ]
store float 0.000000e+00, float* %1
%9 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %1)
%10 = call i32 @feof(i32* %3)
%11 = icmp eq i32 %10, 1
%12 = load float, float* %1
%13 = fcmp oeq float %12, 0.000000e+00
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %22, label %15
15: ; preds = %6
%16 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), float %12)
%17 = load float, float* %1
%18 = fadd float %8, %17
%19 = fadd float %7, 1.000000e+00
%20 = call i32 @feof(i32* %3)
%21 = icmp eq i32 %20, 0
br i1 %21, label %6, label %22
22: ; preds = %15, %6, %0
%23 = phi float [ 0.000000e+00, %0 ], [ %8, %6 ], [ %18, %15 ]
%24 = phi float [ 0.000000e+00, %0 ], [ %7, %6 ], [ %19, %15 ]
%25 = fdiv float %23, %24
%26 = fpext float %25 to double
%27 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), float %23, double %26)
%28 = call i32 @fclose(i32* %3)
ret i32 %28
}