#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);
double ceil(int);
int first;
double floor(int);
int log(double);
int /*<<< orphan*/ make_general_hdl(int);
int /*<<< orphan*/ make_hdl(int, double, double);
double pow(double, double);
void hybrid_ks(int n) {
  static first = 0;
  double l, h;
  if (n < 29) {
    add_to_array(n);
    make_general_hdl(n);
    return;
  }
  if (first == 0) {
    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);
    first = 1;
    hybrid_ks(l);
    hybrid_ks(h);
  } else {
    h = floor(n / 2.0);
    l = ceil(n / 2.0);
    add_to_array(n);
    make_hdl(n, l, h);
    hybrid_ks(l);
    hybrid_ks(h);
  }
}


x86 assembly (clang, -O0):
<hybrid_ks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1d,-0x4(%rbp)
jge    11aa <hybrid_ks+0x2a>
mov    -0x4(%rbp),%edi
call   1050 <add_to_array@plt>
mov    -0x4(%rbp),%edi
call   1060 <make_general_hdl@plt>
jmp    12dd <hybrid_ks+0x15d>
cmpl   $0x0,0x2eb3(%rip)
jne    1271 <hybrid_ks+0xf1>
cvtsi2sdl -0x4(%rbp),%xmm0
call   1080 <log@plt>
mov    %eax,-0x1c(%rbp)
movsd  0xe34(%rip),%xmm0
call   1080 <log@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   10a0 <floor@plt>
movaps %xmm0,%xmm1
movsd  0xe15(%rip),%xmm0
call   1090 <pow@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jne    1225 <hybrid_ks+0xa5>
jp     1225 <hybrid_ks+0xa5>
movsd  -0x10(%rbp),%xmm0
movsd  0xde4(%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   1050 <add_to_array@plt>
mov    -0x4(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <make_hdl@plt>
movl   $0x1,0x2e0c(%rip)
cvttsd2si -0x10(%rbp),%edi
call   1070 <hybrid_ks@plt>
cvttsd2si -0x18(%rbp),%edi
call   1070 <hybrid_ks@plt>
jmp    12dd <hybrid_ks+0x15d>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xd82(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   10a0 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xd63(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <add_to_array@plt>
mov    -0x4(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <make_hdl@plt>
cvttsd2si -0x10(%rbp),%edi
call   1070 <hybrid_ks@plt>
cvttsd2si -0x18(%rbp),%edi
call   1070 <hybrid_ks@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hybrid_ks>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
cmp    $0x1d,%edi
jge    1252 <hybrid_ks+0xd2>
mov    %ebx,%edi
call   1060 <add_to_array@plt>
mov    %ebx,%edi
add    $0x28,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <make_general_hdl@plt>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm0,0x8(%rsp)
call   1090 <log@plt>
mov    %eax,%ebp
movsd  0xe3b(%rip),%xmm0
call   1090 <log@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   10a0 <floor@plt>
call   1050 <exp2@plt>
movapd %xmm0,%xmm1
mulsd  0xe1f(%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   1060 <add_to_array@plt>
mov    %ebx,%edi
movaps 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1040 <make_hdl@plt>
movapd 0x10(%rsp),%xmm0
movb   $0x1,0x2e2a(%rip)
cvttsd2si %xmm0,%edi
call   1080 <hybrid_ks@plt>
cvttsd2si 0x8(%rsp),%ebx
cmp    $0x1d,%ebx
jl     1191 <hybrid_ks+0x11>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
cmpb   $0x0,0x2e04(%rip)
je     11b0 <hybrid_ks+0x30>
mulsd  0xd9a(%rip),%xmm0
cvttsd2si %xmm0,%ebp
mov    %ebp,%edi
call   10a0 <floor@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <ceil@plt>
movapd %xmm0,0x10(%rsp)
mov    %ebx,%edi
call   1060 <add_to_array@plt>
mov    %ebx,%edi
movaps 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1040 <make_hdl@plt>
movapd 0x10(%rsp),%xmm0
jmp    123a <hybrid_ks+0xba>

LLVM IR (-O0):
@hybrid_ks.first = internal global i32 0
@first = global i32 0
define void @hybrid_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, 29
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* %2
%9 = call i32 @add_to_array(i32 %8)
%10 = load i32, i32* %2
%11 = call i32 @make_general_hdl(i32 %10)
br label %66
12: ; preds = %1
%13 = load i32, i32* @hybrid_ks.first
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %45
15: ; preds = %12
%16 = load i32, i32* %2
%17 = sitofp i32 %16 to double
%18 = call i32 @log(double %17)
%19 = call i32 @log(double 2.000000e+00)
%20 = sdiv i32 %18, %19
%21 = call double @floor(i32 %20)
%22 = call double @pow(double 2.000000e+00, double %21)
store double %22, double* %3
%23 = load double, double* %3
%24 = load i32, i32* %2
%25 = sitofp i32 %24 to double
%26 = fcmp oeq double %23, %25
br i1 %26, label %27, label %30
27: ; preds = %15
%28 = load double, double* %3
%29 = fdiv double %28, 2.000000e+00
store double %29, double* %3
br label %30
30: ; preds = %27, %15
%31 = load i32, i32* %2
%32 = sitofp i32 %31 to double
%33 = load double, double* %3
%34 = fsub double %32, %33
store double %34, double* %4
%35 = load i32, i32* %2
%36 = call i32 @add_to_array(i32 %35)
%37 = load i32, i32* %2
%38 = load double, double* %3
%39 = load double, double* %4
%40 = call i32 @make_hdl(i32 %37, double %38, double %39)
store i32 1, i32* @hybrid_ks.first
%41 = load double, double* %3
%42 = fptosi double %41 to i32
%43 = load double, double* %4
%44 = fptosi double %43 to i32
br label %66
45: ; preds = %12
%46 = load i32, i32* %2
%47 = sitofp i32 %46 to double
%48 = fdiv double %47, 2.000000e+00
%49 = fptosi double %48 to i32
%50 = call double @floor(i32 %49)
store double %50, double* %4
%51 = load i32, i32* %2
%52 = sitofp i32 %51 to double
%53 = fdiv double %52, 2.000000e+00
%54 = fptosi double %53 to i32
%55 = call double @ceil(i32 %54)
store double %55, double* %3
%56 = load i32, i32* %2
%57 = call i32 @add_to_array(i32 %56)
%58 = load i32, i32* %2
%59 = load double, double* %3
%60 = load double, double* %4
%61 = call i32 @make_hdl(i32 %58, double %59, double %60)
%62 = load double, double* %3
%63 = fptosi double %62 to i32
%64 = load double, double* %4
%65 = fptosi double %64 to i32
br label %66
66: ; preds = %7, %45, %30
ret void
}

LLVM IR (-O2):
@hybrid_ks.first = internal unnamed_addr global i1 false
@first = global i32 0
define void @hybrid_ks(i32 %0) {
%2 = icmp slt i32 %0, 29
br i1 %2, label %3, label %7
3: ; preds = %23, %1
%4 = phi i32 [ %0, %1 ], [ %27, %23 ]
%5 = tail call i32 @add_to_array(i32 %4)
%6 = tail call i32 @make_general_hdl(i32 %4)
ret void
7: ; preds = %1, %23
%8 = phi i32 [ %27, %23 ], [ %0, %1 ]
%9 = load i1, i1* @hybrid_ks.first
%10 = sitofp i32 %8 to double
br i1 %9, label %29, label %11
11: ; preds = %7
%12 = tail call i32 @log(double %10)
%13 = tail call i32 @log(double 2.000000e+00)
%14 = sdiv i32 %12, %13
%15 = tail call double @floor(i32 %14)
%16 = tail call double @exp2(double %15)
%17 = fcmp oeq double %16, %10
%18 = fmul double %16, 5.000000e-01
%19 = select i1 %17, double %18, double %16
%20 = fsub double %10, %19
%21 = tail call i32 @add_to_array(i32 %8)
%22 = tail call i32 @make_hdl(i32 %8, double %19, double %20)
store i1 true, i1* @hybrid_ks.first
br label %23
23: ; preds = %11, %29
%24 = phi double [ %19, %11 ], [ %33, %29 ]
%25 = phi double [ %20, %11 ], [ %32, %29 ]
%26 = fptosi double %24 to i32
tail call void @hybrid_ks(i32 %26)
%27 = fptosi double %25 to i32
%28 = icmp slt i32 %27, 29
br i1 %28, label %3, label %7
29: ; preds = %7
%30 = fmul double %10, 5.000000e-01
%31 = fptosi double %30 to i32
%32 = tail call double @floor(i32 %31)
%33 = tail call double @ceil(i32 %31)
%34 = tail call i32 @add_to_array(i32 %8)
%35 = tail call i32 @make_hdl(i32 %8, double %33, double %32)
br label %23
}