#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 exponent(double, double);
double taylor_log(double x, unsigned int n) {
  double result;
  if (x < 1) {
    result = -(1 - x);
    for (double i = 2.0; i < n + 2 - 1; ++i)
      result = result - exponent(1 - x, i) / i;
  } else {
    result = (x - 1) / x;
    for (double i = 2.0; i < n + 2 - 1; ++i)
      result = result + exponent((x - 1) / x, i) / i;
  }
  return result;
}


x86 assembly (clang, -O0):
<taylor_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  0xed8(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11d6 <taylor_log+0xc6>
movsd  0xec5(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xea4(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    11d1 <taylor_log+0xc1>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe6b(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1030 <exponent@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe3e(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1169 <taylor_log+0x59>
jmp    1274 <taylor_log+0x164>
movsd  -0x8(%rbp),%xmm0
movsd  0xe1d(%rip),%xmm1
subsd  %xmm1,%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe0f(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    126f <taylor_log+0x15f>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xdd1(%rip),%xmm1
subsd  %xmm1,%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <exponent@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xda0(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11fe <taylor_log+0xee>
jmp    1274 <taylor_log+0x164>
movsd  -0x18(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<taylor_log>:
sub    $0x48,%rsp
movsd  0xee4(%rip),%xmm3
ucomisd %xmm0,%xmm3
jbe    11c4 <taylor_log+0xb4>
subsd  %xmm0,%xmm3
movapd 0xeee(%rip),%xmm0
xorpd  %xmm3,%xmm0
add    $0x1,%edi
cmp    $0x3,%edi
jb     1271 <taylor_log+0x161>
cvtsi2sd %rdi,%xmm2
movsd  %xmm2,0x28(%rsp)
movsd  0xebb(%rip),%xmm1
movapd %xmm3,0x30(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,0x10(%rsp)
movapd %xmm3,%xmm0
call   1030 <exponent@plt>
divsd  0x8(%rsp),%xmm0
movapd 0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
movapd 0x30(%rsp),%xmm3
movapd 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  0xe5b(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x28(%rsp),%xmm2
ucomisd 0x8(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
ja     1160 <taylor_log+0x50>
jmp    1271 <taylor_log+0x161>
movsd  0xe3c(%rip),%xmm1
addsd  %xmm0,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x30(%rsp)
add    $0x1,%edi
cmp    $0x3,%edi
jb     1276 <taylor_log+0x166>
xorps  %xmm0,%xmm0
cvtsi2sd %rdi,%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0xe14(%rip),%xmm1
movsd  0x30(%rsp),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,0x10(%rsp)
movsd  0x30(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <exponent@plt>
divsd  0x8(%rsp),%xmm0
movapd 0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
movapd 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  0xda9(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x28(%rsp),%xmm1
ucomisd 0x8(%rsp),%xmm1
movsd  0x8(%rsp),%xmm1
ja     1210 <taylor_log+0x100>
add    $0x48,%rsp
ret
movsd  0x30(%rsp),%xmm0
add    $0x48,%rsp
ret

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

LLVM IR (-O2):
define double @taylor_log(double %0, i32 %1) {
%3 = fcmp olt double %0, 1.000000e+00
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = fsub double 1.000000e+00, %0
%6 = fneg double %5
%7 = add i32 %1, 1
%8 = uitofp i32 %7 to double
%9 = icmp ugt i32 %7, 2
br i1 %9, label %10, label %32
10: ; preds = %4, %10
%11 = phi double [ %16, %10 ], [ 2.000000e+00, %4 ]
%12 = phi double [ %15, %10 ], [ %6, %4 ]
%13 = tail call double @exponent(double %5, double %11)
%14 = fdiv double %13, %11
%15 = fsub double %12, %14
%16 = fadd double %11, 1.000000e+00
%17 = fcmp olt double %16, %8
br i1 %17, label %10, label %32
18: ; preds = %2
%19 = fadd double %0, -1.000000e+00
%20 = fdiv double %19, %0
%21 = add i32 %1, 1
%22 = uitofp i32 %21 to double
%23 = icmp ugt i32 %21, 2
br i1 %23, label %24, label %32
24: ; preds = %18, %24
%25 = phi double [ %30, %24 ], [ 2.000000e+00, %18 ]
%26 = phi double [ %29, %24 ], [ %20, %18 ]
%27 = tail call double @exponent(double %20, double %25)
%28 = fdiv double %27, %25
%29 = fadd double %26, %28
%30 = fadd double %25, 1.000000e+00
%31 = fcmp olt double %30, %22
br i1 %31, label %24, label %32
32: ; preds = %24, %10, %18, %4
%33 = phi double [ %6, %4 ], [ %20, %18 ], [ %15, %10 ], [ %29, %24 ]
ret double %33
}