#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, double *);
double max(double *, int);
double mean(double *, int);
double min(double *, int);
int /*<<< orphan*/ printf(char *, ...);
double sd(double *, int);
double var(double *, int);
int main(void) {
  FILE *fp = fopen("ass2.dat", "r");
  int i = 0, length;
  double data[20];
  while (fscanf(fp, "%lf", &data[i]) != EOF) {
    printf("%lf ", data[i]);
    if (i % 5 == 4)
      printf("\n");
    i++;
  }
  length = i - 1;
  printf("== ANALYSIS RESULT ==\n");
  printf("avg: %10lf\n", mean(data, length));
  printf("var: %10lf\n", var(data, length));
  printf("sd:  %10lf\n", sd(data, length));
  printf("max: %10lf\n", max(data, length));
  printf("min: %10lf\n", min(data, length));
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe59(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
lea    -0xc0(%rbp),%rdx
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe2e(%rip),%rsi
call   1080 <fscanf@plt>
mov    0x2dff(%rip),%rcx
cmp    (%rcx),%rax
je     123d <main+0xad>
movslq -0x14(%rbp),%rax
movsd  -0xc0(%rbp,%rax,8),%xmm0
ff ff
lea    0xe09(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x4,%edx
jne    122f <main+0x9f>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c0 <main+0x30>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   10b0 <mean@plt>
lea    0xdc1(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1090 <var@plt>
lea    0xdb0(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <sd@plt>
lea    0xd9f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1070 <max@plt>
lea    0xd8e(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <min@plt>
lea    0xd7d(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0xe38(%rip),%rdi
lea    0xe3a(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r14
lea    0xe2d(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   10a0 <fscanf@plt>
mov    0x2df8(%rip),%rcx
mov    $0xffffffff,%ebp
cmp    (%rcx),%rax
jne    12a1 <main+0xf1>
lea    0xe4b(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
call   10d0 <mean@plt>
lea    0xdf6(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   10b0 <var@plt>
lea    0xdea(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <sd@plt>
lea    0xdde(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1090 <max@plt>
lea    0xdd2(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <min@plt>
lea    0xdc6(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8(%rsp),%rbx
mov    $0x4,%r13d
xor    %r15d,%r15d
mov    $0xffffffff,%ebp
jmp    12f1 <main+0x141>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
lea    0xd41(%rip),%rsi
mov    %rbx,%rdx
call   10a0 <fscanf@plt>
add    $0xffffffff,%r13d
add    $0x1,%r15d
add    $0x1,%ebp
add    $0x8,%rbx
mov    0x2d00(%rip),%rcx
cmp    (%rcx),%rax
je     11fe <main+0x4e>
mov    %r15d,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x22,%rax
lea    (%rax,%rax,4),%r12d
movsd  -0x8(%rbx),%xmm0
lea    0xcfe(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
add    %r13d,%r12d
jne    12c0 <main+0x110>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12c0 <main+0x110>

LLVM IR (-O0):
@.str = [9 x i8] c"ass2.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%lf\00"
@EOF = global i64 0
@.str.3 = [5 x i8] c"%lf \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [23 x i8] c"== ANALYSIS RESULT ==\0A\00"
@.str.6 = [12 x i8] c"avg: %10lf\0A\00"
@.str.7 = [12 x i8] c"var: %10lf\0A\00"
@.str.8 = [12 x i8] c"sd: %10lf\0A\00"
@.str.9 = [12 x i8] c"max: %10lf\0A\00"
@.str.10 = [12 x i8] c"min: %10lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [20 x double]
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
store i32 0, i32* %3
br label %7
7: ; preds = %26, %0
%8 = load i32*, i32** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [20 x double], [20 x double]* %5, i64 0, i64 %10
%12 = call i64 @fscanf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %11)
%13 = load i64, i64* @EOF
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %7
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [20 x double], [20 x double]* %5, i64 0, i64 %17
%19 = load double, double* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %19)
%21 = load i32, i32* %3
%22 = srem i32 %21, 5
%23 = icmp eq i32 %22, 4
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %24, %15
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %7
29: ; preds = %7
%30 = load i32, i32* %3
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%33 = getelementptr inbounds [20 x double], [20 x double]* %5, i64 0, i64 0
%34 = load i32, i32* %4
%35 = call double @mean(double* %33, i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), double %35)
%37 = getelementptr inbounds [20 x double], [20 x double]* %5, i64 0, i64 0
%38 = load i32, i32* %4
%39 = call double @var(double* %37, i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), double %39)
%41 = getelementptr inbounds [20 x double], [20 x double]* %5, i64 0, i64 0
%42 = load i32, i32* %4
%43 = call double @sd(double* %41, i32 %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), double %43)
%45 = getelementptr inbounds [20 x double], [20 x double]* %5, i64 0, i64 0
%46 = load i32, i32* %4
%47 = call double @max(double* %45, i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), double %47)
%49 = getelementptr inbounds [20 x double], [20 x double]* %5, i64 0, i64 0
%50 = load i32, i32* %4
%51 = call double @min(double* %49, i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), double %51)
%53 = load i32*, i32** %2
%54 = call i32 @fclose(i32* %53)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"ass2.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%lf\00"
@EOF = global i64 0
@.str.3 = [5 x i8] c"%lf \00"
@.str.6 = [12 x i8] c"avg: %10lf\0A\00"
@.str.7 = [12 x i8] c"var: %10lf\0A\00"
@.str.8 = [12 x i8] c"sd: %10lf\0A\00"
@.str.9 = [12 x i8] c"max: %10lf\0A\00"
@.str.10 = [12 x i8] c"min: %10lf\0A\00"
@str = [22 x i8] c"== ANALYSIS RESULT ==\00"
define i32 @main() {
%1 = alloca [20 x double]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = bitcast [20 x double]* %1 to i8*
%4 = getelementptr inbounds [20 x double], [20 x double]* %1, i64 0, i64 0
%5 = call i64 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %4)
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %27, label %8
8: ; preds = %0, %18
%9 = phi i64 [ %19, %18 ], [ 0, %0 ]
%10 = phi double* [ %20, %18 ], [ %4, %0 ]
%11 = load double, double* %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %11)
%13 = trunc i64 %9 to i32
%14 = urem i32 %13, 5
%15 = icmp eq i32 %14, 4
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @putchar(i32 10)
br label %18
18: ; preds = %16, %8
%19 = add nuw i64 %9, 1
%20 = getelementptr inbounds [20 x double], [20 x double]* %1, i64 0, i64 %19
%21 = call i64 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %20)
%22 = load i64, i64* @EOF
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %8
24: ; preds = %18
%25 = trunc i64 %19 to i32
%26 = add i32 %25, -1
br label %27
27: ; preds = %24, %0
%28 = phi i32 [ -1, %0 ], [ %26, %24 ]
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%30 = call double @mean(double* %4, i32 %28)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), double %30)
%32 = call double @var(double* %4, i32 %28)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), double %32)
%34 = call double @sd(double* %4, i32 %28)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), double %34)
%36 = call double @max(double* %4, i32 %28)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), double %36)
%38 = call double @min(double* %4, i32 %28)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), double %38)
%40 = call i32 @fclose(i32* %2)
ret i32 0
}