#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(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int rows, rowValue, rowsValuesSum, i;
  int *rowsValuesVector;
  float arithmeticMean;
  FILE *file;
  if ((file = fopen(argv[1], "r")) == NULL) {
    printf("ERROR: File could not be loaded");
    exit(0);
  }
  file = fopen(argv[1], "r");
  fscanf(file, "%d", &rows);
  if ((rowsValuesVector = malloc(rows * sizeof(int))) == NULL) {
    printf("Impossible to allocate space");
    exit(0);
  }
  rowsValuesVector = malloc(rows * sizeof(int));
  for (i = 0; i < rows; i++) {
    fscanf(file, "%d", &rowValue);
    rowsValuesVector[i] = rowValue;
    rowsValuesSum += rowValue;
    printf("%d,", rowValue);
  }
  fclose(file);
  arithmeticMean = (float)rowsValuesSum / (float)rows;
  printf("\narithmetic mean: %.2f \n", arithmeticMean);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11ad <main+0x4d>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe44(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe52(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    120b <main+0xab>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    127b <main+0x11b>
mov    -0x38(%rbp),%rdi
lea    0xde6(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1225 <main+0xc5>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
cvtsi2ssl -0x1c(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd9f(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1274 <main+0x114>
mov    0x8(%rbx),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe7e(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0xc(%rsp),%ebp
lea    0x0(,%rbp,4),%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     127d <main+0x11d>
mov    %ebx,%edi
call   1060 <malloc@plt>
test   %ebp,%ebp
jle    122a <main+0xca>
mov    %rax,%rbx
lea    0x14(%rsp),%r12
lea    0xe5c(%rip),%r13
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %r14,%rdi
lea    0xe28(%rip),%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
mov    0x14(%rsp),%esi
mov    %esi,(%rbx,%r15,4)
add    %esi,%ebp
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
movslq 0xc(%rsp),%rax
cmp    %rax,%r15
jl     11f0 <main+0x90>
cvtsi2ss %ebp,%xmm0
jmp    122d <main+0xcd>
xorps  %xmm0,%xmm0
movss  %xmm0,0x10(%rsp)
mov    %r14,%rdi
call   1030 <fclose@plt>
xorps  %xmm0,%xmm0
cvtsi2ssl 0xc(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xdea(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd87(%rip),%rdi
jmp    1284 <main+0x124>
lea    0xda1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [32 x i8] c"ERROR: File could not be loaded\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [29 x i8] c"Impossible to allocate space\00"
@.str.4 = [4 x i8] c"%d,\00"
@.str.5 = [25 x i8] c"\0Aarithmetic mean: %.2f \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca float
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %12
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %12
%26 = load i32*, i32** %12
%27 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 4
%31 = trunc i64 %30 to i32
%32 = call i32* @malloc(i32 %31)
store i32* %32, i32** %10
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %21
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %21
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = mul i64 %39, 4
%41 = trunc i64 %40 to i32
%42 = call i32* @malloc(i32 %41)
store i32* %42, i32** %10
store i32 0, i32* %9
br label %43
43: ; preds = %60, %37
%44 = load i32, i32* %9
%45 = load i32, i32* %6
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %63
47: ; preds = %43
%48 = load i32*, i32** %12
%49 = call i32 @fscanf(i32* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%50 = load i32, i32* %7
%51 = load i32*, i32** %10
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 %50, i32* %54
%55 = load i32, i32* %7
%56 = load i32, i32* %8
%57 = add nsw i32 %56, %55
store i32 %57, i32* %8
%58 = load i32, i32* %7
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %47
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %43
63: ; preds = %43
%64 = load i32*, i32** %12
%65 = call i32 @fclose(i32* %64)
%66 = load i32, i32* %8
%67 = sitofp i32 %66 to float
%68 = load i32, i32* %6
%69 = sitofp i32 %68 to float
%70 = fdiv float %67, %69
store float %70, float* %11
%71 = load float, float* %11
%72 = fpext float %71 to double
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), double %72)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [32 x i8] c"ERROR: File could not be loaded\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [29 x i8] c"Impossible to allocate space\00"
@.str.4 = [4 x i8] c"%d,\00"
@.str.5 = [25 x i8] c"\0Aarithmetic mean: %.2f \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = load i8*, i8** %7
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %3
%19 = shl i32 %18, 2
%20 = call i32* @malloc(i32 %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %14
%26 = call i32* @malloc(i32 %19)
%27 = icmp sgt i32 %18, 0
br i1 %27, label %28, label %42
28: ; preds = %25, %28
%29 = phi i64 [ %36, %28 ], [ 0, %25 ]
%30 = phi i32 [ %34, %28 ], [ undef, %25 ]
%31 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%32 = load i32, i32* %4
%33 = getelementptr inbounds i32, i32* %26, i64 %29
store i32 %32, i32* %33
%34 = add nsw i32 %32, %30
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%36 = add nuw nsw i64 %29, 1
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %28, label %40
40: ; preds = %28
%41 = sitofp i32 %34 to float
br label %42
42: ; preds = %40, %25
%43 = phi float [ 0.000000e+00, %25 ], [ %41, %40 ]
%44 = call i32 @fclose(i32* %16)
%45 = load i32, i32* %3
%46 = sitofp i32 %45 to float
%47 = fdiv float %43, %46
%48 = fpext float %47 to double
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), double %48)
ret i32 0
}