#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*/ add_to_array(int);
int /*<<< orphan*/ floor(int);
int log(double);
int /*<<< orphan*/ make_hdl(int, double, double);
double pow(double, int /*<<< orphan*/);
void binary_ks(int n) {
  double l;
  double h;
  if (n < 2)
    return;
  l = pow(2.0, floor(log(n) / log(2.0)));
  if (l == n)
    l = l / 2;
  h = n - l;
  add_to_array(n);
  make_hdl(n, l, h);
  binary_ks(l);
  binary_ks(h);
}


x86 assembly (clang, -O0):
<binary_ks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    117a <binary_ks+0x1a>
jmp    1224 <binary_ks+0xc4>
cvtsi2sdl -0x4(%rbp),%xmm0
call   1060 <log@plt>
mov    %eax,-0x1c(%rbp)
movsd  0xe71(%rip),%xmm0
call   1060 <log@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1080 <floor@plt>
mov    %eax,%edi
movsd  0xe53(%rip),%xmm0
call   1070 <pow@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jne    11e7 <binary_ks+0x87>
jp     11e7 <binary_ks+0x87>
movsd  -0x10(%rbp),%xmm0
movsd  0xe22(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <add_to_array@plt>
mov    -0x4(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1030 <make_hdl@plt>
cvttsd2si -0x10(%rbp),%edi
call   1050 <binary_ks@plt>
cvttsd2si -0x18(%rbp),%edi
call   1050 <binary_ks@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_ks>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jl     1228 <binary_ks+0xc8>
mov    %edi,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1060 <log@plt>
mov    %eax,%ebp
movsd  0xe64(%rip),%xmm0
call   1060 <log@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1080 <floor@plt>
movsd  0xe49(%rip),%xmm0
mov    %eax,%edi
call   1070 <pow@plt>
movapd %xmm0,%xmm1
mulsd  0xe3e(%rip),%xmm1
movapd %xmm0,%xmm3
movsd  0x8(%rsp),%xmm2
cmpeqsd %xmm2,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm0,%xmm3
orpd   %xmm1,%xmm3
movapd %xmm3,0x10(%rsp)
subsd  %xmm3,%xmm2
movsd  %xmm2,0x8(%rsp)
mov    %ebx,%edi
call   1040 <add_to_array@plt>
mov    %ebx,%edi
movaps 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <make_hdl@plt>
cvttsd2si 0x10(%rsp),%edi
call   1050 <binary_ks@plt>
cvttsd2si 0x8(%rsp),%ebx
cmp    $0x1,%ebx
jg     1180 <binary_ks+0x20>
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @binary_ks(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 2
br i1 %6, label %7, label %8
7: ; preds = %1
br label %38
8: ; preds = %1
%9 = load i32, i32* %2
%10 = sitofp i32 %9 to double
%11 = call i32 @log(double %10)
%12 = call i32 @log(double 2.000000e+00)
%13 = sdiv i32 %11, %12
%14 = call i32 @floor(i32 %13)
%15 = call double @pow(double 2.000000e+00, i32 %14)
store double %15, double* %3
%16 = load double, double* %3
%17 = load i32, i32* %2
%18 = sitofp i32 %17 to double
%19 = fcmp oeq double %16, %18
br i1 %19, label %20, label %23
20: ; preds = %8
%21 = load double, double* %3
%22 = fdiv double %21, 2.000000e+00
store double %22, double* %3
br label %23
23: ; preds = %20, %8
%24 = load i32, i32* %2
%25 = sitofp i32 %24 to double
%26 = load double, double* %3
%27 = fsub double %25, %26
store double %27, double* %4
%28 = load i32, i32* %2
%29 = call i32 @add_to_array(i32 %28)
%30 = load i32, i32* %2
%31 = load double, double* %3
%32 = load double, double* %4
%33 = call i32 @make_hdl(i32 %30, double %31, double %32)
%34 = load double, double* %3
%35 = fptosi double %34 to i32
%36 = load double, double* %4
%37 = fptosi double %36 to i32
br label %38
38: ; preds = %23, %7
ret void
}

LLVM IR (-O2):
define void @binary_ks(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %20, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %18, %3 ], [ %0, %1 ]
%5 = sitofp i32 %4 to double
%6 = tail call i32 @log(double %5)
%7 = tail call i32 @log(double 2.000000e+00)
%8 = sdiv i32 %6, %7
%9 = tail call i32 @floor(i32 %8)
%10 = tail call double @pow(double 2.000000e+00, i32 %9)
%11 = fcmp oeq double %10, %5
%12 = fmul double %10, 5.000000e-01
%13 = select i1 %11, double %12, double %10
%14 = fsub double %5, %13
%15 = tail call i32 @add_to_array(i32 %4)
%16 = tail call i32 @make_hdl(i32 %4, double %13, double %14)
%17 = fptosi double %13 to i32
tail call void @binary_ks(i32 %17)
%18 = fptosi double %14 to i32
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %3
20: ; preds = %3, %1
ret void
}