#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 factorial(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int n;
  do {
    printf("\nEnter a number:\n> ");
    scanf("%d", &n);
    if (n < 0) {
      printf("Number is negative. Please try again\n");
    }
  } while (n < 1);
  printf("\n%d! = %d\n", n, factorial(n));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1175 <main+0x45>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    117a <main+0x4a>
cmpl   $0x1,-0x8(%rbp)
jl     113f <main+0xf>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <factorial@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xead(%rip),%r14
lea    0xeba(%rip),%r15
lea    0xc(%rsp),%rbx
lea    0xebc(%rip),%r12
jmp    1174 <main+0x34>
nopl   0x0(%rax,%rax,1)
test   %ebp,%ebp
jg     119f <main+0x5f>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%ebp
test   %ebp,%ebp
jns    1170 <main+0x30>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%ebp
jmp    1170 <main+0x30>
mov    %ebp,%edi
call   1040 <factorial@plt>
lea    0xe6a(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"\0AEnter a number:\0A> \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"Number is negative. Please try again\0A\00"
@.str.3 = [11 x i8] c"\0A%d! = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %11, %0
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
br label %11
11: ; preds = %10
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 1
br i1 %13, label %3, label %14
14: ; preds = %11
%15 = load i32, i32* %2
%16 = load i32, i32* %2
%17 = call i32 @factorial(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"\0AEnter a number:\0A> \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [11 x i8] c"\0A%d! = %d\0A\00"
@str = [37 x i8] c"Number is negative. Please try again\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %11, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* %1
br label %11
11: ; preds = %3, %8
%12 = phi i32 [ %6, %3 ], [ %10, %8 ]
%13 = icmp slt i32 %12, 1
br i1 %13, label %3, label %14
14: ; preds = %11
%15 = call i32 @factorial(i32 %12)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %15)
ret i32 0
}