#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*/ ft_putendl(char *);
int ft_int_fact(int n) {
  int i;
  int res;
  res = 1;
  i = 1;
  if (n > 16) {
    ft_putendl("ERROR: Result is over the INT_MAX limit");
    return (-1);
  }
  while (i <= n)
    res *= i++;
  return (res);
}


x86 assembly (clang, -O0):
<ft_int_fact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x10,-0x8(%rbp)
jle    114b <ft_int_fact+0x3b>
lea    0xec6(%rip),%rdi
call   1030 <ft_putendl@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1179 <ft_int_fact+0x69>
jmp    1150 <ft_int_fact+0x40>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1173 <ft_int_fact+0x63>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
imul   -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1150 <ft_int_fact+0x40>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_int_fact>:
push   %rax
cmp    $0x10,%edi
jle    1129 <ft_int_fact+0x19>
lea    0xf23(%rip),%rdi
call   1030 <ft_putendl@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    $0x1,%eax
test   %edi,%edi
jle    11aa <ft_int_fact+0x9a>
mov    $0x1,%ecx
cmp    $0x4,%edi
jb     119c <ft_int_fact+0x8c>
mov    %edi,%ecx
and    $0xfffffffc,%ecx
cmp    $0x4,%ecx
je     115a <ft_int_fact+0x4a>
cmp    $0x8,%ecx
je     1164 <ft_int_fact+0x54>
cmp    $0xc,%ecx
jne    116e <ft_int_fact+0x5e>
movdqa 0xeb8(%rip),%xmm0
jmp    1176 <ft_int_fact+0x66>
movdqa 0xe9e(%rip),%xmm0
jmp    1176 <ft_int_fact+0x66>
movdqa 0xeb4(%rip),%xmm0
jmp    1176 <ft_int_fact+0x66>
movdqa 0xeba(%rip),%xmm0
pshufd $0xee,%xmm0,%xmm1
pshufd $0xff,%xmm0,%xmm2
pshufd $0xf5,%xmm0,%xmm3
pmuludq %xmm2,%xmm3
pmuludq %xmm0,%xmm1
pmuludq %xmm3,%xmm1
movd   %xmm1,%eax
cmp    %edi,%ecx
je     11aa <ft_int_fact+0x9a>
or     $0x1,%ecx
add    $0x1,%edi
nop
imul   %ecx,%eax
add    $0x1,%ecx
cmp    %ecx,%edi
jne    11a0 <ft_int_fact+0x90>
pop    %rcx
ret

LLVM IR (-O0):
@.str = [40 x i8] c"ERROR: Result is over the INT_MAX limit\00"
define i32 @ft_int_fact(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
%6 = load i32, i32* %3
%7 = icmp sgt i32 %6, 16
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @ft_putendl(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %22
10: ; preds = %1
br label %11
11: ; preds = %15, %10
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
%18 = load i32, i32* %5
%19 = mul nsw i32 %18, %16
store i32 %19, i32* %5
br label %11
20: ; preds = %11
%21 = load i32, i32* %5
store i32 %21, i32* %2
br label %22
22: ; preds = %20, %8
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [40 x i8] c"ERROR: Result is over the INT_MAX limit\00"
define i32 @ft_int_fact(i32 %0) {
%2 = icmp sgt i32 %0, 16
br i1 %2, label %20, label %3
3: ; preds = %1
%4 = icmp slt i32 %0, 1
br i1 %4, label %28, label %5
5: ; preds = %3
%6 = icmp ult i32 %0, 4
br i1 %6, label %17, label %7
7: ; preds = %5
%8 = and i32 %0, -4
%9 = or i32 %8, 1
switch i32 %8, label %10 [
i32 4, label %13
i32 8, label %11
i32 12, label %12
]
10: ; preds = %7
br label %13
11: ; preds = %7
br label %13
12: ; preds = %7
br label %13
13: ; preds = %7, %12, %11, %10
%14 = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %7 ], [ <i32 585, i32 1680, i32 3465, i32 6144>, %10 ], [ <i32 5, i32 12, i32 21, i32 32>, %11 ], [ <i32 45, i32 120, i32 231, i32 384>, %12 ]
%15 = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %14)
%16 = icmp eq i32 %8, %0
br i1 %16, label %28, label %17
17: ; preds = %5, %13
%18 = phi i32 [ 1, %5 ], [ %15, %13 ]
%19 = phi i32 [ 1, %5 ], [ %9, %13 ]
br label %22
20: ; preds = %1
%21 = tail call i32 @ft_putendl(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %28
22: ; preds = %17, %22
%23 = phi i32 [ %26, %22 ], [ %18, %17 ]
%24 = phi i32 [ %25, %22 ], [ %19, %17 ]
%25 = add nuw i32 %24, 1
%26 = mul nsw i32 %23, %24
%27 = icmp eq i32 %24, %0
br i1 %27, label %28, label %22
28: ; preds = %22, %13, %3, %20
%29 = phi i32 [ -1, %20 ], [ 1, %3 ], [ %15, %13 ], [ %26, %22 ]
ret i32 %29
}