#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 fatorial(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  setlocale(0, "portuguese");
  int num, resultado;
  puts("Insira o número para calcular o fatorial: ");
  scanf("%d", &num);
  resultado = fatorial(num);
  if (resultado)
    fprintf(stdout, "O resultado: %d\n", resultado);
  else
    fprintf(stdout,
            "Ocorreu um erro ao calcular o fatorial deste numero <%d>,\n "
            "talvez ele seja grande demais,\n tente com um número menor.\n",
            num);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
lea    0xe91(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb0(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x14(%rbp),%edi
call   1050 <fatorial@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11c2 <main+0x72>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11da <main+0x8a>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe76(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xea8(%rip),%rsi
xor    %edi,%edi
call   1060 <setlocale@plt>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0xec5(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
call   1050 <fatorial@plt>
mov    0x2e54(%rip),%rcx
mov    (%rcx),%edi
test   %eax,%eax
je     119d <main+0x4d>
lea    0xea1(%rip),%rsi
mov    %eax,%edx
jmp    11a8 <main+0x58>
mov    0x4(%rsp),%edx
lea    0xea3(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"portuguese\00"
@.str.1 = [44 x i8] c"Insira o n\C3\BAmero para calcular o fatorial: \00"
@.str.2 = [3 x i8] c"%d\00"
@stdout = global i32 0
@.str.3 = [17 x i8] c"O resultado: %d\0A\00"
@.str.4 = [120 x i8] c"Ocorreu um erro ao calcular o fatorial deste numero <%d>,\0A talvez ele seja grande demais,\0A tente com um n\C3\BAmero menor.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @setlocale(i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%11 = load i32, i32* %6
%12 = call i32 @fatorial(i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stdout
%17 = load i32, i32* %7
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %23
19: ; preds = %2
%20 = load i32, i32* @stdout
%21 = load i32, i32* %6
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([120 x i8], [120 x i8]* @.str.4, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %15
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"portuguese\00"
@.str.1 = [44 x i8] c"Insira o n\C3\BAmero para calcular o fatorial: \00"
@.str.2 = [3 x i8] c"%d\00"
@stdout = global i32 0
@.str.3 = [17 x i8] c"O resultado: %d\0A\00"
@.str.4 = [120 x i8] c"Ocorreu um erro ao calcular o fatorial deste numero <%d>,\0A talvez ele seja grande demais,\0A tente com um n\C3\BAmero menor.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 @setlocale(i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = call i32 @fatorial(i32 %8)
%10 = icmp eq i32 %9, 0
%11 = load i32, i32* @stdout
br i1 %10, label %14, label %12
12: ; preds = %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %9)
br label %17
14: ; preds = %2
%15 = load i32, i32* %3
%16 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([120 x i8], [120 x i8]* @.str.4, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %12
ret i32 0
}