#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 fscanf(int /*<<< orphan*/ *, char *, char *, double *, double *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *fp;
  int ninzu = 0;
  char name[100];
  double height, weight;
  double hsum = 0.0;
  double wsum = 0.0;
  if ((fp = fopen("hw.dat", "r")) == NULL)
    printf("\a Can not open the file.\n");
  else {
    while (fscanf(fp, "%s%lf%lf", name, &height, &weight) == 3) {
      printf("%-10s %5.1f %5.1f\n", name, height, weight);
      ninzu++;
      hsum += height;
      wsum += weight;
    }
    printf("-------------------------------\n");
    printf("Average     %5.1f %5.1f\n", hsum / ninzu, wsum / ninzu);
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
lea    0xe8a(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a3 <main+0x63>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127a <main+0x13a>
jmp    11a8 <main+0x68>
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe6c(%rip),%rsi
lea    -0x88(%rbp),%rcx
lea    -0x90(%rbp),%r8
call   1050 <fscanf@plt>
cmp    $0x3,%eax
jne    1233 <main+0xf3>
lea    -0x80(%rbp),%rsi
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x90(%rbp),%xmm1
ff
lea    0xe3e(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x88(%rbp),%xmm0
ff
addsd  -0x98(%rbp),%xmm0
ff
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
addsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0xa0(%rbp)
ff
jmp    11a8 <main+0x68>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x98(%rbp),%xmm0
ff
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0xa0(%rbp),%xmm1
ff
cvtsi2sdl -0x14(%rbp),%xmm2
divsd  %xmm2,%xmm1
lea    0xdf6(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xe98(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     129a <main+0x14a>
mov    %rax,%r15
lea    0xe82(%rip),%rsi
lea    0x30(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0x18(%rsp),%r8
mov    %rax,%rdi
call   1060 <fscanf@plt>
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
cmp    $0x3,%eax
jne    1256 <main+0x106>
xor    %r14d,%r14d
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0x30(%rsp),%rbx
lea    0xe31(%rip),%r12
lea    0x20(%rsp),%r13
lea    0x18(%rsp),%rbp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
nopl   0x0(%rax)
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
lea    0xe0f(%rip),%rdi
mov    %rbx,%rsi
mov    $0x2,%al
call   1050 <printf@plt>
add    $0x1,%r14d
movsd  0x8(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1060 <fscanf@plt>
cmp    $0x3,%eax
je     11f0 <main+0xa0>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
movsd  %xmm1,0x28(%rsp)
lea    0xddb(%rip),%rdi
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x28(%rsp),%xmm2
divsd  %xmm2,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm2,%xmm1
lea    0xd9c(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    12a6 <main+0x156>
lea    0xdbd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"hw.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"\07 Can not open the file.\0A\00"
@.str.3 = [9 x i8] c"%s%lf%lf\00"
@.str.4 = [19 x i8] c"%-10s %5.1f %5.1f\0A\00"
@.str.5 = [33 x i8] c"-------------------------------\0A\00"
@.str.6 = [25 x i8] c"Average %5.1f %5.1f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
store i32 0, i32* %3
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
%9 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %45
13: ; preds = %0
br label %14
14: ; preds = %19, %13
%15 = load i32*, i32** %2
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%17 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %16, double* %5, double* %6)
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %32
19: ; preds = %14
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%21 = load double, double* %5
%22 = load double, double* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %20, double %21, double %22)
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
%26 = load double, double* %5
%27 = load double, double* %7
%28 = fadd double %27, %26
store double %28, double* %7
%29 = load double, double* %6
%30 = load double, double* %8
%31 = fadd double %30, %29
store double %31, double* %8
br label %14
32: ; preds = %14
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%34 = load double, double* %7
%35 = load i32, i32* %3
%36 = sitofp i32 %35 to double
%37 = fdiv double %34, %36
%38 = load double, double* %8
%39 = load i32, i32* %3
%40 = sitofp i32 %39 to double
%41 = fdiv double %38, %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), double %37, double %41)
%43 = load i32*, i32** %2
%44 = call i32 @fclose(i32* %43)
br label %45
45: ; preds = %32, %11
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"hw.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [9 x i8] c"%s%lf%lf\00"
@.str.4 = [19 x i8] c"%-10s %5.1f %5.1f\0A\00"
@.str.6 = [25 x i8] c"Average %5.1f %5.1f\0A\00"
@str = [32 x i8] c"-------------------------------\00"
@str.7 = [25 x i8] c"\07 Can not open the file.\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca double
%3 = alloca double
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = bitcast double* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %4, double* %2, double* %3)
%11 = icmp eq i32 %10, 3
br i1 %11, label %14, label %30
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
br label %39
14: ; preds = %9, %14
%15 = phi double [ %25, %14 ], [ 0.000000e+00, %9 ]
%16 = phi double [ %23, %14 ], [ 0.000000e+00, %9 ]
%17 = phi i32 [ %21, %14 ], [ 0, %9 ]
%18 = load double, double* %2
%19 = load double, double* %3
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %4, double %18, double %19)
%21 = add nuw nsw i32 %17, 1
%22 = load double, double* %2
%23 = fadd double %16, %22
%24 = load double, double* %3
%25 = fadd double %15, %24
%26 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %4, double* %2, double* %3)
%27 = icmp eq i32 %26, 3
br i1 %27, label %14, label %28
28: ; preds = %14
%29 = sitofp i32 %21 to double
br label %30
30: ; preds = %28, %9
%31 = phi double [ 0.000000e+00, %9 ], [ %29, %28 ]
%32 = phi double [ 0.000000e+00, %9 ], [ %23, %28 ]
%33 = phi double [ 0.000000e+00, %9 ], [ %25, %28 ]
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%35 = fdiv double %32, %31
%36 = fdiv double %33, %31
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), double %35, double %36)
%38 = call i32 @fclose(i32* %7)
br label %39
39: ; preds = %30, %12
ret i32 0
}