#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 */
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ fact32(int);
scalar_t__ fact64(int);
scalar_t__ fact64_linear(int);
scalar_t__ fact64_tail(int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char const *argv[]) {
  assert(fact32(16) > 0);
  assert(fact32(16 + 1) < 0);
  assert(fact64(20) > 0);
  assert(fact64(20 + 1) < 0);
  for (int64_t i = 0; i <= 20; i++) {
    assert(fact64(i) == fact64_tail(i));
    assert(fact64(i) == fact64_linear(i));
  }
  printf("All Ok.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x10,%edi
call   1080 <fact32@plt>
cmp    $0x0,%rax
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x11,%edi
call   1080 <fact32@plt>
cmp    $0x0,%rax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x14,%edi
call   1030 <fact64@plt>
cmp    $0x0,%rax
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x15,%edi
call   1030 <fact64@plt>
cmp    $0x0,%rax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jg     1257 <main+0xf7>
mov    -0x14(%rbp),%edi
call   1030 <fact64@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <fact64_tail@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x14(%rbp),%edi
call   1030 <fact64@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <fact64_linear@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e9 <main+0x89>
lea    0xda2(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x10,%edi
call   1080 <fact32@plt>
xor    %edi,%edi
test   %rax,%rax
setg   %dil
call   1060 <assert@plt>
mov    $0x11,%edi
call   1080 <fact32@plt>
shr    $0x3f,%rax
mov    %eax,%edi
call   1060 <assert@plt>
mov    $0x14,%edi
call   1030 <fact64@plt>
xor    %edi,%edi
test   %rax,%rax
setg   %dil
call   1060 <assert@plt>
mov    $0x15,%edi
call   1030 <fact64@plt>
shr    $0x3f,%rax
mov    %eax,%edi
call   1060 <assert@plt>
xor    %ebx,%ebx
mov    %ebx,%edi
call   1030 <fact64@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1070 <fact64_tail@plt>
xor    %edi,%edi
cmp    %rax,%r14
sete   %dil
call   1060 <assert@plt>
mov    %ebx,%edi
call   1030 <fact64@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1050 <fact64_linear@plt>
xor    %edi,%edi
cmp    %rax,%r14
sete   %dil
call   1060 <assert@plt>
add    $0x1,%ebx
cmp    $0x15,%ebx
jne    11c0 <main+0x60>
lea    0xdf3(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"All Ok.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 @fact32(i32 16)
%8 = icmp sgt i64 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i64 @fact32(i32 17)
%12 = icmp slt i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = call i64 @fact64(i32 20)
%16 = icmp sgt i64 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i64 @fact64(i32 21)
%20 = icmp slt i64 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
store i32 0, i32* %6
br label %23
23: ; preds = %41, %2
%24 = load i32, i32* %6
%25 = icmp sle i32 %24, 20
br i1 %25, label %26, label %44
26: ; preds = %23
%27 = load i32, i32* %6
%28 = call i64 @fact64(i32 %27)
%29 = load i32, i32* %6
%30 = call i64 @fact64_tail(i32 %29)
%31 = icmp eq i64 %28, %30
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32, i32* %6
%35 = call i64 @fact64(i32 %34)
%36 = load i32, i32* %6
%37 = call i64 @fact64_linear(i32 %36)
%38 = icmp eq i64 %35, %37
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
br label %41
41: ; preds = %26
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %23
44: ; preds = %23
%45 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@str = [8 x i8] c"All Ok.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @fact32(i32 16)
%4 = icmp sgt i64 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i64 @fact32(i32 17)
%8 = lshr i64 %7, 63
%9 = trunc i64 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i64 @fact64(i32 20)
%12 = icmp sgt i64 %11, 0
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i64 @fact64(i32 21)
%16 = lshr i64 %15, 63
%17 = trunc i64 %16 to i32
%18 = tail call i32 @assert(i32 %17)
br label %21
19: ; preds = %21
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32 0
21: ; preds = %2, %21
%22 = phi i32 [ 0, %2 ], [ %33, %21 ]
%23 = tail call i64 @fact64(i32 %22)
%24 = tail call i64 @fact64_tail(i32 %22)
%25 = icmp eq i64 %23, %24
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = tail call i64 @fact64(i32 %22)
%29 = tail call i64 @fact64_linear(i32 %22)
%30 = icmp eq i64 %28, %29
%31 = zext i1 %30 to i32
%32 = tail call i32 @assert(i32 %31)
%33 = add nuw nsw i32 %22, 1
%34 = icmp eq i32 %33, 21
br i1 %34, label %19, label %21
}