#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 acos(int /*<<< orphan*/);
scalar_t__ floor(double);
double log(double);
int calculateNumDigitOfFactorial(int n) {
  if (n <= 3)
    return 1;
  double stirlingApprox =
      n * log(n) - n + 0.5 * log(2 * 2 * acos(0) * n) + 1 / (12.0 * n);
  return (int)floor(stirlingApprox / log(10.0) + 1);
}


x86 assembly (clang, -O0):
<calculateNumDigitOfFactorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jg     1151 <calculateNumDigitOfFactorial+0x21>
movl   $0x1,-0x4(%rbp)
jmp    121f <calculateNumDigitOfFactorial+0xef>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xor    %edi,%edi
call   1030 <acos@plt>
shl    $0x2,%eax
imul   -0x8(%rbp),%eax
cvtsi2sd %eax,%xmm0
call   1040 <log@plt>
movsd  -0x20(%rbp),%xmm1
movsd  0xe5e(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe41(%rip),%xmm2
mulsd  %xmm1,%xmm2
movsd  0xe25(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe0e(%rip),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  0xded(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateNumDigitOfFactorial>:
mov    $0x1,%eax
cmp    $0x4,%edi
jl     11c4 <calculateNumDigitOfFactorial+0x94>
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
cvtsi2sd %edi,%xmm0
movsd  %xmm0,(%rsp)
call   1040 <log@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
call   1030 <acos@plt>
imul   %ebx,%eax
shl    $0x2,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1040 <log@plt>
mulsd  0xe79(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm3
mulsd  0xe6e(%rip),%xmm3
movsd  0xe6e(%rip),%xmm1
movapd %xmm1,%xmm2
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm0
divsd  0xe62(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1050 <floor@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @calculateNumDigitOfFactorial(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp sle i32 %5, 3
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %2
br label %36
8: ; preds = %1
%9 = load i32, i32* %3
%10 = sitofp i32 %9 to double
%11 = load i32, i32* %3
%12 = sitofp i32 %11 to double
%13 = call double @log(double %12)
%14 = load i32, i32* %3
%15 = sitofp i32 %14 to double
%16 = fneg double %15
%17 = call double @llvm.fmuladd.f64(double %10, double %13, double %16)
%18 = call i32 @acos(i32 0)
%19 = mul nsw i32 4, %18
%20 = load i32, i32* %3
%21 = mul nsw i32 %19, %20
%22 = sitofp i32 %21 to double
%23 = call double @log(double %22)
%24 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %23, double %17)
%25 = load i32, i32* %3
%26 = sitofp i32 %25 to double
%27 = fmul double 1.200000e+01, %26
%28 = fdiv double 1.000000e+00, %27
%29 = fadd double %24, %28
store double %29, double* %4
%30 = load double, double* %4
%31 = call double @log(double 1.000000e+01)
%32 = fdiv double %30, %31
%33 = fadd double %32, 1.000000e+00
%34 = call i64 @floor(double %33)
%35 = trunc i64 %34 to i32
store i32 %35, i32* %2
br label %36
36: ; preds = %8, %7
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
define i32 @calculateNumDigitOfFactorial(i32 %0) {
%2 = icmp slt i32 %0, 4
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = sitofp i32 %0 to double
%5 = tail call double @log(double %4)
%6 = fneg double %4
%7 = tail call double @llvm.fmuladd.f64(double %4, double %5, double %6)
%8 = tail call i32 @acos(i32 0)
%9 = shl i32 %0, 2
%10 = mul i32 %9, %8
%11 = sitofp i32 %10 to double
%12 = tail call double @log(double %11)
%13 = tail call double @llvm.fmuladd.f64(double %12, double 5.000000e-01, double %7)
%14 = fmul double %4, 1.200000e+01
%15 = fdiv double 1.000000e+00, %14
%16 = fadd double %15, %13
%17 = fdiv double %16, 0x40026BB1BBB55516
%18 = fadd double %17, 1.000000e+00
%19 = tail call i64 @floor(double %18)
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %1, %3
%22 = phi i32 [ %20, %3 ], [ 1, %1 ]
ret i32 %22
}