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


x86 assembly (clang, -O0):
<ft_iterative_factorial>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1129 <ft_iterative_factorial+0x29>
cmpl   $0xc,-0x8(%rbp)
jle    1135 <ft_iterative_factorial+0x35>
movl   $0x0,-0x4(%rbp)
jmp    1164 <ft_iterative_factorial+0x64>
jmp    113a <ft_iterative_factorial+0x3a>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     115e <ft_iterative_factorial+0x5e>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <ft_iterative_factorial+0x3a>
mov    -0x10(%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     11b9 <ft_iterative_factorial+0xb9>
test   %edi,%edi
je     1142 <ft_iterative_factorial+0x42>
lea    0x3(%rdi),%eax
and    $0xfffffffc,%eax
add    $0xffffffff,%edi
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
cmp    $0x4,%eax
je     1148 <ft_iterative_factorial+0x48>
cmp    $0x8,%eax
jne    115c <ft_iterative_factorial+0x5c>
movdqa 0xeed(%rip),%xmm1
movdqa 0xec5(%rip),%xmm2
mov    $0x4,%eax
jmp    1171 <ft_iterative_factorial+0x71>
mov    $0x1,%eax
ret
movdqa 0xeb0(%rip),%xmm1
movdqa 0xeb8(%rip),%xmm2
xor    %eax,%eax
jmp    1171 <ft_iterative_factorial+0x71>
movdqa 0xecc(%rip),%xmm1
movdqa 0xeb4(%rip),%xmm2
mov    $0x8,%eax
movd   %eax,%xmm3
pshufd $0x0,%xmm3,%xmm3
pxor   0xebe(%rip),%xmm0
por    0xec6(%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
store i32 1, i32* %4
store i32 1, i32* %5
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 12
br i1 %10, label %11, label %12
11: ; preds = %8, %1
store i32 0, i32* %2
br label %25
12: ; preds = %8
br label %13
13: ; preds = %17, %12
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = mul nsw i32 %19, %18
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %13
23: ; preds = %13
%24 = load i32, i32* %5
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %11
%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 eq i32 %0, 0
br i1 %4, label %23, label %5
5: ; preds = %3
%6 = add i32 %0, 3
%7 = and i32 %6, -4
%8 = add i32 %0, -1
%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 5, i32 12, i32 21, i32 32>, %11 ], [ <i32 1, i32 2, i32 3, i32 4>, %12 ]
%16 = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %5 ], [ <i32 45, i32 120, i32 231, i32 384>, %11 ], [ <i32 5, i32 12, i32 21, i32 32>, %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
}