#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*/ isprime(unsigned long);
unsigned long int nextprime(unsigned long int n) {
  unsigned long int next, residue;
  next = n + 1;
  residue = next % 6;
  while (residue != 1 && residue != 5) {
    next++;
    residue = next % 6;
  }
  while (!isprime(next)) {
    residue = next % 6;
    if (residue == 1)
      next += 4;
    else
      next += 2;
  }
  return next;
}


x86 assembly (clang, -O0):
<nextprime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x6,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x1,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     1155 <nextprime+0x45>
cmpq   $0x5,-0x18(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1165 <nextprime+0x55>
jmp    1188 <nextprime+0x78>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x6,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x18(%rbp)
jmp    113a <nextprime+0x2a>
jmp    118d <nextprime+0x7d>
mov    -0x10(%rbp),%rdi
call   1030 <isprime@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ab <nextprime+0x9b>
jmp    11ea <nextprime+0xda>
mov    -0x10(%rbp),%rax
mov    $0x6,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jne    11d9 <nextprime+0xc9>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    11e5 <nextprime+0xd5>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    118d <nextprime+0x7d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nextprime>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x1(%rdi),%rcx
movabs $0xaaaaaaaaaaaaaaab,%r14
aa aa aa
nopl   0x0(%rax)
mov    %rbx,%rsi
mov    %rcx,%rax
mul    %r14
shr    $0x2,%rdx
add    %edx,%edx
lea    (%rdx,%rdx,2),%eax
add    $0x1,%rbx
sub    %eax,%esi
add    $0x1,%esi
and    $0x3,%esi
add    $0x1,%rcx
cmp    $0x1,%esi
jne    1130 <nextprime+0x20>
mov    %rbx,%rdi
call   1030 <isprime@plt>
test   %eax,%eax
jne    11a9 <nextprime+0x99>
movabs $0x5555555555555555,%r15
55 55 55
movabs $0x2aaaaaaaaaaaaaab,%r12
aa aa 2a
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rax
imul   %r14,%rax
add    %r15,%rax
ror    %rax
xor    %ecx,%ecx
cmp    %r12,%rax
setb   %cl
lea    (%rbx,%rcx,2),%rbx
add    $0x2,%rbx
mov    %rbx,%rdi
call   1030 <isprime@plt>
test   %eax,%eax
je     1180 <nextprime+0x70>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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