int ft_find_next_prime(int nb) {
  int i;
  i = 2;
  if (nb < 2)
    return (2);
  while (i < nb) {
    if (nb % i == 0)
      return (ft_find_next_prime(nb + 1));
    i++;
  }
  return (nb);
}


x86 assembly (clang, -O0):
<ft_find_next_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1138 <ft_find_next_prime+0x28>
movl   $0x2,-0x4(%rbp)
jmp    1180 <ft_find_next_prime+0x70>
jmp    113d <ft_find_next_prime+0x2d>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    117a <ft_find_next_prime+0x6a>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    116c <ft_find_next_prime+0x5c>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1030 <ft_find_next_prime@plt>
mov    %eax,-0x4(%rbp)
jmp    1180 <ft_find_next_prime+0x70>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113d <ft_find_next_prime+0x2d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_find_next_prime>:
mov    $0x2,%ecx
cmp    $0x2,%edi
jge    110d <ft_find_next_prime+0xd>
mov    %ecx,%eax
ret
jne    1112 <ft_find_next_prime+0x12>
mov    %edi,%eax
ret
mov    %edi,%ecx
mov    $0x2,%esi
nopl   0x0(%rax)
mov    %ecx,%eax
cltd
idiv   %esi
test   %edx,%edx
je     1140 <ft_find_next_prime+0x40>
add    $0x1,%esi
cmp    %esi,%ecx
jne    1120 <ft_find_next_prime+0x20>
jmp    110a <ft_find_next_prime+0xa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ecx
cmp    $0x2,%edi
jne    1114 <ft_find_next_prime+0x14>
jmp    110a <ft_find_next_prime+0xa>

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

LLVM IR (-O2):
define i32 @ft_find_next_prime(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = icmp eq i32 %0, 2
br i1 %4, label %16, label %5
5: ; preds = %3, %14
%6 = phi i32 [ %15, %14 ], [ %0, %3 ]
br label %9
7: ; preds = %9
%8 = icmp eq i32 %13, %6
br i1 %8, label %16, label %9
9: ; preds = %5, %7
%10 = phi i32 [ %13, %7 ], [ 2, %5 ]
%11 = srem i32 %6, %10
%12 = icmp eq i32 %11, 0
%13 = add nuw nsw i32 %10, 1
br i1 %12, label %14, label %7
14: ; preds = %9
%15 = add nsw i32 %6, 1
br i1 %4, label %16, label %5
16: ; preds = %14, %7, %3, %1
%17 = phi i32 [ 2, %1 ], [ %0, %3 ], [ %6, %7 ], [ %15, %14 ]
ret i32 %17
}