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


x86 assembly (clang, -O0):
<ft_iterative_factorial>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    112b <ft_iterative_factorial+0x2b>
movl   $0x1,-0x4(%rbp)
jmp    119a <ft_iterative_factorial+0x9a>
cmpl   $0x0,-0x8(%rbp)
jle    1173 <ft_iterative_factorial+0x73>
cmpl   $0xc,-0x8(%rbp)
jg     1173 <ft_iterative_factorial+0x73>
jmp    1144 <ft_iterative_factorial+0x44>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1168 <ft_iterative_factorial+0x68>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <ft_iterative_factorial+0x44>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119a <ft_iterative_factorial+0x9a>
cmpl   $0x0,-0x8(%rbp)
jl     1187 <ft_iterative_factorial+0x87>
cmpl   $0xc,-0x8(%rbp)
jle    1193 <ft_iterative_factorial+0x93>
movl   $0x0,-0x4(%rbp)
jmp    119a <ft_iterative_factorial+0x9a>
movl   $0x0,-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>
lea    -0x1(%rdi),%ecx
xor    %eax,%eax
cmp    $0xb,%ecx
ja     11b9 <ft_iterative_factorial+0xb9>
add    $0x3,%edi
and    $0xfffffffc,%edi
movd   %ecx,%xmm0
pshufd $0x0,%xmm0,%xmm0
cmp    $0x4,%edi
je     1148 <ft_iterative_factorial+0x48>
cmp    $0x8,%edi
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* %5
store i32 1, i32* %4
%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 %36
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = load i32, i32* %3
%14 = icmp sle i32 %13, 12
br i1 %14, label %15, label %28
15: ; preds = %12
br label %16
16: ; preds = %20, %15
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = mul nsw i32 %21, %22
store i32 %23, i32* %5
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %16
26: ; preds = %16
%27 = load i32, i32* %5
store i32 %27, i32* %2
br label %36
28: ; preds = %12, %9
%29 = load i32, i32* %3
%30 = icmp slt i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* %3
%33 = icmp sgt i32 %32, 12
br i1 %33, label %34, label %35
34: ; preds = %31, %28
store i32 0, i32* %2
br label %36
35: ; preds = %31
store i32 0, i32* %2
br label %36
36: ; preds = %35, %34, %26, %8
%37 = load i32, i32* %2
ret i32 %37
}

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