#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);
int exp(double);
int log10(int);
int sqrt(double);
long stirling(int n) {
  if (n == 1)
    return 1;
  else
    return (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    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1162 <stirling+0x22>
movq   $0x1,-0x8(%rbp)
jmp    11d1 <stirling+0x91>
xorps  %xmm0,%xmm0
call   1030 <acos@plt>
movaps %xmm0,%xmm1
movsd  0xe93(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1050 <log10@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <log10@plt>
mov    %eax,-0x18(%rbp)
movsd  0xe56(%rip),%xmm0
call   1040 <exp@plt>
mov    %eax,%edi
call   1050 <log10@plt>
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    %eax,%esi
mov    -0x10(%rbp),%eax
sub    %esi,%edx
imul   %edx,%ecx
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stirling>:
mov    $0x1,%eax
cmp    $0x1,%edi
je     118a <stirling+0x5a>
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
cvtsi2sd %edi,%xmm0
mulsd  0xeb4(%rip),%xmm0
call   1050 <sqrt@plt>
mov    %eax,%edi
call   1040 <log10@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1040 <log10@plt>
mov    %eax,%ebx
movsd  0xe9c(%rip),%xmm0
call   1030 <exp@plt>
mov    %eax,%edi
call   1040 <log10@plt>
sub    %eax,%ebx
imul   %ebp,%ebx
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
cltq
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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