#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 ceil(int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(int);
int nextprime(int n) {
  int i, div, ceilsqrt = 0;
  int retval = 0;
  for (;; n++) {
    ceilsqrt = ceil(sqrt(n));
    for (i = 2; i <= ceilsqrt; i++) {
      div = n / i;
      if (div * i == n) {
        retval = n;
        break;
      }
    }
    if (retval) {
      break;
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<nextprime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %eax,-0x10(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1196 <nextprime+0x76>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    1183 <nextprime+0x63>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1196 <nextprime+0x76>
jmp    1188 <nextprime+0x68>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1152 <nextprime+0x32>
cmpl   $0x0,-0x14(%rbp)
je     11a5 <nextprime+0x85>
jmp    11b8 <nextprime+0x98>
jmp    11aa <nextprime+0x8a>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1139 <nextprime+0x19>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nextprime>:
push   %rbx
mov    %edi,%ebx
jmp    1137 <nextprime+0x17>
cs nopw 0x0(%rax,%rax,1)
nop
test   %ebx,%ebx
jne    117d <nextprime+0x5d>
add    $0x1,%ebx
mov    %ebx,%edi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
cmp    $0x2,%eax
jl     1134 <nextprime+0x14>
mov    %eax,%ecx
neg    %ecx
mov    $0x2,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
cltd
idiv   %esi
test   %edx,%edx
je     1130 <nextprime+0x10>
lea    (%rcx,%rsi,1),%eax
add    $0x1,%eax
mov    %esi,%edx
add    $0x1,%edx
mov    %edx,%esi
cmp    $0x1,%eax
jne    1160 <nextprime+0x40>
jmp    1134 <nextprime+0x14>
mov    %ebx,%eax
pop    %rbx
ret

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

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