#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*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Syntaxe : %s <fichier>\n", argv[0]);
    return -1;
  } else {
    FILE *fichier = fopen(argv[1], "r");
    int i = 1;
    int a;
    unsigned long int sum = 0;
    int nbVal = 0;
    while (i == 1) {
      i = fscanf(fichier, "%u", &a);
      if (i == 1) {
        sum += a;
        nbVal++;
      }
    }
    printf("Somme : %u\n", sum);
    printf("Nombre de valeurs : %u\n", nbVal);
    printf("Moyenne : %f\n", ((float)sum) / nbVal);
    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)
cmpl   $0x2,-0x8(%rbp)
je     1171 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <main+0x13f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe98(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    11e4 <main+0xb4>
mov    -0x18(%rbp),%rdi
lea    0xe66(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    11df <main+0xaf>
movslq -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119f <main+0x6f>
mov    -0x28(%rbp),%rsi
lea    0xe2e(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x35(%rbp)
call   1030 <printf@plt>
mov    -0x35(%rbp),%al
mov    -0x2c(%rbp),%esi
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x34(%rbp)
test   %rax,%rax
movss  %xmm0,-0x30(%rbp)
js     1248 <main+0x118>
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
cvtsi2ssl -0x2c(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde0(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    119c <main+0x6c>
mov    0x8(%rsi),%rdi
lea    0xecc(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
lea    0xeb8(%rip),%r14
lea    0xc(%rsp),%r15
jmp    117e <main+0x4e>
nopl   0x0(%rax)
movslq %ecx,%rcx
add    %rcx,%rbx
add    $0x1,%ebp
cmp    $0x1,%eax
jne    11b5 <main+0x85>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <fscanf@plt>
mov    $0x0,%ecx
cmp    $0x1,%eax
jne    1170 <main+0x40>
mov    0xc(%rsp),%ecx
jmp    1170 <main+0x40>
mov    (%rsi),%rsi
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%r14d
jmp    1221 <main+0xf1>
sete   %r15b
lea    0xe5d(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl %r15b,%r15d
add    %ebp,%r15d
lea    0xe4e(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   %rbx,%rbx
js     11f1 <main+0xc1>
cvtsi2ss %rbx,%xmm0
jmp    1206 <main+0xd6>
mov    %rbx,%rax
shr    %rax
and    $0x1,%ebx
or     %rax,%rbx
cvtsi2ss %rbx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %r15d,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe27(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Syntaxe : %s <fichier>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [12 x i8] c"Somme : %u\0A\00"
@.str.4 = [24 x i8] c"Nombre de valeurs : %u\0A\00"
@.str.5 = [14 x i8] c"Moyenne : %f\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 i64
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %3
br label %51
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
store i32 1, i32* %7
store i64 0, i64* %9
store i32 0, i32* %10
br label %23
23: ; preds = %38, %18
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %39
26: ; preds = %23
%27 = load i32*, i32** %6
%28 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %38
31: ; preds = %26
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = load i64, i64* %9
%35 = add i64 %34, %33
store i64 %35, i64* %9
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %38
38: ; preds = %31, %26
br label %23
39: ; preds = %23
%40 = load i64, i64* %9
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 %40)
%42 = load i32, i32* %10
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = load i64, i64* %9
%45 = uitofp i64 %44 to float
%46 = load i32, i32* %10
%47 = sitofp i32 %46 to float
%48 = fdiv float %45, %47
%49 = fpext float %48 to double
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), double %49)
store i32 0, i32* %3
br label %51
51: ; preds = %39, %13
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [24 x i8] c"Syntaxe : %s <fichier>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [12 x i8] c"Somme : %u\0A\00"
@.str.4 = [24 x i8] c"Nombre de valeurs : %u\0A\00"
@.str.5 = [14 x i8] c"Moyenne : %f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %32
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = bitcast i32* %3 to i8*
br label %13
13: ; preds = %8, %13
%14 = phi i32 [ 0, %8 ], [ %23, %13 ]
%15 = phi i64 [ 0, %8 ], [ %21, %13 ]
%16 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%17 = icmp eq i32 %16, 1
%18 = load i32, i32* %3
%19 = select i1 %17, i32 %18, i32 0
%20 = sext i32 %19 to i64
%21 = add i64 %15, %20
%22 = zext i1 %17 to i32
%23 = add nuw nsw i32 %14, %22
br i1 %17, label %13, label %24
24: ; preds = %13
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 %21)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%27 = uitofp i64 %21 to float
%28 = sitofp i32 %23 to float
%29 = fdiv float %27, %28
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), double %30)
br label %32
32: ; preds = %24, %5
%33 = phi i32 [ -1, %5 ], [ 0, %24 ]
ret i32 %33
}