int ft_find_next_prime(int nb) {
  int current_div;
  int div_found;
  int max_div;
  if (nb < 3)
    return (2);
  current_div = 2;
  div_found = 0;
  max_div = nb / 2;
  while (div_found == 0 && current_div <= max_div) {
    if (nb % current_div == 0)
      div_found = 1;
    current_div++;
  }
  return (div_found == 0 ? nb : ft_find_next_prime(nb + 1));
}


x86 assembly (clang, -O0):
<ft_find_next_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1131 <ft_find_next_prime+0x21>
movl   $0x2,-0x4(%rbp)
jmp    11c6 <ft_find_next_prime+0xb6>
movl   $0x2,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x15(%rbp)
jne    1168 <ft_find_next_prime+0x58>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
setle  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1178 <ft_find_next_prime+0x68>
jmp    119d <ft_find_next_prime+0x8d>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    118f <ft_find_next_prime+0x7f>
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <ft_find_next_prime+0x3d>
cmpl   $0x0,-0x10(%rbp)
jne    11b2 <ft_find_next_prime+0xa2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11c0 <ft_find_next_prime+0xb0>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1030 <ft_find_next_prime@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_find_next_prime>:
mov    $0x2,%ecx
cmp    $0x3,%edi
jl     113e <ft_find_next_prime+0x3e>
mov    %edi,%ecx
je     113e <ft_find_next_prime+0x3e>
xchg   %ax,%ax
mov    %ecx,%esi
shr    %esi
mov    $0x2,%edi
nopl   0x0(%rax)
mov    %ecx,%eax
cltd
idiv   %edi
test   %edx,%edx
je     1132 <ft_find_next_prime+0x32>
lea    0x1(%rdi),%eax
cmp    %esi,%edi
mov    %eax,%edi
jb     1120 <ft_find_next_prime+0x20>
test   %edx,%edx
jne    113e <ft_find_next_prime+0x3e>
add    $0x1,%ecx
cmp    $0x3,%ecx
ja     1110 <ft_find_next_prime+0x10>
mov    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @ft_find_next_prime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 2, i32* %2
br label %42
10: ; preds = %1
store i32 2, i32* %4
store i32 0, i32* %5
%11 = load i32, i32* %3
%12 = sdiv i32 %11, 2
store i32 %12, i32* %6
br label %13
13: ; preds = %28, %10
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* %4
%18 = load i32, i32* %6
%19 = icmp sle i32 %17, %18
br label %20
20: ; preds = %16, %13
%21 = phi i1 [ false, %13 ], [ %19, %16 ]
br i1 %21, label %22, label %31
22: ; preds = %20
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = srem i32 %23, %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 1, i32* %5
br label %28
28: ; preds = %27, %22
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %13
31: ; preds = %20
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = load i32, i32* %3
br label %40
36: ; preds = %31
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
%39 = call i32 @ft_find_next_prime(i32 %38)
br label %40
40: ; preds = %36, %34
%41 = phi i32 [ %35, %34 ], [ %39, %36 ]
store i32 %41, i32* %2
br label %42
42: ; preds = %40, %9
%43 = load i32, i32* %2
ret i32 %43
}

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