#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 ntohl(int);
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) {
    num = ntohl(num);
    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    0xe67(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe55(%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    1237 <main+0xd7>
mov    -0x38(%rbp),%edi
call   1080 <ntohl@plt>
mov    %eax,-0x38(%rbp)
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    0xdf1(%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    11de <main+0x7e>
cvtsi2ssl -0x3c(%rbp),%xmm0
cvtsi2ssl -0x40(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
lea    0xdb2(%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    0xea6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe99(%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    1234 <main+0xd4>
pxor   %xmm0,%xmm0
movdqa %xmm0,0x10(%rsp)
lea    0xe60(%rip),%r15
lea    0xc(%rsp),%r12
nopl   0x0(%rax)
mov    0xc(%rsp),%edi
call   1080 <ntohl@plt>
movd   %eax,%xmm0
movaps 0xe2c(%rip),%xmm1
movss  %xmm0,%xmm1
movdqa 0x10(%rsp),%xmm0
paddd  %xmm1,%xmm0
movdqa %xmm0,0x10(%rsp)
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %r12,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     11d0 <main+0x70>
cvtdq2ps 0x10(%rsp),%xmm0
movaps %xmm0,%xmm1
shufps $0x55,%xmm0,%xmm1
divss  %xmm1,%xmm0
jmp    123c <main+0xdc>
movss  0xdc4(%rip),%xmm0
lea    0xde5(%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 %43
30: ; preds = %27
%31 = load i32, i32* %11
%32 = call i32 @ntohl(i32 %31)
store i32 %32, i32* %11
%33 = load i32, i32* %11
%34 = load i32, i32* %12
%35 = add nsw i32 %34, %33
store i32 %35, i32* %12
%36 = load i32, i32* %13
%37 = add nsw i32 %36, 1
store i32 %37, i32* %13
%38 = load i32*, i32** %9
%39 = load i32, i32* %11
%40 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i32*, i32** %8
%42 = call i32 @fread(i32* %11, i32 4, i32 1, i32* %41)
store i32 %42, i32* %10
br label %27
43: ; preds = %27
%44 = load i32, i32* %12
%45 = sitofp i32 %44 to float
%46 = load i32, i32* %13
%47 = sitofp i32 %46 to float
%48 = fdiv float %45, %47
store float %48, float* %14
%49 = load float, float* %14
%50 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), float %49)
%51 = load i32*, i32** %8
%52 = call i32 @fclose(i32* %51)
%53 = load i32*, i32** %9
%54 = call i32 @fclose(i32* %53)
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 %27
13: ; preds = %2, %13
%14 = phi <2 x i32> [ %18, %13 ], [ zeroinitializer, %2 ]
%15 = load i32, i32* %3
%16 = tail call i32 @ntohl(i32 %15)
store i32 %16, i32* %3
%17 = insertelement <2 x i32> <i32 poison, i32 1>, i32 %16, i64 0
%18 = add nsw <2 x i32> %17, %14
%19 = tail call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%20 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %8)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %13, label %22
22: ; preds = %13
%23 = sitofp <2 x i32> %18 to <2 x float>
%24 = extractelement <2 x float> %23, i64 0
%25 = extractelement <2 x float> %23, i64 1
%26 = fdiv float %24, %25
br label %27
27: ; preds = %22, %2
%28 = phi float [ %26, %22 ], [ 0x7FF8000000000000, %2 ]
%29 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), float %28)
%30 = tail call i32 @fclose(i32* %8)
%31 = tail call i32 @fclose(i32* %9)
ret i32 0
}