#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 */
unsigned long long factorial(unsigned int);
int main(void) {
  unsigned long long factorials[21] = {1,
                                       1,
                                       2,
                                       6,
                                       24,
                                       120,
                                       720,
                                       5040,
                                       40320,
                                       362880,
                                       3628800,
                                       39916800,
                                       479001600,
                                       6227020800,
                                       87178291200,
                                       1307674368000,
                                       20922789888000,
                                       355687428096000,
                                       6402373705728000,
                                       121645100408832000,
                                       2432902008176640000};
  for (unsigned int i = 0; i < 21; ++i) {
    unsigned long long ret = factorial(i);
    if (ret != factorials[i])
      return i + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xb0(%rbp),%rdi
lea    0xec0(%rip),%rsi
mov    $0xa8,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0xb4(%rbp)
cmpl   $0x15,-0xb4(%rbp)
jae    11b8 <main+0x98>
mov    -0xb4(%rbp),%edi
call   1030 <factorial@plt>
mov    %rax,-0xc0(%rbp)
mov    -0xc0(%rbp),%rax
mov    -0xb4(%rbp),%ecx
cmp    -0xb0(%rbp,%rcx,8),%rax
ff
je     119f <main+0x7f>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <main+0x9f>
jmp    11a4 <main+0x84>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    1154 <main+0x34>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xee4(%rip),%r15
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x15,%rbx
je     1150 <main+0x40>
mov    %ebx,%edi
call   1030 <factorial@plt>
add    $0x1,%rbx
lea    0x8(%r15),%rcx
cmp    (%r15),%rax
mov    %rcx,%r15
je     1130 <main+0x20>
mov    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.factorials = [21 x i64] [i64 1, i64 1, i64 2, i64 6, i64 24, i64 120, i64 720, i64 5040, i64 40320, i64 362880, i64 3628800, i64 39916800, i64 479001600, i64 6227020800, i64 87178291200, i64 1307674368000, i64 20922789888000, i64 355687428096000, i64 6402373705728000, i64 121645100408832000, i64 2432902008176640000]
define i32 @main() {
%1 = alloca i32
%2 = alloca [21 x i64]
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
%5 = bitcast [21 x i64]* %2 to i8*
store i32 0, i32* %3
br label %6
6: ; preds = %22, %0
%7 = load i32, i32* %3
%8 = icmp ult i32 %7, 21
br i1 %8, label %9, label %25
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i64 @factorial(i32 %10)
store i64 %11, i64* %4
%12 = load i64, i64* %4
%13 = load i32, i32* %3
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [21 x i64], [21 x i64]* %2, i64 0, i64 %14
%16 = load i64, i64* %15
%17 = icmp ne i64 %12, %16
br i1 %17, label %18, label %21
18: ; preds = %9
%19 = load i32, i32* %3
%20 = add i32 %19, 1
store i32 %20, i32* %1
br label %26
21: ; preds = %9
br label %22
22: ; preds = %21
%23 = load i32, i32* %3
%24 = add i32 %23, 1
store i32 %24, i32* %3
br label %6
25: ; preds = %6
store i32 0, i32* %1
br label %26
26: ; preds = %25, %18
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@__const.main.factorials = [21 x i64] [i64 1, i64 1, i64 2, i64 6, i64 24, i64 120, i64 720, i64 5040, i64 40320, i64 362880, i64 3628800, i64 39916800, i64 479001600, i64 6227020800, i64 87178291200, i64 1307674368000, i64 20922789888000, i64 355687428096000, i64 6402373705728000, i64 121645100408832000, i64 2432902008176640000]
define i32 @main() {
br label %1
1: ; preds = %4, %0
%2 = phi i64 [ %10, %4 ], [ 0, %0 ]
%3 = icmp eq i64 %2, 21
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = trunc i64 %2 to i32
%6 = tail call i64 @factorial(i32 %5)
%7 = getelementptr inbounds [21 x i64], [21 x i64]* @__const.main.factorials, i64 0, i64 %2
%8 = load i64, i64* %7
%9 = icmp eq i64 %6, %8
%10 = add nuw nsw i64 %2, 1
br i1 %9, label %1, label %11
11: ; preds = %4
%12 = trunc i64 %10 to i32
br label %13
13: ; preds = %1, %11
%14 = phi i32 [ %12, %11 ], [ 0, %1 ]
ret i32 %14
}