#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 sqrt(int);
int nextPrime(int n) {
  int i, root, keepGoing = 1;
  if (n % 2 == 0)
    ++n;
  while (keepGoing) {
    keepGoing = 0;
    root = sqrt(n);
    for (i = 3; i <= root; i++) {
      if (n % i == 0) {
        n += 2;
        keepGoing = 1;
        break;
      }
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<nextPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    113f <nextPrime+0x2f>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1144 <nextPrime+0x34>
cmpl   $0x0,-0x10(%rbp)
je     11b0 <nextPrime+0xa0>
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,-0xc(%rbp)
movl   $0x3,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11ab <nextPrime+0x9b>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    1198 <nextPrime+0x88>
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    11ab <nextPrime+0x9b>
jmp    119d <nextPrime+0x8d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1167 <nextPrime+0x57>
jmp    1144 <nextPrime+0x34>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nextPrime>:
push   %rbx
mov    %edi,%ebx
not    %ebx
and    $0x1,%ebx
add    %edi,%ebx
mov    %ebx,%edi
call   1030 <sqrt@plt>
cmp    $0x3,%eax
jge    112a <nextPrime+0x1a>
mov    %ebx,%eax
pop    %rbx
ret
mov    %eax,%ecx
neg    %ecx
mov    $0x3,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
cltd
idiv   %esi
test   %edx,%edx
je     1160 <nextPrime+0x50>
lea    (%rcx,%rsi,1),%eax
add    $0x1,%eax
mov    %esi,%edx
add    $0x1,%edx
mov    %edx,%esi
cmp    $0x1,%eax
jne    1140 <nextPrime+0x30>
jmp    1126 <nextPrime+0x16>
nopl   (%rax)
add    $0x2,%ebx
mov    %ebx,%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
cmp    $0x2,%eax
jg     112c <nextPrime+0x1c>
jmp    1126 <nextPrime+0x16>

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

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