#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 __pow_fi(double, int);
double log(double x) {
  int i, m;
  double z, y, t;
  if (x <= 0)
    return -1;
  m = 0;
  z = x / __pow_fi(2.0, m);
  while (2.0 <= z) {
    m++;
    z = x / __pow_fi(2.0, m);
  }
  y = (z - 1) / (z + 1);
  t = 0;
  for (i = 0; i < 10; i++) {
    t += __pow_fi(y, 2 * i + 1) / (2 * i + 1);
  }
  return (2.0 * t + m * 0.693147180);
}


x86 assembly (clang, -O0):
<log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     113d <log+0x2d>
movsd  0xee5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    125f <log+0x14f>
movl   $0x0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%edi
movsd  0xea7(%rip),%xmm0
call   1030 <__pow_fi@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe83(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11c1 <log+0xb1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%edi
movsd  0xe5b(%rip),%xmm0
call   1030 <__pow_fi@plt>
movsd  -0x40(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1170 <log+0x60>
movsd  -0x20(%rbp),%xmm0
movsd  0xe3a(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe2e(%rip),%xmm1
addsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    123c <log+0x12c>
movsd  -0x28(%rbp),%xmm0
mov    -0x14(%rbp),%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1030 <__pow_fi@plt>
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f7 <log+0xe7>
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xdc2(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    1401 <log+0x2f1>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xecf(%rip),%xmm0
xor    %ebx,%ebx
xor    %edi,%edi
movsd  %xmm1,0x10(%rsp)
call   1030 <__pow_fi@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x10(%rsp),%xmm2
divsd  %xmm1,%xmm2
ucomisd 0xea7(%rip),%xmm2
jb     11b6 <log+0xa6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
movsd  0xe8d(%rip),%xmm0
mov    %ebx,%edi
call   1030 <__pow_fi@plt>
movsd  0xe7e(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x10(%rsp),%xmm2
divsd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
jae    1170 <log+0x60>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  0xe60(%rip),%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0xe42(%rip),%xmm0
addsd  %xmm2,%xmm0
addsd  0xe4e(%rip),%xmm2
divsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0x1,%edi
call   1030 <__pow_fi@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x3,%edi
call   1030 <__pow_fi@plt>
cltq
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x5,%edi
call   1030 <__pow_fi@plt>
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
sar    %eax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x7,%edi
call   1030 <__pow_fi@plt>
cltq
imul   $0xffffffff92492493,%rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x2,%eax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x9,%edi
call   1030 <__pow_fi@plt>
cltq
imul   $0x38e38e39,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
sar    %eax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0xb,%edi
call   1030 <__pow_fi@plt>
cltq
imul   $0x2e8ba2e9,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
sar    %eax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0xd,%edi
call   1030 <__pow_fi@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
sar    $0x2,%eax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0xf,%edi
call   1030 <__pow_fi@plt>
cltq
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x3,%eax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x11,%edi
call   1030 <__pow_fi@plt>
cltq
imul   $0x78787879,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x13,%edi
call   1030 <__pow_fi@plt>
cltq
imul   $0x6bca1af3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
addsd  0x18(%rsp),%xmm0
jmp    1409 <log+0x2f9>
movsd  0xbf7(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @log(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %3
%9 = load double, double* %3
%10 = fcmp ole double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %1
store double -1.000000e+00, double* %2
br label %60
12: ; preds = %1
store i32 0, i32* %5
%13 = load double, double* %3
%14 = load i32, i32* %5
%15 = call i32 @__pow_fi(double 2.000000e+00, i32 %14)
%16 = sitofp i32 %15 to double
%17 = fdiv double %13, %16
store double %17, double* %6
br label %18
18: ; preds = %21, %12
%19 = load double, double* %6
%20 = fcmp ole double 2.000000e+00, %19
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = load double, double* %3
%25 = load i32, i32* %5
%26 = call i32 @__pow_fi(double 2.000000e+00, i32 %25)
%27 = sitofp i32 %26 to double
%28 = fdiv double %24, %27
store double %28, double* %6
br label %18
29: ; preds = %18
%30 = load double, double* %6
%31 = fsub double %30, 1.000000e+00
%32 = load double, double* %6
%33 = fadd double %32, 1.000000e+00
%34 = fdiv double %31, %33
store double %34, double* %7
store double 0.000000e+00, double* %8
store i32 0, i32* %4
br label %35
35: ; preds = %51, %29
%36 = load i32, i32* %4
%37 = icmp slt i32 %36, 10
br i1 %37, label %38, label %54
38: ; preds = %35
%39 = load double, double* %7
%40 = load i32, i32* %4
%41 = mul nsw i32 2, %40
%42 = add nsw i32 %41, 1
%43 = call i32 @__pow_fi(double %39, i32 %42)
%44 = load i32, i32* %4
%45 = mul nsw i32 2, %44
%46 = add nsw i32 %45, 1
%47 = sdiv i32 %43, %46
%48 = sitofp i32 %47 to double
%49 = load double, double* %8
%50 = fadd double %49, %48
store double %50, double* %8
br label %51
51: ; preds = %38
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 1
store i32 %53, i32* %4
br label %35
54: ; preds = %35
%55 = load double, double* %8
%56 = load i32, i32* %5
%57 = sitofp i32 %56 to double
%58 = fmul double %57, 0x3FE62E42FEAD449C
%59 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %55, double %58)
store double %59, double* %2
br label %60
60: ; preds = %54, %11
%61 = load double, double* %2
ret double %61
}

LLVM IR (-O2):
define double @log(double %0) {
%2 = fcmp ugt double %0, 0.000000e+00
br i1 %2, label %3, label %63
3: ; preds = %1
%4 = tail call i32 @__pow_fi(double 2.000000e+00, i32 0)
%5 = sitofp i32 %4 to double
%6 = fdiv double %0, %5
%7 = fcmp ult double %6, 2.000000e+00
br i1 %7, label %18, label %8
8: ; preds = %3, %8
%9 = phi i32 [ %10, %8 ], [ 0, %3 ]
%10 = add nuw nsw i32 %9, 1
%11 = tail call i32 @__pow_fi(double 2.000000e+00, i32 %10)
%12 = sitofp i32 %11 to double
%13 = fdiv double %0, %12
%14 = fcmp ult double %13, 2.000000e+00
br i1 %14, label %15, label %8
15: ; preds = %8
%16 = sitofp i32 %10 to double
%17 = fmul double %16, 0x3FE62E42FEAD449C
br label %18
18: ; preds = %15, %3
%19 = phi double [ 0.000000e+00, %3 ], [ %17, %15 ]
%20 = phi double [ %6, %3 ], [ %13, %15 ]
%21 = fadd double %20, -1.000000e+00
%22 = fadd double %20, 1.000000e+00
%23 = fdiv double %21, %22
%24 = tail call i32 @__pow_fi(double %23, i32 1)
%25 = sitofp i32 %24 to double
%26 = tail call i32 @__pow_fi(double %23, i32 3)
%27 = sdiv i32 %26, 3
%28 = sitofp i32 %27 to double
%29 = fadd double %25, %28
%30 = tail call i32 @__pow_fi(double %23, i32 5)
%31 = sdiv i32 %30, 5
%32 = sitofp i32 %31 to double
%33 = fadd double %29, %32
%34 = tail call i32 @__pow_fi(double %23, i32 7)
%35 = sdiv i32 %34, 7
%36 = sitofp i32 %35 to double
%37 = fadd double %33, %36
%38 = tail call i32 @__pow_fi(double %23, i32 9)
%39 = sdiv i32 %38, 9
%40 = sitofp i32 %39 to double
%41 = fadd double %37, %40
%42 = tail call i32 @__pow_fi(double %23, i32 11)
%43 = sdiv i32 %42, 11
%44 = sitofp i32 %43 to double
%45 = fadd double %41, %44
%46 = tail call i32 @__pow_fi(double %23, i32 13)
%47 = sdiv i32 %46, 13
%48 = sitofp i32 %47 to double
%49 = fadd double %45, %48
%50 = tail call i32 @__pow_fi(double %23, i32 15)
%51 = sdiv i32 %50, 15
%52 = sitofp i32 %51 to double
%53 = fadd double %49, %52
%54 = tail call i32 @__pow_fi(double %23, i32 17)
%55 = sdiv i32 %54, 17
%56 = sitofp i32 %55 to double
%57 = fadd double %53, %56
%58 = tail call i32 @__pow_fi(double %23, i32 19)
%59 = sdiv i32 %58, 19
%60 = sitofp i32 %59 to double
%61 = fadd double %57, %60
%62 = tail call double @llvm.fmuladd.f64(double %61, double 2.000000e+00, double %19)
br label %63
63: ; preds = %1, %18
%64 = phi double [ %62, %18 ], [ -1.000000e+00, %1 ]
ret double %64
}