#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");
  while (scanf("%d", &num) == 1) {
    if (num < 0)
      printf("No negative numbers please.\n");
    else if (num > 12)
      printf("Keep input lower than 13.\n");
    else {
      printf("loop: %d! = %ld\n", num, fact(num));
      printf("recursion: %d! = %ld\n", num, rfact(num));
    }
    printf("Enter a value in the range of 0 - 12 (q to quit): \n");
  }
  printf("Bye.\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    0xec1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    120a <main+0xca>
cmpl   $0x0,-0x8(%rbp)
jge    1193 <main+0x53>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f7 <main+0xb7>
cmpl   $0xc,-0x8(%rbp)
jle    11b0 <main+0x70>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f2 <main+0xb2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <fact@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe96(%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    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f7 <main+0xb7>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    115d <main+0x1d>
lea    0xeaa(%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    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe92(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1224 <main+0xd4>
lea    0xf18(%rip),%r14
lea    0xec4(%rip),%r15
lea    0xe6a(%rip),%r12
lea    0x4(%rsp),%rbx
lea    0xe72(%rip),%r13
jmp    11d0 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1224 <main+0xd4>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
js     11b0 <main+0x60>
cmp    $0xd,%ebp
jb     11f0 <main+0xa0>
lea    0xea2(%rip),%rdi
jmp    11b3 <main+0x63>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1060 <fact@plt>
lea    0xe05(%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    11b8 <main+0x68>
lea    0xe23(%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 = [37 x i8] c"This program calculates factorials.\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"No negative numbers please.\0A\00"
@.str.3 = [27 x i8] c"Keep input lower than 13.\0A\00"
@.str.4 = [17 x i8] c"loop: %d! = %ld\0A\00"
@.str.5 = [22 x i8] c"recursion: %d! = %ld\0A\00"
@.str.6 = [52 x i8] c"Enter a value in the range of 0 - 12 (q to quit): \0A\00"
@.str.7 = [6 x i8] c"Bye.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %27, %0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %29
7: ; preds = %4
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %27
12: ; preds = %7
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 12
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %26
17: ; preds = %12
%18 = load i32, i32* %2
%19 = load i32, i32* %2
%20 = call i32 @fact(i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %18, i32 %20)
%22 = load i32, i32* %2
%23 = load i32, i32* %2
%24 = call i32 @rfact(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %22, i32 %24)
br label %26
26: ; preds = %17, %15
br label %27
27: ; preds = %26, %10
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0))
br label %4
29: ; preds = %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

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