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


x86 assembly (clang, -O0):
<is_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x2,-0x10(%rbp)
jge    1143 <is_prime+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <is_prime+0xc7>
cmpq   $0x4,-0x10(%rbp)
jge    115a <is_prime+0x3a>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <is_prime+0xc7>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    117e <is_prime+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <is_prime+0xc7>
cvtsi2sdq -0x10(%rbp),%xmm0
call   1030 <sqrt@plt>
mov    %eax,%edi
call   1040 <floor@plt>
mov    %rax,-0x18(%rbp)
movq   $0x3,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11e0 <is_prime+0xc0>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x20(%rbp)
cmp    $0x0,%rdx
jne    11ca <is_prime+0xaa>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <is_prime+0xc7>
jmp    11cf <is_prime+0xaf>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    119c <is_prime+0x7c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_prime>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%rdi
jge    112d <is_prime+0xd>
xor    %ebp,%ebp
jmp    113b <is_prime+0x1b>
mov    %rdi,%rbx
mov    $0x1,%ebp
cmp    $0x4,%rdi
jae    1144 <is_prime+0x24>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
test   $0x1,%bl
je     1129 <is_prime+0x9>
cvtsi2sd %rbx,%xmm0
call   1030 <sqrt@plt>
mov    %eax,%edi
call   1040 <floor@plt>
cmp    $0x4,%rax
jl     113b <is_prime+0x1b>
mov    %rax,%rcx
movabs $0xaaaaaaaaaaaaaaab,%rax
aa aa aa
imul   %rbx,%rax
movabs $0x2aaaaaaaaaaaaaaa,%rdx
aa aa 2a
add    %rax,%rdx
movabs $0x5555555555555555,%rax
55 55 55
mov    $0x0,%ebp
cmp    %rax,%rdx
jb     113b <is_prime+0x1b>
mov    $0x4,%eax
jmp    11af <is_prime+0x8f>
nopl   0x0(%rax)
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
lea    0x1(%rsi),%rax
test   %rdx,%rdx
je     11cd <is_prime+0xad>
mov    %rax,%rsi
cmp    %rax,%rcx
je     11cd <is_prime+0xad>
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     11a0 <is_prime+0x80>
mov    %rbx,%rax
cqto
idiv   %rsi
jmp    11a6 <is_prime+0x86>
xor    %ebp,%ebp
cmp    %rcx,%rsi
setge  %bpl
jmp    113b <is_prime+0x1b>

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

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