int ft_iterative_factorial(int nb) {
  int out;
  int i;
  if (nb > 12)
    return (0);
  if (nb < 0)
    return (0);
  out = 1;
  i = 1;
  while (i++ < nb)
    out *= i;
  return (out);
}


x86 assembly (clang, -O0):
<ft_iterative_factorial>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0xc,-0x8(%rbp)
jle    111d <ft_iterative_factorial+0x1d>
movl   $0x0,-0x4(%rbp)
jmp    116a <ft_iterative_factorial+0x6a>
cmpl   $0x0,-0x8(%rbp)
jge    1133 <ft_iterative_factorial+0x33>
movl   $0x0,-0x4(%rbp)
jmp    116a <ft_iterative_factorial+0x6a>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
cmp    -0x8(%rbp),%eax
jge    1164 <ft_iterative_factorial+0x64>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <ft_iterative_factorial+0x41>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_iterative_factorial>:
xor    %eax,%eax
cmp    $0xc,%edi
ja     11bd <ft_iterative_factorial+0xbd>
mov    $0x1,%eax
cmp    $0x2,%edi
jb     11bd <ft_iterative_factorial+0xbd>
lea    0x2(%rdi),%eax
and    $0xfffffffc,%eax
add    $0xfffffffe,%edi
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
cmp    $0x4,%eax
je     114c <ft_iterative_factorial+0x4c>
cmp    $0x8,%eax
jne    1160 <ft_iterative_factorial+0x60>
movdqa 0xee3(%rip),%xmm1
movdqa 0xebb(%rip),%xmm2
mov    $0x4,%eax
jmp    1175 <ft_iterative_factorial+0x75>
movdqa 0xeac(%rip),%xmm1
movdqa 0xeb4(%rip),%xmm2
xor    %eax,%eax
jmp    1175 <ft_iterative_factorial+0x75>
movdqa 0xec8(%rip),%xmm1
movdqa 0xeb0(%rip),%xmm2
mov    $0x8,%eax
movd   %eax,%xmm3
pshufd $0x0,%xmm3,%xmm3
pxor   0xeba(%rip),%xmm0
por    0xec2(%rip),%xmm3
pcmpgtd %xmm0,%xmm3
pand   %xmm3,%xmm2
pandn  %xmm1,%xmm3
por    %xmm2,%xmm3
pshufd $0xee,%xmm3,%xmm0
pshufd $0xff,%xmm3,%xmm1
pshufd $0xf5,%xmm3,%xmm2
pmuludq %xmm1,%xmm2
pmuludq %xmm3,%xmm0
pmuludq %xmm2,%xmm0
movd   %xmm0,%eax
ret

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

LLVM IR (-O2):
define i32 @ft_iterative_factorial(i32 %0) {
%2 = icmp ugt i32 %0, 12
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = icmp ugt i32 %0, 1
br i1 %4, label %5, label %23
5: ; preds = %3
%6 = add i32 %0, 2
%7 = and i32 %6, -4
%8 = add i32 %0, -2
%9 = insertelement <4 x i32> poison, i32 %8, i64 0
%10 = shufflevector <4 x i32> %9, <4 x i32> poison, <4 x i32> zeroinitializer
switch i32 %7, label %11 [
i32 4, label %13
i32 8, label %12
]
11: ; preds = %5
br label %13
12: ; preds = %5
br label %13
13: ; preds = %5, %12, %11
%14 = phi i32 [ 0, %5 ], [ 8, %11 ], [ 4, %12 ]
%15 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %5 ], [ <i32 12, i32 21, i32 32, i32 45>, %11 ], [ <i32 2, i32 3, i32 4, i32 5>, %12 ]
%16 = phi <4 x i32> [ <i32 2, i32 3, i32 4, i32 5>, %5 ], [ <i32 120, i32 231, i32 384, i32 585>, %11 ], [ <i32 12, i32 21, i32 32, i32 45>, %12 ]
%17 = insertelement <4 x i32> poison, i32 %14, i64 0
%18 = shufflevector <4 x i32> %17, <4 x i32> poison, <4 x i32> zeroinitializer
%19 = or <4 x i32> %18, <i32 0, i32 1, i32 2, i32 3>
%20 = icmp ugt <4 x i32> %19, %10
%21 = select <4 x i1> %20, <4 x i32> %15, <4 x i32> %16
%22 = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %21)
br label %23
23: ; preds = %13, %3, %1
%24 = phi i32 [ 0, %1 ], [ 1, %3 ], [ %22, %13 ]
ret i32 %24
}