#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 horner(double);
double sqrt(double);
double ln(double x) {
  int i;
  if (x > 1.5) {
    for (i = 0; x > 1.25; i++) {
      x = sqrt(x);
    }
    return (1 << i) * horner(x - 1);
  } else if (x < 0.7 && x > 0) {
    for (i = 0; x < 0.7; i++) {
      x = sqrt(x);
    }
    return (1 << i) * horner(x - 1);
  } else if (x > 0) {
    return horner(x - 1);
  }
}


x86 assembly (clang, -O0):
<ln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xec6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11be <ln+0x9e>
movl   $0x0,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xec0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    117f <ln+0x5f>
movsd  -0x10(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <ln+0x2b>
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe71(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1040 <horner@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1295 <ln+0x175>
movsd  0xe42(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1259 <ln+0x139>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1259 <ln+0x139>
movl   $0x0,-0x14(%rbp)
movsd  0xe16(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    121a <ln+0xfa>
movsd  -0x10(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ea <ln+0xca>
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xdd6(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1040 <horner@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1295 <ln+0x175>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    128b <ln+0x16b>
movsd  -0x10(%rbp),%xmm0
movsd  0xd98(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1040 <horner@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1295 <ln+0x175>
jmp    1290 <ln+0x170>
jmp    1295 <ln+0x175>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ln>:
push   %rbx
sub    $0x10,%rsp
ucomisd 0xed3(%rip),%xmm0
jbe    1176 <ln+0x56>
xor    %ebx,%ebx
ucomisd 0xedf(%rip),%xmm0
jbe    11c6 <ln+0xa6>
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
movsd  0xecb(%rip),%xmm2
jmp    116a <ln+0x4a>
nop
call   1030 <sqrt@plt>
movsd  0xebb(%rip),%xmm2
xorpd  %xmm1,%xmm1
add    $0x1,%ebx
ucomisd %xmm2,%xmm0
jbe    11c6 <ln+0xa6>
ucomisd %xmm1,%xmm0
jb     1150 <ln+0x30>
sqrtsd %xmm0,%xmm0
jmp    1161 <ln+0x41>
movsd  0xe8a(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11e6 <ln+0xc6>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jbe    11e6 <ln+0xc6>
mov    $0xffffffff,%ebx
jmp    11ba <ln+0x9a>
cs nopw 0x0(%rax,%rax,1)
nop
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  0xe57(%rip),%xmm1
add    $0x1,%ebx
ucomisd %xmm0,%xmm1
jbe    1202 <ln+0xe2>
ucomisd %xmm2,%xmm0
jb     11a0 <ln+0x80>
sqrtsd %xmm0,%xmm0
jmp    11b1 <ln+0x91>
mov    $0x1,%eax
mov    %ebx,%ecx
shl    %cl,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm1,0x8(%rsp)
addsd  0xe2c(%rip),%xmm0
jmp    1220 <ln+0x100>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    122f <ln+0x10f>
addsd  0xe18(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
jmp    1040 <horner@plt>
mov    $0x2,%eax
mov    %ebx,%ecx
shl    %cl,%eax
addsd  0xdfd(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1040 <horner@plt>
movapd %xmm0,%xmm1
mulsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @ln(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
store double %0, double* %3
%5 = load double, double* %3
%6 = fcmp ogt double %5, 1.500000e+00
br i1 %6, label %7, label %25
7: ; preds = %1
store i32 0, i32* %4
br label %8
8: ; preds = %14, %7
%9 = load double, double* %3
%10 = fcmp ogt double %9, 1.250000e+00
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load double, double* %3
%13 = call double @sqrt(double %12)
store double %13, double* %3
br label %14
14: ; preds = %11
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %8
17: ; preds = %8
%18 = load i32, i32* %4
%19 = shl i32 1, %18
%20 = sitofp i32 %19 to double
%21 = load double, double* %3
%22 = fsub double %21, 1.000000e+00
%23 = call double @horner(double %22)
%24 = fmul double %20, %23
store double %24, double* %2
br label %58
25: ; preds = %1
%26 = load double, double* %3
%27 = fcmp olt double %26, 0x3FE6666666666666
br i1 %27, label %28, label %49
28: ; preds = %25
%29 = load double, double* %3
%30 = fcmp ogt double %29, 0.000000e+00
br i1 %30, label %31, label %49
31: ; preds = %28
store i32 0, i32* %4
br label %32
32: ; preds = %38, %31
%33 = load double, double* %3
%34 = fcmp olt double %33, 0x3FE6666666666666
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load double, double* %3
%37 = call double @sqrt(double %36)
store double %37, double* %3
br label %38
38: ; preds = %35
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %32
41: ; preds = %32
%42 = load i32, i32* %4
%43 = shl i32 1, %42
%44 = sitofp i32 %43 to double
%45 = load double, double* %3
%46 = fsub double %45, 1.000000e+00
%47 = call double @horner(double %46)
%48 = fmul double %44, %47
store double %48, double* %2
br label %58
49: ; preds = %28, %25
%50 = load double, double* %3
%51 = fcmp ogt double %50, 0.000000e+00
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load double, double* %3
%54 = fsub double %53, 1.000000e+00
%55 = call double @horner(double %54)
store double %55, double* %2
br label %58
56: ; preds = %49
br label %57
57: ; preds = %56
br label %58
58: ; preds = %17, %41, %52, %57
%59 = load double, double* %2
ret double %59
}

LLVM IR (-O2):
define double @ln(double %0) {
%2 = fcmp ogt double %0, 1.500000e+00
br i1 %2, label %3, label %19
3: ; preds = %1
%4 = fcmp ogt double %0, 1.250000e+00
br i1 %4, label %5, label %11
5: ; preds = %3, %5
%6 = phi i32 [ %9, %5 ], [ 0, %3 ]
%7 = phi double [ %8, %5 ], [ %0, %3 ]
%8 = tail call double @sqrt(double %7)
%9 = add nuw nsw i32 %6, 1
%10 = fcmp ogt double %8, 1.250000e+00
br i1 %10, label %5, label %11
11: ; preds = %5, %3
%12 = phi double [ %0, %3 ], [ %8, %5 ]
%13 = phi i32 [ 0, %3 ], [ %9, %5 ]
%14 = shl nuw i32 1, %13
%15 = sitofp i32 %14 to double
%16 = fadd double %12, -1.000000e+00
%17 = tail call double @horner(double %16)
%18 = fmul double %17, %15
br label %39
19: ; preds = %1
%20 = fcmp olt double %0, 0x3FE6666666666666
%21 = fcmp ogt double %0, 0.000000e+00
%22 = and i1 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %19, %23
%24 = phi i32 [ %27, %23 ], [ 0, %19 ]
%25 = phi double [ %26, %23 ], [ %0, %19 ]
%26 = tail call double @sqrt(double %25)
%27 = add nuw nsw i32 %24, 1
%28 = fcmp olt double %26, 0x3FE6666666666666
br i1 %28, label %23, label %29
29: ; preds = %23
%30 = fadd double %26, -1.000000e+00
%31 = shl i32 2, %24
%32 = sitofp i32 %31 to double
%33 = tail call double @horner(double %30)
%34 = fmul double %33, %32
br label %39
35: ; preds = %19
br i1 %21, label %36, label %39
36: ; preds = %35
%37 = fadd double %0, -1.000000e+00
%38 = tail call double @horner(double %37)
br label %39
39: ; preds = %35, %36, %29, %11
%40 = phi double [ %18, %11 ], [ %34, %29 ], [ %38, %36 ], [ undef, %35 ]
ret double %40
}