#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ ft_isprime(int);
int ft_nextprime(int n) {
  int i;
  i = n + 1;
  while (!(ft_isprime(i)) && i < 2147483647)
    i++;
  if (ft_isprime(i))
    return (i);
  return (0);
}


x86 assembly (clang, -O0):
<ft_nextprime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <ft_isprime@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xd(%rbp)
jne    114b <ft_nextprime+0x3b>
cmpl   $0x7fffffff,-0xc(%rbp)
setl   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    115b <ft_nextprime+0x4b>
jmp    1169 <ft_nextprime+0x59>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1124 <ft_nextprime+0x14>
mov    -0xc(%rbp),%edi
call   1030 <ft_isprime@plt>
cmp    $0x0,%rax
je     1186 <ft_nextprime+0x76>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118d <ft_nextprime+0x7d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_nextprime>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rbx),%ebp
mov    %ebp,%edi
call   1030 <ft_isprime@plt>
test   %rax,%rax
jne    1139 <ft_nextprime+0x29>
cmp    $0x7ffffffe,%ebx
mov    %ebp,%ebx
jne    1120 <ft_nextprime+0x10>
mov    %ebp,%edi
call   1030 <ft_isprime@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmovne %ebp,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ft_nextprime(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ %0, %1 ], [ %4, %2 ]
%4 = add nsw i32 %3, 1
%5 = tail call i64 @ft_isprime(i32 %4)
%6 = icmp eq i64 %5, 0
%7 = icmp ne i32 %4, 2147483647
%8 = and i1 %6, %7
br i1 %8, label %2, label %9
9: ; preds = %2
%10 = tail call i64 @ft_isprime(i32 %4)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i32 0, i32 %4
ret i32 %12
}