double kaijyou(int n) {
  static double bank[1000] = {1, 1};
  static int nmax = 1;
  int i;
  double a;
  if (n < 0) {
    return 1.0;
  } else if (n <= nmax) {
    return bank[n];
  }
  a = bank[nmax];
  for (i = nmax + 1; i <= n; i++) {
    a *= i;
    bank[i] = a;
  }
  nmax = n;
  return a;
}


x86 assembly (clang, -O0):
<kaijyou>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1123 <kaijyou+0x23>
movsd  0xee7(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c6 <kaijyou+0xc6>
mov    -0xc(%rbp),%eax
cmp    0x4e44(%rip),%eax
jg     114c <kaijyou+0x4c>
movslq -0xc(%rbp),%rcx
lea    0x2ef3(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c6 <kaijyou+0xc6>
jmp    1151 <kaijyou+0x51>
movslq 0x4e18(%rip),%rcx
lea    0x2ed1(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    0x4e01(%rip),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11b3 <kaijyou+0xb3>
cvtsi2sdl -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movslq -0x10(%rbp),%rcx
lea    0x2e90(%rip),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1175 <kaijyou+0x75>
mov    -0xc(%rbp),%eax
mov    %eax,0x4db4(%rip)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<kaijyou>:
test   %edi,%edi
js     11d0 <kaijyou+0xd0>
movslq 0x4e61(%rip),%rax
cmp    %edi,%eax
jge    11d9 <kaijyou+0xd9>
lea    0x2f12(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
mov    %edi,%r9d
mov    %edi,%esi
sub    %eax,%esi
mov    %rax,%r8
not    %r8
add    %r9,%r8
and    $0x3,%rsi
je     115e <kaijyou+0x5e>
lea    0x1(%rax),%edx
nopl   0x0(%rax)
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rcx,%rax,8)
add    $0x1,%rax
add    $0x1,%edx
add    $0xffffffffffffffff,%rsi
jne    1140 <kaijyou+0x40>
cmp    $0x3,%r8
jb     11c9 <kaijyou+0xc9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(%rax),%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rcx,%rax,8)
lea    0x2(%rax),%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rcx,%rax,8)
lea    0x3(%rax),%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
mulsd  %xmm0,%xmm1
lea    0x4(%rax),%rdx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movsd  %xmm1,0x18(%rcx,%rax,8)
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rcx,%rax,8)
mov    %rdx,%rax
cmp    %rdx,%r9
jne    1170 <kaijyou+0x70>
mov    %edi,0x4da1(%rip)
ret
movsd  0xe28(%rip),%xmm0
ret
mov    %edi,%eax
lea    0x2e4e(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
ret

LLVM IR (-O0):
@kaijyou.bank = internal global <{ double, double, [998 x double] }> <{ double 1.000000e+00, double 1.000000e+00, [998 x double] zeroinitializer }>
@kaijyou.nmax = internal global i32 1
define double @kaijyou(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store double 1.000000e+00, double* %2
br label %45
9: ; preds = %1
%10 = load i32, i32* %3
%11 = load i32, i32* @kaijyou.nmax
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1000 x double], [1000 x double]* bitcast (<{ double, double, [998 x double] }>* @kaijyou.bank to [1000 x double]*), i64 0, i64 %15
%17 = load double, double* %16
store double %17, double* %2
br label %45
18: ; preds = %9
br label %19
19: ; preds = %18
%20 = load i32, i32* @kaijyou.nmax
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1000 x double], [1000 x double]* bitcast (<{ double, double, [998 x double] }>* @kaijyou.bank to [1000 x double]*), i64 0, i64 %21
%23 = load double, double* %22
store double %23, double* %5
%24 = load i32, i32* @kaijyou.nmax
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %39, %19
%27 = load i32, i32* %4
%28 = load i32, i32* %3
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %42
30: ; preds = %26
%31 = load i32, i32* %4
%32 = sitofp i32 %31 to double
%33 = load double, double* %5
%34 = fmul double %33, %32
store double %34, double* %5
%35 = load double, double* %5
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1000 x double], [1000 x double]* bitcast (<{ double, double, [998 x double] }>* @kaijyou.bank to [1000 x double]*), i64 0, i64 %37
store double %35, double* %38
br label %39
39: ; preds = %30
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %26
42: ; preds = %26
%43 = load i32, i32* %3
store i32 %43, i32* @kaijyou.nmax
%44 = load double, double* %5
store double %44, double* %2
br label %45
45: ; preds = %42, %13, %8
%46 = load double, double* %2
ret double %46
}

LLVM IR (-O2):
@kaijyou.bank = internal unnamed_addr global <{ double, double, [998 x double] }> <{ double 1.000000e+00, double 1.000000e+00, [998 x double] zeroinitializer }>
@kaijyou.nmax = internal unnamed_addr global i32 1
define double @kaijyou(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %62, label %3
3: ; preds = %1
%4 = load i32, i32* @kaijyou.nmax
%5 = icmp slt i32 %4, %0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = zext i32 %0 to i64
%8 = getelementptr inbounds [1000 x double], [1000 x double]* bitcast (<{ double, double, [998 x double] }>* @kaijyou.bank to [1000 x double]*), i64 0, i64 %7
%9 = load double, double* %8
br label %62
10: ; preds = %3
%11 = sext i32 %4 to i64
%12 = getelementptr inbounds [1000 x double], [1000 x double]* bitcast (<{ double, double, [998 x double] }>* @kaijyou.bank to [1000 x double]*), i64 0, i64 %11
%13 = load double, double* %12
%14 = zext i32 %0 to i64
%15 = sub nsw i64 %14, %11
%16 = xor i64 %11, -1
%17 = add nsw i64 %16, %14
%18 = and i64 %15, 3
%19 = icmp eq i64 %18, 0
br i1 %19, label %31, label %20
20: ; preds = %10, %20
%21 = phi i64 [ %24, %20 ], [ %11, %10 ]
%22 = phi double [ %27, %20 ], [ %13, %10 ]
%23 = phi i64 [ %29, %20 ], [ 0, %10 ]
%24 = add nsw i64 %21, 1
%25 = trunc i64 %24 to i32
%26 = sitofp i32 %25 to double
%27 = fmul double %22, %26
%28 = getelementptr inbounds [1000 x double], [1000 x double]* bitcast (<{ double, double, [998 x double] }>* @kaijyou.bank to [1000 x double]*), i64 0, i64 %24
store double %27, double* %28
%29 = add i64 %23, 1
%30 = icmp eq i64 %29, %18
br i1 %30, label %31, label %20
31: ; preds = %20, %10
%32 = phi double [ undef, %10 ], [ %27, %20 ]
%33 = phi i64 [ %11, %10 ], [ %24, %20 ]
%34 = phi double [ %13, %10 ], [ %27, %20 ]
%35 = icmp ult i64 %17, 3
br i1 %35, label %60, label %36
36: ; preds = %31, %36
%37 = phi i64 [ %54, %36 ], [ %33, %31 ]
%38 = phi double [ %57, %36 ], [ %34, %31 ]
%39 = add nsw i64 %37, 1
%40 = trunc i64 %39 to i32
%41 = sitofp i32 %40 to double
%42 = fmul double %38, %41
%43 = getelementptr inbounds [1000 x double], [1000 x double]* bitcast (<{ double, double, [998 x double] }>* @kaijyou.bank to [1000 x double]*), i64 0, i64 %39
store double %42, double* %43
%44 = add nsw i64 %37, 2
%45 = trunc i64 %44 to i32
%46 = sitofp i32 %45 to double
%47 = fmul double %42, %46
%48 = getelementptr inbounds [1000 x double], [1000 x double]* bitcast (<{ double, double, [998 x double] }>* @kaijyou.bank to [1000 x double]*), i64 0, i64 %44
store double %47, double* %48
%49 = add nsw i64 %37, 3
%50 = trunc i64 %49 to i32
%51 = sitofp i32 %50 to double
%52 = fmul double %47, %51
%53 = getelementptr inbounds [1000 x double], [1000 x double]* bitcast (<{ double, double, [998 x double] }>* @kaijyou.bank to [1000 x double]*), i64 0, i64 %49
store double %52, double* %53
%54 = add nsw i64 %37, 4
%55 = trunc i64 %54 to i32
%56 = sitofp i32 %55 to double
%57 = fmul double %52, %56
%58 = getelementptr inbounds [1000 x double], [1000 x double]* bitcast (<{ double, double, [998 x double] }>* @kaijyou.bank to [1000 x double]*), i64 0, i64 %54
store double %57, double* %58
%59 = icmp eq i64 %54, %14
br i1 %59, label %60, label %36
60: ; preds = %36, %31
%61 = phi double [ %32, %31 ], [ %57, %36 ]
store i32 %0, i32* @kaijyou.nmax
br label %62
62: ; preds = %1, %60, %6
%63 = phi double [ %9, %6 ], [ %61, %60 ], [ 1.000000e+00, %1 ]
ret double %63
}