#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 */
int /*<<< orphan*/ is_prime(size_t);
size_t next_prime(size_t x) {
  switch (x) {
  case 0:
  case 1:
  case 2:
    return 2;
  case 3:
    return 3;
  case 4:
  case 5:
    return 5;
  }
  size_t k = x / 6;
  size_t i = x - 6 * k;
  size_t o = i < 2 ? 1 : 5;
  x = 6 * k + o;
  for (i = (3 + o) / 2; !is_prime(x); x += i)
    i ^= 6;
  return x;
}


x86 assembly (clang, -O0):
<next_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
sub    $0x3,%rax
jb     115d <next_prime+0x4d>
jmp    1133 <next_prime+0x23>
mov    -0x30(%rbp),%rax
sub    $0x3,%rax
je     116a <next_prime+0x5a>
jmp    1146 <next_prime+0x36>
mov    -0x30(%rbp),%rax
add    $0xfffffffffffffffc,%rax
sub    $0x2,%rax
jb     1177 <next_prime+0x67>
jmp    1184 <next_prime+0x74>
movq   $0x2,-0x8(%rbp)
jmp    1221 <next_prime+0x111>
movq   $0x3,-0x8(%rbp)
jmp    1221 <next_prime+0x111>
movq   $0x5,-0x8(%rbp)
jmp    1221 <next_prime+0x111>
mov    -0x10(%rbp),%rax
mov    $0x6,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x6,-0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    $0x5,%eax
mov    $0x1,%ecx
cmp    $0x2,%rdx
cmovb  %ecx,%eax
cltq
mov    %rax,-0x28(%rbp)
imul   $0x6,-0x18(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
add    $0x3,%rax
shr    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <is_prime@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11fc <next_prime+0xec>
jmp    1219 <next_prime+0x109>
mov    -0x20(%rbp),%rax
xor    $0x6,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11de <next_prime+0xce>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_prime>:
push   %r14
push   %rbx
push   %rax
cmp    $0x6,%rdi
jae    1127 <next_prime+0x17>
lea    0xedf(%rip),%rax
mov    (%rax,%rdi,8),%r14
jmp    1193 <next_prime+0x83>
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mov    %rdi,%rax
mul    %rcx
shr    %rdx
and    $0xfffffffffffffffe,%rdx
lea    (%rdx,%rdx,2),%rax
sub    %rax,%rdi
xor    %ebx,%ebx
cmp    $0x2,%rdi
setae  %bl
lea    (%rax,%rbx,4),%r14
add    $0x1,%r14
mov    %r14,%rdi
call   1030 <is_prime@plt>
test   %eax,%eax
jne    1193 <next_prime+0x83>
lea    0x1(,%rbx,4),%rbx
add    $0x3,%rbx
shr    %rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    $0x6,%rbx
add    %rbx,%r14
mov    %r14,%rdi
call   1030 <is_prime@plt>
test   %eax,%eax
je     1180 <next_prime+0x70>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @next_prime(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
%7 = load i64, i64* %3
switch i64 %7, label %11 [
i64 0, label %8
i64 1, label %8
i64 2, label %8
i64 3, label %9
i64 4, label %10
i64 5, label %10
]
8: ; preds = %1, %1, %1
store i64 2, i64* %2
br label %44
9: ; preds = %1
store i64 3, i64* %2
br label %44
10: ; preds = %1, %1
store i64 5, i64* %2
br label %44
11: ; preds = %1
%12 = load i64, i64* %3
%13 = udiv i64 %12, 6
store i64 %13, i64* %4
%14 = load i64, i64* %3
%15 = load i64, i64* %4
%16 = mul i64 6, %15
%17 = sub i64 %14, %16
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = icmp ult i64 %18, 2
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 1, i32 5
%22 = sext i32 %21 to i64
store i64 %22, i64* %6
%23 = load i64, i64* %4
%24 = mul i64 6, %23
%25 = load i64, i64* %6
%26 = add i64 %24, %25
store i64 %26, i64* %3
%27 = load i64, i64* %6
%28 = add i64 3, %27
%29 = udiv i64 %28, 2
store i64 %29, i64* %5
br label %30
30: ; preds = %38, %11
%31 = load i64, i64* %3
%32 = call i32 @is_prime(i64 %31)
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
br i1 %34, label %35, label %42
35: ; preds = %30
%36 = load i64, i64* %5
%37 = xor i64 %36, 6
store i64 %37, i64* %5
br label %38
38: ; preds = %35
%39 = load i64, i64* %5
%40 = load i64, i64* %3
%41 = add i64 %40, %39
store i64 %41, i64* %3
br label %30
42: ; preds = %30
%43 = load i64, i64* %3
store i64 %43, i64* %2
br label %44
44: ; preds = %42, %10, %9, %8
%45 = load i64, i64* %2
ret i64 %45
}

LLVM IR (-O2):
@switch.table.next_prime = [6 x i64] [i64 2, i64 2, i64 2, i64 3, i64 5, i64 5]
define i64 @next_prime(i64 %0) {
%2 = icmp ult i64 %0, 6
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = urem i64 %0, 6
%5 = sub nuw i64 %0, %4
%6 = icmp ugt i64 %4, 1
%7 = select i1 %6, i64 5, i64 1
%8 = add i64 %5, %7
%9 = tail call i32 @is_prime(i64 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %3
%12 = add nuw nsw i64 %7, 3
%13 = lshr exact i64 %12, 1
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ %17, %14 ], [ %13, %11 ]
%16 = phi i64 [ %18, %14 ], [ %8, %11 ]
%17 = xor i64 %15, 6
%18 = add i64 %17, %16
%19 = tail call i32 @is_prime(i64 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %14, label %24
21: ; preds = %1
%22 = getelementptr inbounds [6 x i64], [6 x i64]* @switch.table.next_prime, i64 0, i64 %0
%23 = load i64, i64* %22
br label %24
24: ; preds = %14, %21, %3
%25 = phi i64 [ %8, %3 ], [ %23, %21 ], [ %18, %14 ]
ret i64 %25
}