#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__ sqrt(double);
unsigned long int NearestPrime(unsigned int n) {
  int p;
  int i;
  for (p = n;; p++) {
    for (i = 2; i <= (int)sqrt((double)p) && p % i != 0; i++)
      ;
    if (p % i != 0) {
      break;
    }
  }
  return p;
}


x86 assembly (clang, -O0):
<NearestPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
call   1030 <sqrt@plt>
mov    -0x14(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0xd(%rbp)
jg     115a <NearestPrime+0x4a>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    116a <NearestPrime+0x5a>
jmp    117d <NearestPrime+0x6d>
jmp    116f <NearestPrime+0x5f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1128 <NearestPrime+0x18>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
je     1192 <NearestPrime+0x82>
jmp    11a5 <NearestPrime+0x95>
jmp    1197 <NearestPrime+0x87>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1121 <NearestPrime+0x11>
movslq -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NearestPrime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
jmp    1130 <NearestPrime+0x20>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%ebp
mov    %r14d,%eax
cltd
idiv   %ebp
lea    0x1(%r14),%edi
test   %edx,%edx
jne    1180 <NearestPrime+0x70>
mov    %edi,%r14d
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <sqrt@plt>
mov    $0x2,%ebp
cmp    $0x2,%eax
jl     1122 <NearestPrime+0x12>
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14d,%eax
cltd
idiv   %ebx
test   %edx,%edx
je     1120 <NearestPrime+0x10>
lea    0x1(%rbx),%ebp
movsd  0x8(%rsp),%xmm0
call   1030 <sqrt@plt>
cmp    %eax,%ebx
mov    %ebp,%ebx
jl     1160 <NearestPrime+0x50>
jmp    1122 <NearestPrime+0x12>
movslq %r14d,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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