#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(long);
double logfac(long n) {
  long i;
  double x;
  switch (n) {
  case 0:
    return 0.;
  case 1:
    return 0.;
  case 2:
    return 0.693147180559945309417232121458;
  case 3:
    return 1.791759469228055000812477358381;
  case 4:
    return 3.1780538303479456196469416013;
  case 5:
    return 4.78749174278204599424770093452;
  case 6:
    return 6.5792512120101009950601782929;
  case 7:
    return 8.52516136106541430016553103635;
  case 8:
    return 10.60460290274525022841722740072;
  case 9:
    return 12.80182748008146961120771787457;
  case 10:
    return 15.10441257307551529522570932925;
  case 11:
    return 17.50230784587388583928765290722;
  case 12:
    return 19.98721449566188614951736238706;
  default:
    x = 19.98721449566188614951736238706;
    for (i = 13; i <= n; i++)
      x += log(i);
    return x;
  }
}


x86 assembly (clang, -O0):
<logfac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
sub    $0xc,%rax
ja     1222 <logfac+0x112>
mov    -0x28(%rbp),%rax
lea    0xf1f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xeec(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xed2(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xeb8(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xe9e(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xe84(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xe6a(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xe50(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xe36(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xe1c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xe02(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xde8(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <logfac+0x163>
movsd  0xdd6(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movq   $0xd,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jg     1269 <logfac+0x159>
mov    -0x18(%rbp),%rdi
call   1030 <log@plt>
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1237 <logfac+0x127>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logfac>:
push   %r14
push   %rbx
push   %rax
cmp    $0xd,%rdi
jae    1128 <logfac+0x18>
lea    0xee7(%rip),%rax
movsd  (%rax,%rdi,8),%xmm0
jmp    1182 <logfac+0x72>
jge    1134 <logfac+0x24>
movsd  0xece(%rip),%xmm0
jmp    1182 <logfac+0x72>
mov    $0xc,%r14d
sub    %rdi,%r14
mov    $0xd,%ebx
movsd  0xeb6(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <log@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0xd,%rax
jne    1150 <logfac+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @logfac(i64 %0) {
%2 = alloca double
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
store i64 %0, i64* %3
%6 = load i64, i64* %3
switch i64 %6, label %20 [
i64 0, label %7
i64 1, label %8
i64 2, label %9
i64 3, label %10
i64 4, label %11
i64 5, label %12
i64 6, label %13
i64 7, label %14
i64 8, label %15
i64 9, label %16
i64 10, label %17
i64 11, label %18
i64 12, label %19
]
7: ; preds = %1
store double 0.000000e+00, double* %2
br label %35
8: ; preds = %1
store double 0.000000e+00, double* %2
br label %35
9: ; preds = %1
store double 0x3FE62E42FEFA39EF, double* %2
br label %35
10: ; preds = %1
store double 0x3FFCAB0BFA2A2002, double* %2
br label %35
11: ; preds = %1
store double 0x40096CA77C922CF9, double* %2
br label %35
12: ; preds = %1
store double 0x401326643C4479C9, double* %2
br label %35
13: ; preds = %1
store double 0x401A51273ACF01CA, double* %2
br label %35
14: ; preds = %1
store double 0x40210CE1F32DCC30, double* %2
br label %35
15: ; preds = %1
store double 0x4025358E82FCB70D, double* %2
br label %35
16: ; preds = %1
store double 0x40299A8921A7F7CF, double* %2
br label %35
17: ; preds = %1
store double 0x402E357590954D15, double* %2
br label %35
18: ; preds = %1
store double 0x403180973F3A8D74, double* %2
br label %35
19: ; preds = %1
store double 0x4033FCBA16D50143, double* %2
br label %35
20: ; preds = %1
store double 0x4033FCBA16D50143, double* %5
store i64 13, i64* %4
br label %21
21: ; preds = %30, %20
%22 = load i64, i64* %4
%23 = load i64, i64* %3
%24 = icmp sle i64 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i64, i64* %4
%27 = call double @log(i64 %26)
%28 = load double, double* %5
%29 = fadd double %28, %27
store double %29, double* %5
br label %30
30: ; preds = %25
%31 = load i64, i64* %4
%32 = add nsw i64 %31, 1
store i64 %32, i64* %4
br label %21
33: ; preds = %21
%34 = load double, double* %5
store double %34, double* %2
br label %35
35: ; preds = %33, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7
%36 = load double, double* %2
ret double %36
}

LLVM IR (-O2):
@switch.table.logfac = [13 x double] [double 0.000000e+00, double 0.000000e+00, double 0x3FE62E42FEFA39EF, double 0x3FFCAB0BFA2A2002, double 0x40096CA77C922CF9, double 0x401326643C4479C9, double 0x401A51273ACF01CA, double 0x40210CE1F32DCC30, double 0x4025358E82FCB70D, double 0x40299A8921A7F7CF, double 0x402E357590954D15, double 0x403180973F3A8D74, double 0x4033FCBA16D50143]
define double @logfac(i64 %0) {
%2 = icmp ult i64 %0, 13
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = icmp slt i64 %0, 13
br i1 %4, label %15, label %5
5: ; preds = %3, %5
%6 = phi double [ %9, %5 ], [ 0x4033FCBA16D50143, %3 ]
%7 = phi i64 [ %10, %5 ], [ 13, %3 ]
%8 = tail call double @log(i64 %7)
%9 = fadd double %6, %8
%10 = add nuw i64 %7, 1
%11 = icmp eq i64 %7, %0
br i1 %11, label %15, label %5
12: ; preds = %1
%13 = getelementptr inbounds [13 x double], [13 x double]* @switch.table.logfac, i64 0, i64 %0
%14 = load double, double* %13
br label %15
15: ; preds = %5, %12, %3
%16 = phi double [ 0x4033FCBA16D50143, %3 ], [ %14, %12 ], [ %9, %5 ]
ret double %16
}