#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 */
double M_LOG2E;
double factorial(int);
double log2(int);
double pow(int, int);
double MMLparameter_cost(double *p, int numProbs, double N) {
  double h = factorial(numProbs - 1);
  double F = 1.0 / p[0];
  double cost;
  int i;
  for (i = 1; i < numProbs - 1; i++) {
    F *= N / p[i];
  }
  cost = 0.5 * log2(1 + F / (h * h * pow(12, numProbs - 1)));
  cost += 0.5 * (numProbs - 1) * M_LOG2E;
  return cost;
}


x86 assembly (clang, -O0):
<MMLparameter_cost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1040 <factorial@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xea0(%rip),%xmm0
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ab <MMLparameter_cost+0x7b>
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1170 <MMLparameter_cost+0x40>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    $0xc,%edi
call   1050 <pow@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  0xe0f(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log2@plt>
movaps %xmm0,%xmm1
movsd  0xdff(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xde4(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2db1(%rip),%rax
movsd  (%rax),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MMLparameter_cost>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,(%rsp)
mov    %esi,%ebp
mov    %rdi,%rbx
lea    -0x1(%rbp),%r14d
mov    %r14d,%edi
call   1040 <factorial@plt>
movsd  0xeaa(%rip),%xmm1
divsd  (%rbx),%xmm1
cmp    $0x3,%ebp
jl     11ca <MMLparameter_cost+0x9a>
mov    %r14d,%eax
add    $0xffffffffffffffff,%rax
cmp    $0x2,%r14d
movsd  (%rsp),%xmm3
jne    1178 <MMLparameter_cost+0x48>
mov    $0x1,%ecx
jmp    11bd <MMLparameter_cost+0x8d>
mov    %rax,%rdx
and    $0xfffffffffffffffe,%rdx
neg    %rdx
mov    $0x1,%ecx
nopw   0x0(%rax,%rax,1)
movapd %xmm3,%xmm2
divsd  (%rbx,%rcx,8),%xmm2
mulsd  %xmm1,%xmm2
movapd %xmm3,%xmm1
divsd  0x8(%rbx,%rcx,8),%xmm1
mulsd  %xmm2,%xmm1
lea    (%rdx,%rcx,1),%rsi
add    $0x2,%rsi
add    $0x2,%rcx
cmp    $0x1,%rsi
jne    1190 <MMLparameter_cost+0x60>
test   $0x1,%al
je     11ca <MMLparameter_cost+0x9a>
divsd  (%rbx,%rcx,8),%xmm3
mulsd  %xmm3,%xmm1
movsd  %xmm1,(%rsp)
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xc,%edi
mov    %r14d,%esi
call   1050 <pow@plt>
mulsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0xe03(%rip),%xmm1
cvttsd2si %xmm1,%edi
call   1030 <log2@plt>
movsd  0xdfa(%rip),%xmm1
mulsd  %xmm1,%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %r14d,%xmm2
mulsd  %xmm1,%xmm2
mov    0x2dbb(%rip),%rax
mulsd  (%rax),%xmm2
addsd  %xmm2,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@M_LOG2E = global double 0.000000e+00
define double @MMLparameter_cost(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
%13 = call double @factorial(i32 %12)
store double %13, double* %7
%14 = load double*, double** %4
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = fdiv double 1.000000e+00, %16
store double %17, double* %8
store i32 1, i32* %10
br label %18
18: ; preds = %33, %3
%19 = load i32, i32* %10
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, 1
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %36
23: ; preds = %18
%24 = load double, double* %6
%25 = load double*, double** %4
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = fdiv double %24, %29
%31 = load double, double* %8
%32 = fmul double %31, %30
store double %32, double* %8
br label %33
33: ; preds = %23
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %18
36: ; preds = %18
%37 = load double, double* %8
%38 = load double, double* %7
%39 = load double, double* %7
%40 = fmul double %38, %39
%41 = load i32, i32* %5
%42 = sub nsw i32 %41, 1
%43 = call double @pow(i32 12, i32 %42)
%44 = fmul double %40, %43
%45 = fdiv double %37, %44
%46 = fadd double 1.000000e+00, %45
%47 = fptosi double %46 to i32
%48 = call double @log2(i32 %47)
%49 = fmul double 5.000000e-01, %48
store double %49, double* %9
%50 = load i32, i32* %5
%51 = sub nsw i32 %50, 1
%52 = sitofp i32 %51 to double
%53 = fmul double 5.000000e-01, %52
%54 = load double, double* @M_LOG2E
%55 = load double, double* %9
%56 = call double @llvm.fmuladd.f64(double %53, double %54, double %55)
store double %56, double* %9
%57 = load double, double* %9
ret double %57
}

LLVM IR (-O2):
@M_LOG2E = global double 0.000000e+00
define double @MMLparameter_cost(double* nocapture %0, i32 %1, double %2) {
%4 = add nsw i32 %1, -1
%5 = tail call double @factorial(i32 %4)
%6 = load double, double* %0
%7 = fdiv double 1.000000e+00, %6
%8 = icmp sgt i32 %1, 2
br i1 %8, label %9, label %42
9: ; preds = %3
%10 = zext i32 %4 to i64
%11 = add nsw i64 %10, -1
%12 = and i64 %11, 1
%13 = icmp eq i32 %4, 2
br i1 %13, label %32, label %14
14: ; preds = %9
%15 = and i64 %11, -2
br label %16
16: ; preds = %16, %14
%17 = phi i64 [ 1, %14 ], [ %29, %16 ]
%18 = phi double [ %7, %14 ], [ %28, %16 ]
%19 = phi i64 [ 0, %14 ], [ %30, %16 ]
%20 = getelementptr inbounds double, double* %0, i64 %17
%21 = load double, double* %20
%22 = fdiv double %2, %21
%23 = fmul double %18, %22
%24 = add nuw nsw i64 %17, 1
%25 = getelementptr inbounds double, double* %0, i64 %24
%26 = load double, double* %25
%27 = fdiv double %2, %26
%28 = fmul double %23, %27
%29 = add nuw nsw i64 %17, 2
%30 = add i64 %19, 2
%31 = icmp eq i64 %30, %15
br i1 %31, label %32, label %16
32: ; preds = %16, %9
%33 = phi double [ undef, %9 ], [ %28, %16 ]
%34 = phi i64 [ 1, %9 ], [ %29, %16 ]
%35 = phi double [ %7, %9 ], [ %28, %16 ]
%36 = icmp eq i64 %12, 0
br i1 %36, label %42, label %37
37: ; preds = %32
%38 = getelementptr inbounds double, double* %0, i64 %34
%39 = load double, double* %38
%40 = fdiv double %2, %39
%41 = fmul double %35, %40
br label %42
42: ; preds = %37, %32, %3
%43 = phi double [ %7, %3 ], [ %33, %32 ], [ %41, %37 ]
%44 = fmul double %5, %5
%45 = tail call double @pow(i32 12, i32 %4)
%46 = fmul double %44, %45
%47 = fdiv double %43, %46
%48 = fadd double %47, 1.000000e+00
%49 = fptosi double %48 to i32
%50 = tail call double @log2(i32 %49)
%51 = fmul double %50, 5.000000e-01
%52 = sitofp i32 %4 to double
%53 = fmul double %52, 5.000000e-01
%54 = load double, double* @M_LOG2E
%55 = tail call double @llvm.fmuladd.f64(double %53, double %54, double %51)
ret double %55
}