#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 fatorial(int N) {
  int f;
  printf("Entrei em fatorial(%d)\n", N);
  if (N == 1) {
    printf("Retornando fatorial(1) = 1\n");
    return 1;
  } else {
    f = fatorial(N - 1) * N;
    printf("Retornando fatorial(%d) = %d\n", N, f);
    return f;
  }
}


x86 assembly (clang, -O0):
<fatorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1160 <fatorial+0x40>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    118c <fatorial+0x6c>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1040 <fatorial@plt>
imul   -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fatorial>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xec4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%ebx
jne    115d <fatorial+0x2d>
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
jmp    117c <fatorial+0x4c>
lea    -0x1(%rbx),%edi
call   1050 <fatorial@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
lea    0xea7(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Entrei em fatorial(%d)\0A\00"
@.str.1 = [28 x i8] c"Retornando fatorial(1) = 1\0A\00"
@.str.2 = [30 x i8] c"Retornando fatorial(%d) = %d\0A\00"
define i32 @fatorial(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %21
11: ; preds = %1
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 1
%14 = call i32 @fatorial(i32 %13)
%15 = load i32, i32* %3
%16 = mul nsw i32 %14, %15
store i32 %16, i32* %4
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %21
21: ; preds = %11, %9
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [24 x i8] c"Entrei em fatorial(%d)\0A\00"
@.str.2 = [30 x i8] c"Retornando fatorial(%d) = %d\0A\00"
@str = [27 x i8] c"Retornando fatorial(1) = 1\00"
define i32 @fatorial(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %4, %8
%7 = phi i32 [ %11, %8 ], [ 1, %4 ]
ret i32 %7
8: ; preds = %1
%9 = add nsw i32 %0, -1
%10 = tail call i32 @fatorial(i32 %9)
%11 = mul nsw i32 %10, %0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %11)
br label %6
}