#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__ is_prime(int);
int next_prime(int n) {
  if (n < 2) {
    return 2;
  } else if (n == 2) {
    return 3;
  } else if (0 == n % 2) {
    if (is_prime(n + 1)) {
      return n + 1;
    } else {
      return next_prime(n + 1);
    }
  } else {
    if (is_prime(2 + n)) {
      return 2 + n;
    } else {
      return next_prime(2 + n);
    }
  }
}


x86 assembly (clang, -O0):
<next_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1141 <next_prime+0x21>
movl   $0x2,-0x4(%rbp)
jmp    11d3 <next_prime+0xb3>
cmpl   $0x2,-0x8(%rbp)
jne    1157 <next_prime+0x37>
movl   $0x3,-0x4(%rbp)
jmp    11d3 <next_prime+0xb3>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
jne    11a2 <next_prime+0x82>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     118f <next_prime+0x6f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11d3 <next_prime+0xb3>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1030 <next_prime@plt>
mov    %eax,-0x4(%rbp)
jmp    11d3 <next_prime+0xb3>
mov    -0x8(%rbp),%edi
add    $0x2,%edi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     11c5 <next_prime+0xa5>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
jmp    11d3 <next_prime+0xb3>
mov    -0x8(%rbp),%edi
add    $0x2,%edi
call   1030 <next_prime@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_prime>:
push   %rbx
mov    $0x2,%ebx
cmp    $0x2,%edi
jl     1149 <next_prime+0x39>
je     1144 <next_prime+0x34>
mov    %edi,%ebx
nop
test   $0x1,%bl
jne    1130 <next_prime+0x20>
add    $0x1,%ebx
jmp    1133 <next_prime+0x23>
nopw   0x0(%rax,%rax,1)
add    $0x2,%ebx
mov    %ebx,%edi
call   1030 <is_prime@plt>
test   %rax,%rax
jne    1149 <next_prime+0x39>
cmp    $0x2,%ebx
jne    1120 <next_prime+0x10>
mov    $0x3,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

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