#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 INT_MAX;
int factorielle_recursive(int n) {
  int num;
  if (n <= 0)
    return 1;
  else {
    num = factorielle_recursive(n - 1);
    if (num == -1 || INT_MAX / n < num)
      return -1;
    else
      return n * num;
  }
}


x86 assembly (clang, -O0):
<factorielle_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1131 <factorielle_recursive+0x21>
movl   $0x1,-0x4(%rbp)
jmp    1175 <factorielle_recursive+0x65>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1030 <factorielle_recursive@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     115f <factorielle_recursive+0x4f>
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
cltd
idivl  -0x8(%rbp)
cmp    -0xc(%rbp),%eax
jge    116b <factorielle_recursive+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1175 <factorielle_recursive+0x65>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorielle_recursive>:
push   %rbx
test   %edi,%edi
jle    1141 <factorielle_recursive+0x31>
mov    %edi,%ebx
lea    -0x1(%rbx),%edi
call   1030 <factorielle_recursive@plt>
cmp    $0xffffffff,%eax
je     1148 <factorielle_recursive+0x38>
mov    %eax,%ecx
mov    0x2ebb(%rip),%rax
mov    (%rax),%eax
cltd
idiv   %ebx
imul   %ecx,%ebx
cmp    %ecx,%eax
mov    $0xffffffff,%eax
cmovge %ebx,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@INT_MAX = global i32 0
define i32 @factorielle_recursive(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = add nsw i32 %0, -1
%5 = tail call i32 @factorielle_recursive(i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = load i32, i32* @INT_MAX
%9 = sdiv i32 %8, %0
%10 = icmp slt i32 %9, %5
%11 = mul nsw i32 %5, %0
%12 = select i1 %10, i32 -1, i32 %11
br label %13
13: ; preds = %7, %3, %1
%14 = phi i32 [ 1, %1 ], [ -1, %3 ], [ %12, %7 ]
ret i32 %14
}