#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 logn(double x, int n) {
  if (x < 0.5)
    return -1;
  else {
    if (n == 0)
      return 0;
    else
      return pow((x - 1) / x, n) / n + logn(x, n - 1);
  }
}


x86 assembly (clang, -O0):
<logn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  0xec8(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1155 <logn+0x35>
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b8 <logn+0x98>
cmpl   $0x0,-0x14(%rbp)
jne    116c <logn+0x4c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b8 <logn+0x98>
movsd  -0x10(%rbp),%xmm0
movsd  0xe8f(%rip),%xmm1
subsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%edi
call   1040 <pow@plt>
cltd
idivl  -0x14(%rbp)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
call   1030 <logn@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logn>:
push   %rbx
sub    $0x10,%rsp
movapd %xmm0,%xmm1
movsd  0xed7(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1141 <logn+0x21>
movsd  0xec1(%rip),%xmm0
jmp    118e <logn+0x6e>
mov    %edi,%ebx
test   %edi,%edi
je     118a <logn+0x6a>
movsd  0xeb1(%rip),%xmm0
addsd  %xmm1,%xmm0
divsd  %xmm1,%xmm0
mov    %ebx,%edi
movsd  %xmm1,0x8(%rsp)
call   1040 <pow@plt>
cltd
idiv   %ebx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
add    $0xffffffff,%ebx
movsd  0x8(%rsp),%xmm0
mov    %ebx,%edi
call   1030 <logn@plt>
addsd  (%rsp),%xmm0
jmp    118e <logn+0x6e>
xorpd  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @logn(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
%6 = load double, double* %4
%7 = fcmp olt double %6, 5.000000e-01
br i1 %7, label %8, label %9
8: ; preds = %2
store double -1.000000e+00, double* %3
br label %28
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store double 0.000000e+00, double* %3
br label %28
13: ; preds = %9
%14 = load double, double* %4
%15 = fsub double %14, 1.000000e+00
%16 = load double, double* %4
%17 = fdiv double %15, %16
%18 = load i32, i32* %5
%19 = call i32 @pow(double %17, i32 %18)
%20 = load i32, i32* %5
%21 = sdiv i32 %19, %20
%22 = sitofp i32 %21 to double
%23 = load double, double* %4
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = call double @logn(double %23, i32 %25)
%27 = fadd double %22, %26
store double %27, double* %3
br label %28
28: ; preds = %13, %12, %8
%29 = load double, double* %3
ret double %29
}

LLVM IR (-O2):
define double @logn(double %0, i32 %1) {
%3 = fcmp olt double %0, 5.000000e-01
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = icmp eq i32 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %2, %4, %8
%7 = phi double [ %16, %8 ], [ -1.000000e+00, %2 ], [ 0.000000e+00, %4 ]
ret double %7
8: ; preds = %4
%9 = fadd double %0, -1.000000e+00
%10 = fdiv double %9, %0
%11 = tail call i32 @pow(double %10, i32 %1)
%12 = sdiv i32 %11, %1
%13 = sitofp i32 %12 to double
%14 = add nsw i32 %1, -1
%15 = tail call double @logn(double %0, i32 %14)
%16 = fadd double %15, %13
br label %6
}