#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, n, fact = 1;
  printf("Introduzca el número al cual se le calculará su factorial: ");
  scanf("%d", &n);
  if (n < 0) {
    printf("\nEl número introducido  no es valido.");
    return 0;
  } else {
    for (i = n; i > 0; i--) {
      fact = fact * i;
      if (i > 1) {
        printf("%d! * ", i);
      } else {
        printf("%d!", i);
      }
    }
    printf(" = %d", fact);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf28(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jge    1178 <main+0x58>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ee <main+0xce>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11d6 <main+0xb6>
mov    -0x10(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11b2 <main+0x92>
mov    -0x8(%rbp),%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c3 <main+0xa3>
mov    -0x8(%rbp),%esi
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c8 <main+0xa8>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    117e <main+0x5e>
mov    -0x10(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf35(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%r15d
test   %r15d,%r15d
js     119b <main+0x7b>
je     11ab <main+0x8b>
cmp    $0x1,%r15d
je     1186 <main+0x66>
lea    -0x1(%r15),%ebx
lea    0xf00(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
imul   %ebx,%r15d
add    $0xffffffff,%ebx
jne    1170 <main+0x50>
lea    0xedf(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11b1 <main+0x91>
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c2 <main+0xa2>
mov    $0x1,%r15d
lea    0xeb8(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [62 x i8] c"Introduzca el n\C3\BAmero al cual se le calcular\C3\A1 su factorial: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"\0AEl n\C3\BAmero introducido no es valido.\00"
@.str.3 = [7 x i8] c"%d! * \00"
@.str.4 = [4 x i8] c"%d!\00"
@.str.5 = [6 x i8] c" = %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %36
11: ; preds = %0
%12 = load i32, i32* %3
store i32 %12, i32* %2
br label %13
13: ; preds = %29, %11
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %32
16: ; preds = %13
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = mul nsw i32 %17, %18
store i32 %19, i32* %4
%20 = load i32, i32* %2
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %28
25: ; preds = %16
%26 = load i32, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %22
br label %29
29: ; preds = %28
%30 = load i32, i32* %2
%31 = add nsw i32 %30, -1
store i32 %31, i32* %2
br label %13
32: ; preds = %13
%33 = load i32, i32* %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32
store i32 0, i32* %1
br label %36
36: ; preds = %35, %9
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [62 x i8] c"Introduzca el n\C3\BAmero al cual se le calcular\C3\A1 su factorial: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"\0AEl n\C3\BAmero introducido no es valido.\00"
@.str.3 = [7 x i8] c"%d! * \00"
@.str.4 = [4 x i8] c"%d!\00"
@.str.5 = [6 x i8] c" = %d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 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 slt i32 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %0
switch i32 %5, label %10 [
i32 0, label %20
i32 1, label %17
]
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %23
10: ; preds = %7, %10
%11 = phi i32 [ %15, %10 ], [ %5, %7 ]
%12 = phi i32 [ %14, %10 ], [ %5, %7 ]
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = add nsw i32 %12, -1
%15 = mul nsw i32 %11, %14
%16 = icmp eq i32 %14, 1
br i1 %16, label %17, label %10
17: ; preds = %10, %7
%18 = phi i32 [ %5, %7 ], [ %15, %10 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %20
20: ; preds = %7, %17
%21 = phi i32 [ 1, %7 ], [ %18, %17 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %8
ret i32 0
}