#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 */
int /*<<< orphan*/ fact(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rfact(int);
int scanf(char *, int *);
int main(void) {
  int num;
  printf("This program calculates factorials\n");
  printf("Enter a value in the 0-12 (q to quit): ");
  while (scanf("%d", &num) == 1) {
    if (num < 0) {
      printf("No negative numbers\n");
    } else if (num > 12) {
      printf("Keep it under 13 buddy\n");
    } else {
      printf("loop %d factorial = %ld\n", num, fact(num));
      printf("recursion: %d factorial = %ld\n", num, rfact(num));
    }
    printf("Enter a value in the 0-12 (q to quit): ");
  }
  printf("Peace out\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1218 <main+0xd8>
cmpl   $0x0,-0x8(%rbp)
jge    11a1 <main+0x61>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1205 <main+0xc5>
cmpl   $0xc,-0x8(%rbp)
jle    11be <main+0x7e>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1200 <main+0xc0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <fact@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <rfact@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1205 <main+0xc5>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    116b <main+0x2b>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf01(%rip),%rdi
call   1030 <puts@plt>
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1234 <main+0xe4>
lea    0xf11(%rip),%r14
lea    0xe63(%rip),%r15
lea    0xe84(%rip),%r12
lea    0x4(%rsp),%rbx
lea    0xe94(%rip),%r13
jmp    11e2 <main+0x92>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1234 <main+0xe4>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
js     11c0 <main+0x70>
cmp    $0xd,%ebp
jb     1200 <main+0xb0>
lea    0xe9a(%rip),%rdi
jmp    11c3 <main+0x73>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1060 <fact@plt>
lea    0xe1d(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
call   1050 <rfact@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c8 <main+0x78>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"This program calculates factorials\0A\00"
@.str.1 = [40 x i8] c"Enter a value in the 0-12 (q to quit): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [21 x i8] c"No negative numbers\0A\00"
@.str.4 = [24 x i8] c"Keep it under 13 buddy\0A\00"
@.str.5 = [25 x i8] c"loop %d factorial = %ld\0A\00"
@.str.6 = [31 x i8] c"recursion: %d factorial = %ld\0A\00"
@.str.7 = [11 x i8] c"Peace out\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %28, %0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %30
8: ; preds = %5
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %28
13: ; preds = %8
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 12
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %27
18: ; preds = %13
%19 = load i32, i32* %2
%20 = load i32, i32* %2
%21 = call i32 @fact(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %19, i32 %21)
%23 = load i32, i32* %2
%24 = load i32, i32* %2
%25 = call i32 @rfact(i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %23, i32 %25)
br label %27
27: ; preds = %18, %16
br label %28
28: ; preds = %27, %11
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %5
30: ; preds = %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [40 x i8] c"Enter a value in the 0-12 (q to quit): \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.5 = [25 x i8] c"loop %d factorial = %ld\0A\00"
@.str.6 = [31 x i8] c"recursion: %d factorial = %ld\0A\00"
@str = [35 x i8] c"This program calculates factorials\00"
@str.8 = [10 x i8] c"Peace out\00"
@str.9 = [23 x i8] c"Keep it under 13 buddy\00"
@str.10 = [20 x i8] c"No negative numbers\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %26
7: ; preds = %0, %22
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0))
br label %22
12: ; preds = %7
%13 = icmp ugt i32 %8, 12
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.9, i64 0, i64 0))
br label %22
16: ; preds = %12
%17 = call i32 @fact(i32 %8)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %8, i32 %17)
%19 = load i32, i32* %1
%20 = call i32 @rfact(i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %19, i32 %20)
br label %22
22: ; preds = %14, %16, %10
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%25 = icmp eq i32 %24, 1
br i1 %25, label %7, label %26
26: ; preds = %22, %0
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0))
ret i32 0
}