#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 */
double floor(double);
int next_prime(int x) {
  double i, j;
  int f;
  i = x;
  while (i++) {
    f = 1;
    for (j = 2; j < i; j++) {
      if ((i / j) == floor(i / j)) {
        f = 0;
        break;
      }
    }
    if (f) {
      return (int)i;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<next_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xece(%rip),%xmm2
movaps %xmm0,%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,-0x10(%rbp)
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1156 <next_prime+0x46>
jp     1156 <next_prime+0x46>
jmp    11f8 <next_prime+0xe8>
movl   $0x1,-0x1c(%rbp)
movsd  0xea3(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11dc <next_prime+0xcc>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jne    11c0 <next_prime+0xb0>
jp     11c0 <next_prime+0xb0>
movl   $0x0,-0x1c(%rbp)
jmp    11dc <next_prime+0xcc>
jmp    11c5 <next_prime+0xb5>
movsd  0xe33(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    116a <next_prime+0x5a>
cmpl   $0x0,-0x1c(%rbp)
je     11f3 <next_prime+0xe3>
cvttsd2si -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ff <next_prime+0xef>
jmp    1125 <next_prime+0x15>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_prime>:
push   %rbx
sub    $0x20,%rsp
mov    $0x1,%ebx
test   %edi,%edi
je     11e0 <next_prime+0xd0>
cvtsi2sd %edi,%xmm0
movsd  0xed2(%rip),%xmm1
movsd  0xed2(%rip),%xmm2
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jbe    11dc <next_prime+0xcc>
movsd  0xebc(%rip),%xmm1
movsd  %xmm0,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm1,0x10(%rsp)
divsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
call   1030 <floor@plt>
movsd  0x18(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    1183 <next_prime+0x73>
jnp    11b0 <next_prime+0xa0>
movsd  0xe75(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
ucomisd %xmm1,%xmm0
ja     1160 <next_prime+0x50>
jmp    11dc <next_prime+0xcc>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x8(%rsp),%xmm0
ucomisd 0xe52(%rip),%xmm0
movsd  0xe3a(%rip),%xmm1
movsd  0xe3a(%rip),%xmm2
jne    1136 <next_prime+0x26>
jp     1136 <next_prime+0x26>
jmp    11e0 <next_prime+0xd0>
cvttsd2si %xmm0,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @next_prime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = sitofp i32 %7 to double
store double %8, double* %4
br label %9
9: ; preds = %38, %1
%10 = load double, double* %4
%11 = fadd double %10, 1.000000e+00
store double %11, double* %4
%12 = fcmp une double %10, 0.000000e+00
br i1 %12, label %13, label %39
13: ; preds = %9
store i32 1, i32* %6
store double 2.000000e+00, double* %5
br label %14
14: ; preds = %29, %13
%15 = load double, double* %5
%16 = load double, double* %4
%17 = fcmp olt double %15, %16
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = load double, double* %4
%20 = load double, double* %5
%21 = fdiv double %19, %20
%22 = load double, double* %4
%23 = load double, double* %5
%24 = fdiv double %22, %23
%25 = call double @llvm.floor.f64(double %24)
%26 = fcmp oeq double %21, %25
br i1 %26, label %27, label %28
27: ; preds = %18
store i32 0, i32* %6
br label %32
28: ; preds = %18
br label %29
29: ; preds = %28
%30 = load double, double* %5
%31 = fadd double %30, 1.000000e+00
store double %31, double* %5
br label %14
32: ; preds = %27, %14
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load double, double* %4
%37 = fptosi double %36 to i32
store i32 %37, i32* %2
br label %40
38: ; preds = %32
br label %9
39: ; preds = %9
store i32 1, i32* %2
br label %40
40: ; preds = %39, %35
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @next_prime(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = sitofp i32 %0 to double
br label %7
5: ; preds = %11
%6 = fcmp une double %9, 0.000000e+00
br i1 %6, label %7, label %21
7: ; preds = %3, %5
%8 = phi double [ %9, %5 ], [ %4, %3 ]
%9 = fadd double %8, 1.000000e+00
%10 = fcmp ogt double %9, 2.000000e+00
br i1 %10, label %11, label %19
11: ; preds = %7, %16
%12 = phi double [ %17, %16 ], [ 2.000000e+00, %7 ]
%13 = fdiv double %9, %12
%14 = tail call double @llvm.floor.f64(double %13)
%15 = fcmp oeq double %13, %14
br i1 %15, label %5, label %16
16: ; preds = %11
%17 = fadd double %12, 1.000000e+00
%18 = fcmp olt double %17, %9
br i1 %18, label %11, label %19
19: ; preds = %7, %16
%20 = fptosi double %9 to i32
br label %21
21: ; preds = %5, %1, %19
%22 = phi i32 [ %20, %19 ], [ 1, %1 ], [ 1, %5 ]
ret i32 %22
}