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


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)
jne    112b <ft_iterative_factorial+0x2b>
movl   $0x1,-0x4(%rbp)
jmp    117f <ft_iterative_factorial+0x7f>
cmpl   $0x0,-0x8(%rbp)
jl     113f <ft_iterative_factorial+0x3f>
cmpl   $0xd,-0x8(%rbp)
jl     114b <ft_iterative_factorial+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    117f <ft_iterative_factorial+0x7f>
jmp    1150 <ft_iterative_factorial+0x50>
jmp    1155 <ft_iterative_factorial+0x55>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1179 <ft_iterative_factorial+0x79>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1155 <ft_iterative_factorial+0x55>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_iterative_factorial>:
test   %edi,%edi
je     1142 <ft_iterative_factorial+0x42>
xor    %eax,%eax
cmp    $0xc,%edi
ja     11b9 <ft_iterative_factorial+0xb9>
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 eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %2
br label %30
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* %3
%14 = icmp sge i32 %13, 13
br i1 %14, label %15, label %16
15: ; preds = %12, %9
store i32 0, i32* %2
br label %30
16: ; preds = %12
br label %17
17: ; preds = %16
br label %18
18: ; preds = %22, %17
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = mul nsw i32 %23, %24
store i32 %25, i32* %4
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %18
28: ; preds = %18
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %30
30: ; preds = %28, %15, %8
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @ft_iterative_factorial(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = icmp ugt i32 %0, 12
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 [ 1, %1 ], [ 0, %3 ], [ %22, %13 ]
ret i32 %24
}