#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 */

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
double avg(double x[], int n, bool verbose) {
  double mu;
  int m, i;
  mu = 0.;
  m = 0;
  if (verbose)
    printf("Calculating mu...\n");
  for (i = 0; i < n; i++) {
    mu += x[i];
    if (verbose)
      if (((int)(100 * (i / (n + 0.)))) == m) {
        printf("\r\r\r\r%d%%", m);
        fflush(stdout);
        m++;
      }
  }
  mu /= n + 0.;
  if (verbose)
    printf("\r\r\r\rDone!\n");
  return mu;
}


x86 assembly (clang, -O0):
<avg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1159 <avg+0x39>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fb <avg+0xdb>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11e8 <avg+0xc8>
cvtsi2sdl -0x20(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm0
xorps  %xmm2,%xmm2
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  0xe56(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cmp    -0x1c(%rbp),%eax
jne    11e3 <avg+0xc3>
mov    -0x1c(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e8 <avg+0xc8>
jmp    11ed <avg+0xcd>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1160 <avg+0x40>
cvtsi2sdl -0xc(%rbp),%xmm1
xorps  %xmm0,%xmm0
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     122d <avg+0x10d>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<avg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%r14
test   %edx,%edx
je     1156 <avg+0x26>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
cvtsi2sd %ebp,%xmm1
test   %ebp,%ebp
movsd  %xmm1,0x10(%rsp)
jle    11f4 <avg+0xc4>
mov    %ebp,%ebx
xorpd  %xmm0,%xmm0
movsd  0xe8a(%rip),%xmm3
mov    0x2e63(%rip),%r13
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    1199 <avg+0x69>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r15
cmp    %r15,%rbx
je     11f8 <avg+0xc8>
addsd  (%r14,%r15,8),%xmm0
test   %r12d,%r12d
je     1190 <avg+0x60>
xorps  %xmm2,%xmm2
cvtsi2sd %r15d,%xmm2
divsd  %xmm1,%xmm2
mulsd  %xmm3,%xmm2
cvttsd2si %xmm2,%eax
cmp    %eax,%ebp
jne    1190 <avg+0x60>
lea    0xe45(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1040 <printf@plt>
mov    0x0(%r13),%edi
call   1050 <fflush@plt>
movsd  0xe1d(%rip),%xmm3
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
add    $0x1,%ebp
jmp    1190 <avg+0x60>
xorpd  %xmm0,%xmm0
test   %r12d,%r12d
je     121b <avg+0xeb>
lea    0xe0d(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Calculating mu...\0A\00"
@.str.1 = [9 x i8] c"\0D\0D\0D\0D%d%%\00"
@stdout = global i32 0
@.str.2 = [11 x i8] c"\0D\0D\0D\0DDone!\0A\00"
define double @avg(double* %0, i32 %1, i32 %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
store i32 0, i32* %9
br label %15
15: ; preds = %49, %14
%16 = load i32, i32* %9
%17 = load i32, i32* %5
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %52
19: ; preds = %15
%20 = load double*, double** %4
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = load double, double* %7
%26 = fadd double %25, %24
store double %26, double* %7
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %48
29: ; preds = %19
%30 = load i32, i32* %9
%31 = sitofp i32 %30 to double
%32 = load i32, i32* %5
%33 = sitofp i32 %32 to double
%34 = fadd double %33, 0.000000e+00
%35 = fdiv double %31, %34
%36 = fmul double 1.000000e+02, %35
%37 = fptosi double %36 to i32
%38 = load i32, i32* %8
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %47
40: ; preds = %29
%41 = load i32, i32* %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%43 = load i32, i32* @stdout
%44 = call i32 @fflush(i32 %43)
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %47
47: ; preds = %40, %29
br label %48
48: ; preds = %47, %19
br label %49
49: ; preds = %48
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %15
52: ; preds = %15
%53 = load i32, i32* %5
%54 = sitofp i32 %53 to double
%55 = fadd double %54, 0.000000e+00
%56 = load double, double* %7
%57 = fdiv double %56, %55
store double %57, double* %7
%58 = load i32, i32* %6
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %52
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %60, %52
%63 = load double, double* %7
ret double %63
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"\0D\0D\0D\0D%d%%\00"
@stdout = global i32 0
@str = [10 x i8] c"\0D\0D\0D\0DDone!\00"
@str.3 = [18 x i8] c"Calculating mu...\00"
define double @avg(double* nocapture %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %35
9: ; preds = %7
%10 = sitofp i32 %1 to double
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %9, %31
%13 = phi i64 [ 0, %9 ], [ %33, %31 ]
%14 = phi i32 [ 0, %9 ], [ %32, %31 ]
%15 = phi double [ 0.000000e+00, %9 ], [ %18, %31 ]
%16 = getelementptr inbounds double, double* %0, i64 %13
%17 = load double, double* %16
%18 = fadd double %15, %17
br i1 %4, label %31, label %19
19: ; preds = %12
%20 = trunc i64 %13 to i32
%21 = sitofp i32 %20 to double
%22 = fdiv double %21, %10
%23 = fmul double %22, 1.000000e+02
%24 = fptosi double %23 to i32
%25 = icmp eq i32 %14, %24
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%28 = load i32, i32* @stdout
%29 = tail call i32 @fflush(i32 %28)
%30 = add nsw i32 %14, 1
br label %31
31: ; preds = %12, %26, %19
%32 = phi i32 [ %30, %26 ], [ %14, %19 ], [ %14, %12 ]
%33 = add nuw nsw i64 %13, 1
%34 = icmp eq i64 %33, %11
br i1 %34, label %35, label %12
35: ; preds = %31, %7
%36 = phi double [ 0.000000e+00, %7 ], [ %18, %31 ]
br i1 %4, label %39, label %37
37: ; preds = %35
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %39
39: ; preds = %37, %35
%40 = sitofp i32 %1 to double
%41 = fdiv double %36, %40
ret double %41
}