#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 binomial(int, int);
double log(int);
double memory_compl(int n, int k, int p, int l) {
  double x, res, aux;
  x = binomial(k / 2, p);
  res = log(x) / log(2);
  aux = (res > l) ? res : l;
  return res + log(log(aux) / log(2) + aux) / log(2);
}


x86 assembly (clang, -O0):
<memory_compl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0xc(%rbp),%esi
call   1030 <binomial@plt>
movsd  %xmm0,-0x18(%rbp)
cvttsd2si -0x18(%rbp),%edi
call   1040 <log@plt>
movsd  %xmm0,-0x30(%rbp)
mov    $0x2,%edi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    119b <memory_compl+0x7b>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11a5 <memory_compl+0x85>
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
cvttsd2si -0x28(%rbp),%edi
call   1040 <log@plt>
movsd  %xmm0,-0x50(%rbp)
mov    $0x2,%edi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
movsd  %xmm0,-0x48(%rbp)
mov    $0x2,%edi
call   1040 <log@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory_compl>:
push   %rbx
sub    $0x20,%rsp
mov    %ecx,%ebx
mov    %esi,%edi
shr    $0x1f,%edi
add    %esi,%edi
sar    %edi
mov    %edx,%esi
call   1030 <binomial@plt>
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
movsd  %xmm0,0x10(%rsp)
mov    $0x2,%edi
call   1040 <log@plt>
cvtsi2sd %ebx,%xmm1
movsd  0x10(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
maxsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
cvttsd2si %xmm2,%edi
call   1040 <log@plt>
movsd  %xmm0,0x18(%rsp)
mov    $0x2,%edi
call   1040 <log@plt>
movsd  0x18(%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0x8(%rsp),%xmm1
cvttsd2si %xmm1,%edi
call   1040 <log@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%edi
call   1040 <log@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @memory_compl(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %6
%13 = sdiv i32 %12, 2
%14 = load i32, i32* %7
%15 = call double @binomial(i32 %13, i32 %14)
store double %15, double* %9
%16 = load double, double* %9
%17 = fptosi double %16 to i32
%18 = call double @log(i32 %17)
%19 = call double @log(i32 2)
%20 = fdiv double %18, %19
store double %20, double* %10
%21 = load double, double* %10
%22 = load i32, i32* %8
%23 = sitofp i32 %22 to double
%24 = fcmp ogt double %21, %23
br i1 %24, label %25, label %27
25: ; preds = %4
%26 = load double, double* %10
br label %30
27: ; preds = %4
%28 = load i32, i32* %8
%29 = sitofp i32 %28 to double
br label %30
30: ; preds = %27, %25
%31 = phi double [ %26, %25 ], [ %29, %27 ]
store double %31, double* %11
%32 = load double, double* %10
%33 = load double, double* %11
%34 = fptosi double %33 to i32
%35 = call double @log(i32 %34)
%36 = call double @log(i32 2)
%37 = fdiv double %35, %36
%38 = load double, double* %11
%39 = fadd double %37, %38
%40 = fptosi double %39 to i32
%41 = call double @log(i32 %40)
%42 = call double @log(i32 2)
%43 = fdiv double %41, %42
%44 = fadd double %32, %43
ret double %44
}

LLVM IR (-O2):
define double @memory_compl(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = sdiv i32 %1, 2
%6 = tail call double @binomial(i32 %5, i32 %2)
%7 = fptosi double %6 to i32
%8 = tail call double @log(i32 %7)
%9 = tail call double @log(i32 2)
%10 = fdiv double %8, %9
%11 = sitofp i32 %3 to double
%12 = fcmp ogt double %10, %11
%13 = select i1 %12, double %10, double %11
%14 = fptosi double %13 to i32
%15 = tail call double @log(i32 %14)
%16 = tail call double @log(i32 2)
%17 = fdiv double %15, %16
%18 = fadd double %17, %13
%19 = fptosi double %18 to i32
%20 = tail call double @log(i32 %19)
%21 = tail call double @log(i32 2)
%22 = fdiv double %20, %21
%23 = fadd double %10, %22
ret double %23
}