#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_iteractive(int n) {
  int i, p = 1;
  for (i = 1; i <= n; ++i) {
    if (INT_MAX / n < p)
      return -1;
    p *= i;
  }
  return p;
}


x86 assembly (clang, -O0):
<factorielle_iteractive>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     115b <factorielle_iteractive+0x5b>
mov    0x2ec0(%rip),%rax
mov    (%rax),%eax
cltd
idivl  -0x8(%rbp)
cmp    -0x10(%rbp),%eax
jge    1143 <factorielle_iteractive+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    1161 <factorielle_iteractive+0x61>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1115 <factorielle_iteractive+0x15>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorielle_iteractive>:
test   %edi,%edi
jle    1136 <factorielle_iteractive+0x36>
mov    0x2edd(%rip),%rax
mov    (%rax),%eax
cltd
idiv   %edi
mov    %eax,%ecx
neg    %edi
mov    $0x1,%eax
mov    $0x1,%edx
xchg   %ax,%ax
cmp    %eax,%ecx
jl     113c <factorielle_iteractive+0x3c>
imul   %edx,%eax
lea    (%rdi,%rdx,1),%esi
add    $0x1,%esi
add    $0x1,%edx
cmp    $0x1,%esi
jne    1120 <factorielle_iteractive+0x20>
ret
mov    $0x1,%eax
ret
mov    $0xffffffff,%eax
ret

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

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