#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 acos(double);
long exp(double);
long log10(long);
long sqrt(double);
long long stirling(long n) {
  if (n == 1)
    return 1;
  else
    return (long long)((log10(sqrt(4.0 * acos(0.0) * n)) +
                        n * (log10(n) - log10(exp(1.0)))) +
                       1);
}


x86 assembly (clang, -O0):
<stirling>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jne    1164 <stirling+0x24>
movq   $0x1,-0x8(%rbp)
jmp    11e1 <stirling+0xa1>
xorps  %xmm0,%xmm0
call   1030 <acos@plt>
movaps %xmm0,%xmm1
movsd  0xe91(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    %rax,%rdi
call   1050 <log10@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <log10@plt>
mov    %rax,-0x28(%rbp)
movsd  0xe4d(%rip),%xmm0
call   1040 <exp@plt>
mov    %rax,%rdi
call   1050 <log10@plt>
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    %rax,%rsi
mov    -0x18(%rbp),%rax
sub    %rsi,%rdx
imul   %rdx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stirling>:
mov    $0x1,%eax
cmp    $0x1,%rdi
je     1194 <stirling+0x64>
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
cvtsi2sd %rdi,%xmm0
mulsd  0xeb0(%rip),%xmm0
call   1050 <sqrt@plt>
mov    %rax,%rdi
call   1040 <log10@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <log10@plt>
mov    %rax,%rbx
movsd  0xe95(%rip),%xmm0
call   1030 <exp@plt>
mov    %rax,%rdi
call   1040 <log10@plt>
sub    %rax,%rbx
imul   %r15,%rbx
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @stirling(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = icmp eq i64 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %1
store i64 1, i64* %2
br label %24
7: ; preds = %1
%8 = call double @acos(double 0.000000e+00)
%9 = fmul double 4.000000e+00, %8
%10 = load i64, i64* %3
%11 = sitofp i64 %10 to double
%12 = fmul double %9, %11
%13 = call i64 @sqrt(double %12)
%14 = call i64 @log10(i64 %13)
%15 = load i64, i64* %3
%16 = load i64, i64* %3
%17 = call i64 @log10(i64 %16)
%18 = call i64 @exp(double 1.000000e+00)
%19 = call i64 @log10(i64 %18)
%20 = sub nsw i64 %17, %19
%21 = mul nsw i64 %15, %20
%22 = add nsw i64 %14, %21
%23 = add nsw i64 %22, 1
store i64 %23, i64* %2
br label %24
24: ; preds = %7, %6
%25 = load i64, i64* %2
ret i64 %25
}

LLVM IR (-O2):
define i64 @stirling(i64 %0) {
%2 = icmp eq i64 %0, 1
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = sitofp i64 %0 to double
%5 = fmul double %4, 0x401921FB54442D18
%6 = tail call i64 @sqrt(double %5)
%7 = tail call i64 @log10(i64 %6)
%8 = tail call i64 @log10(i64 %0)
%9 = tail call i64 @exp(double 1.000000e+00)
%10 = tail call i64 @log10(i64 %9)
%11 = sub nsw i64 %8, %10
%12 = mul nsw i64 %11, %0
%13 = add i64 %7, 1
%14 = add i64 %13, %12
br label %15
15: ; preds = %1, %3
%16 = phi i64 [ %14, %3 ], [ 1, %1 ]
ret i64 %16
}