#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, float);
int main(int argc, char *argv[]) {
  char *infile = argv[1];
  char *otfile = argv[2];
  FILE *in = fopen(infile, "r");
  FILE *ot = fopen(otfile, "w");
  int res;
  int num;
  int total = 0;
  int values = 0;
  res = fread(&num, sizeof(int), 1, in);
  while (res > 0) {
    total += num;
    values += 1;
    fprintf(ot, "%u\n", num);
    res = fread(&num, sizeof(int), 1, in);
  }
  float avg = (float)total / (float)values;
  printf("Average: %0.3f\n", avg);
  fclose(in);
  fclose(ot);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x38(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    121c <main+0xcc>
mov    -0x38(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%edx
lea    0xe0c(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rcx
lea    -0x38(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x34(%rbp)
jmp    11ce <main+0x7e>
cvtsi2ssl -0x3c(%rbp),%xmm0
cvtsi2ssl -0x40(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
lea    0xdcd(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%r14
lea    0xeb6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xea9(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    1207 <main+0xb7>
pxor   %xmm2,%xmm2
lea    0xe7a(%rip),%r15
lea    0xc(%rsp),%r12
nop
mov    0xc(%rsp),%edx
movd   %edx,%xmm0
movaps 0xe51(%rip),%xmm1
movss  %xmm0,%xmm1
paddd  %xmm1,%xmm2
movdqa %xmm2,0x10(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <fprintf@plt>
mov    %r12,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
movdqa 0x10(%rsp),%xmm2
test   %eax,%eax
jg     11b0 <main+0x60>
cvtdq2ps %xmm2,%xmm0
movaps %xmm0,%xmm1
shufps $0x55,%xmm0,%xmm1
divss  %xmm1,%xmm0
jmp    120f <main+0xbf>
movss  0xdf1(%rip),%xmm0
lea    0xe12(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%u\0A\00"
@.str.3 = [16 x i8] c"Average: %0.3f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
store i8* %20, i8** %7
%21 = load i8*, i8** %6
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %8
%23 = load i8*, i8** %7
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %9
store i32 0, i32* %12
store i32 0, i32* %13
%25 = load i32*, i32** %8
%26 = call i32 @fread(i32* %11, i32 4, i32 1, i32* %25)
store i32 %26, i32* %10
br label %27
27: ; preds = %30, %2
%28 = load i32, i32* %10
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %27
%31 = load i32, i32* %11
%32 = load i32, i32* %12
%33 = add nsw i32 %32, %31
store i32 %33, i32* %12
%34 = load i32, i32* %13
%35 = add nsw i32 %34, 1
store i32 %35, i32* %13
%36 = load i32*, i32** %9
%37 = load i32, i32* %11
%38 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = load i32*, i32** %8
%40 = call i32 @fread(i32* %11, i32 4, i32 1, i32* %39)
store i32 %40, i32* %10
br label %27
41: ; preds = %27
%42 = load i32, i32* %12
%43 = sitofp i32 %42 to float
%44 = load i32, i32* %13
%45 = sitofp i32 %44 to float
%46 = fdiv float %43, %45
store float %46, float* %14
%47 = load float, float* %14
%48 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), float %47)
%49 = load i32*, i32** %8
%50 = call i32 @fclose(i32* %49)
%51 = load i32*, i32** %9
%52 = call i32 @fclose(i32* %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%u\0A\00"
@.str.3 = [16 x i8] c"Average: %0.3f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = bitcast i32* %3 to i8*
%11 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %8)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %2, %13
%14 = phi <2 x i32> [ %17, %13 ], [ zeroinitializer, %2 ]
%15 = load i32, i32* %3
%16 = insertelement <2 x i32> <i32 poison, i32 1>, i32 %15, i64 0
%17 = add nsw <2 x i32> %16, %14
%18 = tail call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%19 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %8)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %13, label %21
21: ; preds = %13
%22 = sitofp <2 x i32> %17 to <2 x float>
%23 = extractelement <2 x float> %22, i64 0
%24 = extractelement <2 x float> %22, i64 1
%25 = fdiv float %23, %24
br label %26
26: ; preds = %21, %2
%27 = phi float [ %25, %21 ], [ 0x7FF8000000000000, %2 ]
%28 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), float %27)
%29 = tail call i32 @fclose(i32* %8)
%30 = tail call i32 @fclose(i32* %9)
ret i32 0
}