#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 log(int);
double st_perm_ln(unsigned int n) {
  if (n == 0)
    return 0;
  return n * (log(n) - 1.0) + 0.5 * log(2 * 3.1415926 * n) + 1.0 / (12 * n);
}


x86 assembly (clang, -O0):
<st_perm_ln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1132 <st_perm_ln+0x22>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ba <st_perm_ln+0xaa>
mov    -0xc(%rbp),%eax
mov    %eax,%edi
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
call   1030 <log@plt>
movsd  0xeba(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xea9(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
movsd  -0x20(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0xe8f(%rip),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
mov    %ecx,%eax
lea    (%rax,%rax,2),%eax
cvtsi2sd %rax,%xmm2
movsd  0xe53(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<st_perm_ln>:
test   %edi,%edi
je     1188 <st_perm_ln+0x78>
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %edi,%eax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rsp)
call   1030 <log@plt>
addsd  0xecc(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xec6(%rip),%xmm0
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
mulsd  0xeb8(%rip),%xmm0
movsd  0x8(%rsp),%xmm2
mulsd  (%rsp),%xmm2
shl    $0x2,%ebx
lea    (%rbx,%rbx,2),%eax
cvtsi2sd %rax,%xmm1
addsd  %xmm0,%xmm2
movsd  0xe9e(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
add    $0x10,%rsp
pop    %rbx
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @st_perm_ln(i32 %0) {
%2 = alloca double
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %1
store double 0.000000e+00, double* %2
br label %25
7: ; preds = %1
%8 = load i32, i32* %3
%9 = uitofp i32 %8 to double
%10 = load i32, i32* %3
%11 = call double @log(i32 %10)
%12 = fsub double %11, 1.000000e+00
%13 = load i32, i32* %3
%14 = uitofp i32 %13 to double
%15 = fmul double 0x401921FB4D12D84A, %14
%16 = fptosi double %15 to i32
%17 = call double @log(i32 %16)
%18 = fmul double 5.000000e-01, %17
%19 = call double @llvm.fmuladd.f64(double %9, double %12, double %18)
%20 = load i32, i32* %3
%21 = mul i32 12, %20
%22 = uitofp i32 %21 to double
%23 = fdiv double 1.000000e+00, %22
%24 = fadd double %19, %23
store double %24, double* %2
br label %25
25: ; preds = %7, %6
%26 = load double, double* %2
ret double %26
}

LLVM IR (-O2):
define double @st_perm_ln(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = uitofp i32 %0 to double
%5 = tail call double @log(i32 %0)
%6 = fadd double %5, -1.000000e+00
%7 = fmul double %4, 0x401921FB4D12D84A
%8 = fptosi double %7 to i32
%9 = tail call double @log(i32 %8)
%10 = fmul double %9, 5.000000e-01
%11 = tail call double @llvm.fmuladd.f64(double %4, double %6, double %10)
%12 = mul i32 %0, 12
%13 = uitofp i32 %12 to double
%14 = fdiv double 1.000000e+00, %13
%15 = fadd double %14, %11
br label %16
16: ; preds = %1, %3
%17 = phi double [ %15, %3 ], [ 0.000000e+00, %1 ]
ret double %17
}