#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*/ factorial(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int num;
  printf("Ingrese un numero: ");
  scanf("%d", &num);
  if (num > 20) {
    printf("Factorial demasiado grande\n");
    return -1;
  }
  if (num >= 0)
    printf("%d! = %lu\n", num, factorial(num));
  else
    printf("No existen los factoriales de numeros negativos\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   $0x14,-0x8(%rbp)
jle    1181 <main+0x51>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <main+0x96>
cmpl   $0x0,-0x8(%rbp)
jl     11b1 <main+0x81>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <factorial@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11bf <main+0x8f>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xebc(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%ebx
cmp    $0x15,%ebx
jl     117e <main+0x3e>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
jmp    11ad <main+0x6d>
test   %ebx,%ebx
js     119f <main+0x5f>
mov    %ebx,%edi
call   1040 <factorial@plt>
lea    0xe87(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11ad <main+0x6d>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Ingrese un numero: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"Factorial demasiado grande\0A\00"
@.str.3 = [11 x i8] c"%d! = %lu\0A\00"
@.str.4 = [49 x i8] c"No existen los factoriales de numeros negativos\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 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* %2)
%5 = load i32, i32* %2
%6 = icmp sgt i32 %5, 20
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %20
9: ; preds = %0
%10 = load i32, i32* %2
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* %2
%14 = load i32, i32* %2
%15 = call i32 @factorial(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %15)
br label %19
17: ; preds = %9
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
store i32 0, i32* %1
br label %20
20: ; preds = %19, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [20 x i8] c"Ingrese un numero: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [11 x i8] c"%d! = %lu\0A\00"
@str = [48 x i8] c"No existen los factoriales de numeros negativos\00"
@str.5 = [27 x i8] c"Factorial demasiado grande\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 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 = load i32, i32* %1
%6 = icmp sgt i32 %5, 20
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %16
9: ; preds = %0
%10 = icmp sgt i32 %5, -1
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = call i32 @factorial(i32 %5)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %5, i32 %12)
br label %16
14: ; preds = %9
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %11, %14, %7
%17 = phi i32 [ -1, %7 ], [ 0, %14 ], [ 0, %11 ]
ret i32 %17
}