#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 M_LOG10E;
int ceil(double);
scalar_t__ log(int);
int size_of_fact(int n) {
  int i;
  double sum = 0;
  for (i = 1; i < n + 1; i++) {
    sum += log(i);
  }
  sum *= M_LOG10E;
  int size = ceil(sum);
  return size;
}


x86 assembly (clang, -O0):
<size_of_fact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1170 <size_of_fact+0x50>
mov    -0x8(%rbp),%edi
call   1040 <log@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113a <size_of_fact+0x1a>
mov    0x2e71(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<size_of_fact>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    117c <size_of_fact+0x5c>
mov    %edi,%r14d
neg    %r14d
xorpd  %xmm0,%xmm0
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    %ebx,%edi
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1140 <size_of_fact+0x20>
jmp    1180 <size_of_fact+0x60>
xorpd  %xmm0,%xmm0
mov    0x2e61(%rip),%rax
mulsd  (%rax),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <ceil@plt>

LLVM IR (-O0):
@M_LOG10E = global double 0.000000e+00
define i32 @size_of_fact(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
store i32 %0, i32* %2
store double 0.000000e+00, double* %4
store i32 1, i32* %3
br label %6
6: ; preds = %17, %1
%7 = load i32, i32* %3
%8 = load i32, i32* %2
%9 = add nsw i32 %8, 1
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %20
11: ; preds = %6
%12 = load i32, i32* %3
%13 = call i64 @log(i32 %12)
%14 = sitofp i64 %13 to double
%15 = load double, double* %4
%16 = fadd double %15, %14
store double %16, double* %4
br label %17
17: ; preds = %11
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %6
20: ; preds = %6
%21 = load double, double* @M_LOG10E
%22 = load double, double* %4
%23 = fmul double %22, %21
store double %23, double* %4
%24 = load double, double* %4
%25 = call i32 @ceil(double %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@M_LOG10E = global double 0.000000e+00
define i32 @size_of_fact(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %11, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %9, %3 ], [ 1, %1 ]
%5 = phi double [ %8, %3 ], [ 0.000000e+00, %1 ]
%6 = tail call i64 @log(i32 %4)
%7 = sitofp i64 %6 to double
%8 = fadd double %5, %7
%9 = add nuw i32 %4, 1
%10 = icmp eq i32 %4, %0
br i1 %10, label %11, label %3
11: ; preds = %3, %1
%12 = phi double [ 0.000000e+00, %1 ], [ %8, %3 ]
%13 = load double, double* @M_LOG10E
%14 = fmul double %12, %13
%15 = tail call i32 @ceil(double %14)
ret i32 %15
}