#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 floor(int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(double);
int is_prime(const int x) {
  if (x < 2) {
    return -1;
  }
  if (x < 4) {
    return 1;
  }
  if ((x % 2) == 0) {
    return 0;
  }
  for (int i = 3; i <= floor(sqrt((double)x)); i += 2) {
    if ((x % i) == 0) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1141 <is_prime+0x21>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <is_prime+0xb8>
cmpl   $0x4,-0x8(%rbp)
jge    1157 <is_prime+0x37>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <is_prime+0xb8>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1177 <is_prime+0x57>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <is_prime+0xb8>
movl   $0x3,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
call   1030 <sqrt@plt>
mov    %eax,%edi
call   1040 <floor@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jg     11d1 <is_prime+0xb1>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11be <is_prime+0x9e>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <is_prime+0xb8>
jmp    11c3 <is_prime+0xa3>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    117e <is_prime+0x5e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_prime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%eax
cmp    $0x2,%edi
jl     119c <is_prime+0x7c>
mov    %edi,%r14d
mov    $0x1,%eax
cmp    $0x4,%edi
jb     119c <is_prime+0x7c>
xor    %eax,%eax
test   $0x1,%r14b
je     119c <is_prime+0x7c>
cvtsi2sd %r14d,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <sqrt@plt>
mov    %eax,%edi
call   1040 <floor@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x3,%ecx
jl     119c <is_prime+0x7c>
mov    $0x3,%ebx
nop
mov    %r14d,%eax
cltd
idiv   %ebx
mov    %edx,%ebp
test   %edx,%edx
je     1195 <is_prime+0x75>
add    $0x2,%ebx
movsd  0x8(%rsp),%xmm0
call   1030 <sqrt@plt>
mov    %eax,%edi
call   1040 <floor@plt>
cmp    %eax,%ebx
jle    1170 <is_prime+0x50>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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