#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 */
typedef int uint32_t;

/* Variables and functions */
double sqrt(int);
uint32_t next_prime(uint32_t const a) {
  for (uint32_t x = a;; x++) {
    if (x % 2 == 0)
      continue;
    bool is_prime = true;
    double const limit = sqrt(x);
    for (uint32_t i = 3; i <= limit; i += 2) {
      if (x % i == 0) {
        is_prime = false;
        break;
      }
    }
    if (is_prime)
      return x;
  }
}


x86 assembly (clang, -O0):
<next_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    113a <next_prime+0x2a>
jmp    11b0 <next_prime+0xa0>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x3,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1198 <next_prime+0x88>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
cmp    $0x0,%edx
jne    1185 <next_prime+0x75>
movl   $0x0,-0xc(%rbp)
jmp    1198 <next_prime+0x88>
jmp    118a <next_prime+0x7a>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <next_prime+0x45>
cmpl   $0x0,-0xc(%rbp)
je     11ab <next_prime+0x9b>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    11b0 <next_prime+0xa0>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1121 <next_prime+0x11>

x86 assembly (clang, -O2):
<next_prime>:
push   %rbx
mov    %edi,%ebx
jmp    1123 <next_prime+0x13>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
test   $0x1,%bl
je     1120 <next_prime+0x10>
mov    %ebx,%edi
call   1030 <sqrt@plt>
ucomisd 0xec9(%rip),%xmm0
jb     1159 <next_prime+0x49>
mov    $0x3,%ecx
xchg   %ax,%ax
mov    %ebx,%eax
cltd
idiv   %ecx
test   %edx,%edx
je     1120 <next_prime+0x10>
add    $0x2,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
ucomisd %xmm1,%xmm0
jae    1140 <next_prime+0x30>
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @next_prime(i32 %0) {
br label %2
2: ; preds = %17, %1
%3 = phi i32 [ %0, %1 ], [ %18, %17 ]
%4 = and i32 %3, 1
%5 = icmp eq i32 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = tail call double @sqrt(i32 %3)
%8 = fcmp ult double %7, 3.000000e+00
br i1 %8, label %19, label %12
9: ; preds = %12
%10 = sitofp i32 %16 to double
%11 = fcmp ult double %7, %10
br i1 %11, label %19, label %12
12: ; preds = %6, %9
%13 = phi i32 [ %16, %9 ], [ 3, %6 ]
%14 = srem i32 %3, %13
%15 = icmp eq i32 %14, 0
%16 = add nuw nsw i32 %13, 2
br i1 %15, label %17, label %9
17: ; preds = %12, %2
%18 = add nsw i32 %3, 1
br label %2
19: ; preds = %6, %9
ret i32 %3
}