#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(double, int);
double log(double x) {
  double y = 0;
  double u = 0;
  u = (x - 1) / (x + 1);
  for (unsigned int i = 0; i != 16; i++)
    y += _pow(u, 2 * i) / (2 * i + 1);
  return 2 * u * y;
}


x86 assembly (clang, -O0):
<log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xec6(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xeba(%rip),%xmm1
addsd  -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
je     119e <log+0x8e>
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
add    %edi,%edi
call   1030 <_pow@plt>
mov    -0x1c(%rbp),%edx
mov    %edx,%ecx
lea    0x1(%rcx,%rcx,1),%ecx
xor    %edx,%edx
div    %ecx
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <log+0x4b>
movsd  0xe62(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log>:
push   %rbx
sub    $0x10,%rsp
movsd  0xee3(%rip),%xmm1
addsd  %xmm0,%xmm1
addsd  0xedf(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xorpd  %xmm1,%xmm1
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  (%rsp),%xmm0
mov    %ebx,%edi
call   1030 <_pow@plt>
movsd  0x8(%rsp),%xmm1
lea    0x1(%rbx),%ecx
xor    %edx,%edx
div    %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
add    $0x2,%ebx
cmp    $0x20,%ebx
jne    1140 <log+0x30>
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @log(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
%6 = load double, double* %2
%7 = fsub double %6, 1.000000e+00
%8 = load double, double* %2
%9 = fadd double %8, 1.000000e+00
%10 = fdiv double %7, %9
store double %10, double* %4
store i32 0, i32* %5
br label %11
11: ; preds = %26, %1
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 16
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load double, double* %4
%16 = load i32, i32* %5
%17 = mul i32 2, %16
%18 = call i32 @_pow(double %15, i32 %17)
%19 = load i32, i32* %5
%20 = mul i32 2, %19
%21 = add i32 %20, 1
%22 = udiv i32 %18, %21
%23 = uitofp i32 %22 to double
%24 = load double, double* %3
%25 = fadd double %24, %23
store double %25, double* %3
br label %26
26: ; preds = %14
%27 = load i32, i32* %5
%28 = add i32 %27, 1
store i32 %28, i32* %5
br label %11
29: ; preds = %11
%30 = load double, double* %4
%31 = fmul double 2.000000e+00, %30
%32 = load double, double* %3
%33 = fmul double %31, %32
ret double %33
}

LLVM IR (-O2):
define double @log(double %0) {
%2 = fadd double %0, -1.000000e+00
%3 = fadd double %0, 1.000000e+00
%4 = fdiv double %2, %3
br label %8
5: ; preds = %8
%6 = fmul double %4, 2.000000e+00
%7 = fmul double %6, %16
ret double %7
8: ; preds = %1, %8
%9 = phi i32 [ 0, %1 ], [ %17, %8 ]
%10 = phi double [ 0.000000e+00, %1 ], [ %16, %8 ]
%11 = shl nuw i32 %9, 1
%12 = tail call i32 @_pow(double %4, i32 %11)
%13 = or i32 %11, 1
%14 = udiv i32 %12, %13
%15 = uitofp i32 %14 to double
%16 = fadd double %10, %15
%17 = add nuw nsw i32 %9, 1
%18 = icmp eq i32 %17, 16
br i1 %18, label %5, label %8
}