#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 */
scalar_t__ EOF;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, float *, float *, float *);
int /*<<< orphan*/ printf(char *, float, float, float);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  float x, y, z;
  float bx = 0, by = 0, bz = 0;
  int c = 0;
  FILE *fp;
  if (argc < 2) {
    fprintf(stderr, "Utilizzo programma: lab01_1.exe <file>\n");
    return -1;
  }
  if ((fp = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "Impossibile aprire il file %s\n", argv[1]);
    return -2;
  }
  while (fscanf(fp, "%f %f %f", &x, &y, &z) != EOF) {
    c++;
    bx += x;
    by += y;
    bz += z;
  }
  bx = bx / (float)c;
  by = by / (float)c;
  bz = bz / (float)c;
  printf("Baricentro: %.1f %.1f %.1f\n", bx, by, bz);
  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)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a2 <main+0x62>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b6 <main+0x176>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11ef <main+0xaf>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12b6 <main+0x176>
jmp    11f4 <main+0xb4>
mov    -0x38(%rbp),%rdi
lea    0xe4a(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1040 <fscanf@plt>
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%rax
je     125b <main+0x11b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movss  -0x14(%rbp),%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x1c(%rbp),%xmm0
addss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
jmp    11f4 <main+0xb4>
movss  -0x20(%rbp),%xmm0
cvtsi2ssl -0x2c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x24(%rbp),%xmm0
cvtsi2ssl -0x2c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x28(%rbp),%xmm0
cvtsi2ssl -0x2c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x20(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
movss  -0x28(%rbp),%xmm2
lea    0xda8(%rip),%rdi
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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jg     1174 <main+0x34>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1278 <main+0x138>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1258 <main+0x118>
mov    %rax,%rbx
lea    0xeaf(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    0x2e32(%rip),%r14
xorps  %xmm0,%xmm0
xorps  %xmm1,%xmm1
xorps  %xmm2,%xmm2
xorps  %xmm3,%xmm3
cmp    (%r14),%rax
je     123c <main+0xfc>
xorps  %xmm2,%xmm2
xor    %ebp,%ebp
lea    0x8(%rsp),%r15
lea    0x4(%rsp),%r12
mov    %rsp,%r13
xorps  %xmm1,%xmm1
xorps  %xmm0,%xmm0
nop
add    $0x1,%ebp
addss  0x8(%rsp),%xmm0
movss  %xmm0,0x10(%rsp)
addss  0x4(%rsp),%xmm1
movss  %xmm1,0xc(%rsp)
addss  (%rsp),%xmm2
movss  %xmm2,0x14(%rsp)
mov    %rbx,%rdi
lea    0xe39(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1040 <fscanf@plt>
movss  0xc(%rsp),%xmm1
movss  0x10(%rsp),%xmm0
movss  0x14(%rsp),%xmm2
cmp    (%r14),%rax
jne    11e0 <main+0xa0>
xorps  %xmm3,%xmm3
cvtsi2ss %ebp,%xmm3
divss  %xmm3,%xmm0
divss  %xmm3,%xmm1
divss  %xmm3,%xmm2
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    1278 <main+0x138>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdbe(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xfffffffe,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Utilizzo programma: lab01_1.exe <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Impossibile aprire il file %s\0A\00"
@.str.3 = [9 x i8] c"%f %f %f\00"
@EOF = global i64 0
@.str.4 = [28 x i8] c"Baricentro: %.1f %.1f %.1f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca i32
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store float 0.000000e+00, float* %9
store float 0.000000e+00, float* %10
store float 0.000000e+00, float* %11
store i32 0, i32* %12
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %66
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %13
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 -2, i32* %3
br label %66
31: ; preds = %19
br label %32
32: ; preds = %37, %31
%33 = load i32*, i32** %13
%34 = call i64 @fscanf(i32* %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float* %6, float* %7, float* %8)
%35 = load i64, i64* @EOF
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %49
37: ; preds = %32
%38 = load i32, i32* %12
%39 = add nsw i32 %38, 1
store i32 %39, i32* %12
%40 = load float, float* %6
%41 = load float, float* %9
%42 = fadd float %41, %40
store float %42, float* %9
%43 = load float, float* %7
%44 = load float, float* %10
%45 = fadd float %44, %43
store float %45, float* %10
%46 = load float, float* %8
%47 = load float, float* %11
%48 = fadd float %47, %46
store float %48, float* %11
br label %32
49: ; preds = %32
%50 = load float, float* %9
%51 = load i32, i32* %12
%52 = sitofp i32 %51 to float
%53 = fdiv float %50, %52
store float %53, float* %9
%54 = load float, float* %10
%55 = load i32, i32* %12
%56 = sitofp i32 %55 to float
%57 = fdiv float %54, %56
store float %57, float* %10
%58 = load float, float* %11
%59 = load i32, i32* %12
%60 = sitofp i32 %59 to float
%61 = fdiv float %58, %60
store float %61, float* %11
%62 = load float, float* %9
%63 = load float, float* %10
%64 = load float, float* %11
%65 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), float %62, float %63, float %64)
store i32 0, i32* %3
br label %66
66: ; preds = %49, %25, %16
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Utilizzo programma: lab01_1.exe <file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"Impossibile aprire il file %s\0A\00"
@.str.3 = [9 x i8] c"%f %f %f\00"
@EOF = global i64 0
@.str.4 = [28 x i8] c"Baricentro: %.1f %.1f %.1f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = bitcast float* %3 to i8*
%7 = bitcast float* %4 to i8*
%8 = bitcast float* %5 to i8*
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %52
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = call i64 @fscanf(i32* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float* %3, float* %4, float* %5)
%20 = load i64, i64* @EOF
%21 = icmp eq i64 %19, %20
br i1 %21, label %43, label %26
22: ; preds = %13
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %14
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %52
26: ; preds = %18, %26
%27 = phi i32 [ %31, %26 ], [ 0, %18 ]
%28 = phi float [ %37, %26 ], [ 0.000000e+00, %18 ]
%29 = phi float [ %35, %26 ], [ 0.000000e+00, %18 ]
%30 = phi float [ %33, %26 ], [ 0.000000e+00, %18 ]
%31 = add nuw nsw i32 %27, 1
%32 = load float, float* %3
%33 = fadd float %30, %32
%34 = load float, float* %4
%35 = fadd float %29, %34
%36 = load float, float* %5
%37 = fadd float %28, %36
%38 = call i64 @fscanf(i32* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float* %3, float* %4, float* %5)
%39 = load i64, i64* @EOF
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %26
41: ; preds = %26
%42 = sitofp i32 %31 to float
br label %43
43: ; preds = %41, %18
%44 = phi float [ 0.000000e+00, %18 ], [ %33, %41 ]
%45 = phi float [ 0.000000e+00, %18 ], [ %35, %41 ]
%46 = phi float [ 0.000000e+00, %18 ], [ %37, %41 ]
%47 = phi float [ 0.000000e+00, %18 ], [ %42, %41 ]
%48 = fdiv float %44, %47
%49 = fdiv float %45, %47
%50 = fdiv float %46, %47
%51 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), float %48, float %49, float %50)
br label %52
52: ; preds = %43, %22, %10
%53 = phi i32 [ -1, %10 ], [ -2, %22 ], [ 0, %43 ]
ret i32 %53
}