#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 powi(double, int);
double log(double y) {
  double x = (y - 1) / (y + 1);
  double sigma = 0;
  int i;
  for (i = 0; i < 150; i++)
    sigma += powi(x, 2 * i + 1) / (2 * i + 1);
  return 2 * sigma;
}


x86 assembly (clang, -O0):
<log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xeca(%rip),%xmm1
addsd  -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x96,-0x1c(%rbp)
jge    119b <log+0x8b>
movsd  -0x10(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1030 <powi@plt>
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1153 <log+0x43>
movsd  0xe65(%rip),%xmm0
mulsd  -0x18(%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,0x8(%rsp)
xorpd  %xmm0,%xmm0
mov    $0x1,%ebx
nopl   0x0(%rax)
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mov    %ebx,%edi
call   1030 <powi@plt>
cltd
idiv   %ebx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x2,%ebx
cmp    $0x12d,%ebx
jne    1140 <log+0x30>
addsd  %xmm0,%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
%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* %3
store double 0.000000e+00, double* %4
store i32 0, i32* %5
br label %11
11: ; preds = %27, %1
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 150
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = load double, double* %3
%16 = load i32, i32* %5
%17 = mul nsw i32 2, %16
%18 = add nsw i32 %17, 1
%19 = call i32 @powi(double %15, i32 %18)
%20 = load i32, i32* %5
%21 = mul nsw i32 2, %20
%22 = add nsw i32 %21, 1
%23 = sdiv i32 %19, %22
%24 = sitofp i32 %23 to double
%25 = load double, double* %4
%26 = fadd double %25, %24
store double %26, double* %4
br label %27
27: ; preds = %14
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %11
30: ; preds = %11
%31 = load double, double* %4
%32 = fmul double 2.000000e+00, %31
ret double %32
}

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 %5
5: ; preds = %1, %5
%6 = phi i32 [ 0, %1 ], [ %14, %5 ]
%7 = phi double [ 0.000000e+00, %1 ], [ %13, %5 ]
%8 = shl nuw nsw i32 %6, 1
%9 = or i32 %8, 1
%10 = tail call i32 @powi(double %4, i32 %9)
%11 = sdiv i32 %10, %9
%12 = sitofp i32 %11 to double
%13 = fadd double %7, %12
%14 = add nuw nsw i32 %6, 1
%15 = icmp eq i32 %14, 150
br i1 %15, label %16, label %5
16: ; preds = %5
%17 = fmul double %13, 2.000000e+00
ret double %17
}