int ft_recursive_factorial(int nb) {
  int a;
  a = 1;
  if (nb == 0) {
    return (1);
  }
  if (nb < 0 || nb > 12) {
    return (0);
  }
  if (nb > 0 && nb <= 12) {
    a = nb * ft_recursive_factorial(nb - 1);
    return (a);
  }
  return (0);
}


x86 assembly (clang, -O0):
<ft_recursive_factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1138 <ft_recursive_factorial+0x28>
movl   $0x1,-0x4(%rbp)
jmp    119a <ft_recursive_factorial+0x8a>
cmpl   $0x0,-0x8(%rbp)
jl     114c <ft_recursive_factorial+0x3c>
cmpl   $0xc,-0x8(%rbp)
jle    1158 <ft_recursive_factorial+0x48>
movl   $0x0,-0x4(%rbp)
jmp    119a <ft_recursive_factorial+0x8a>
cmpl   $0x0,-0x8(%rbp)
jle    1193 <ft_recursive_factorial+0x83>
cmpl   $0xc,-0x8(%rbp)
jg     1193 <ft_recursive_factorial+0x83>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1030 <ft_recursive_factorial@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119a <ft_recursive_factorial+0x8a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_recursive_factorial>:
mov    $0x1,%eax
test   %edi,%edi
je     1129 <ft_recursive_factorial+0x29>
mov    %edi,%ecx
nopl   0x0(%rax,%rax,1)
cmp    $0xc,%edi
ja     1124 <ft_recursive_factorial+0x24>
imul   %ecx,%eax
add    $0xffffffff,%ecx
jne    1110 <ft_recursive_factorial+0x10>
mov    $0x1,%ecx
jmp    1126 <ft_recursive_factorial+0x26>
xor    %ecx,%ecx
imul   %ecx,%eax
ret

LLVM IR (-O0):
define i32 @ft_recursive_factorial(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %4
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %2
br label %29
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 12
br i1 %13, label %14, label %15
14: ; preds = %11, %8
store i32 0, i32* %2
br label %29
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32, i32* %3
%20 = icmp sle i32 %19, 12
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %3
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 1
%25 = call i32 @ft_recursive_factorial(i32 %24)
%26 = mul nsw i32 %22, %25
store i32 %26, i32* %4
%27 = load i32, i32* %4
store i32 %27, i32* %2
br label %29
28: ; preds = %18, %15
store i32 0, i32* %2
br label %29
29: ; preds = %28, %21, %14, %7
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @ft_recursive_factorial(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = icmp ugt i32 %0, 12
br label %5
5: ; preds = %3, %8
%6 = phi i32 [ %9, %8 ], [ %0, %3 ]
%7 = phi i32 [ %10, %8 ], [ 1, %3 ]
br i1 %4, label %12, label %8
8: ; preds = %5
%9 = add nsw i32 %6, -1
%10 = mul nsw i32 %6, %7
%11 = icmp eq i32 %9, 0
br i1 %11, label %12, label %5
12: ; preds = %5, %8
%13 = phi i32 [ %10, %8 ], [ %7, %5 ]
%14 = phi i32 [ 1, %8 ], [ 0, %5 ]
%15 = mul nuw nsw i32 %14, %13
br label %16
16: ; preds = %12, %1
%17 = phi i32 [ %15, %12 ], [ 1, %1 ]
ret i32 %17
}