#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 /*<<< orphan*/ assert(int);
int floor(scalar_t__);
scalar_t__ sqrt(int);
int is_prime(int x) {
  int i, m;
  assert(x >= 0);
  if (x == 1)
    return 0;
  m = floor(sqrt(x) + 0.5);
  for (i = 2; i <= m; i++)
    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   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1162 <is_prime+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <is_prime+0xa1>
mov    -0x8(%rbp),%edi
call   1040 <sqrt@plt>
cvtsi2sd %rax,%xmm0
movsd  0xe89(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1050 <floor@plt>
mov    %eax,-0x10(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11ca <is_prime+0x9a>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11b7 <is_prime+0x87>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <is_prime+0xa1>
jmp    11bc <is_prime+0x8c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118f <is_prime+0x5f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_prime>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
xor    %ebx,%ebx
cmp    $0x1,%ebp
je     11a0 <is_prime+0x70>
mov    %ebp,%edi
call   1040 <sqrt@plt>
cvtsi2sd %rax,%xmm0
addsd  0xea6(%rip),%xmm0
cvttsd2si %xmm0,%rdi
call   1050 <floor@plt>
cmp    $0x2,%eax
jl     119b <is_prime+0x6b>
mov    %eax,%ecx
neg    %ecx
mov    $0x2,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%eax
cltd
idiv   %esi
test   %edx,%edx
je     11a0 <is_prime+0x70>
lea    (%rcx,%rsi,1),%eax
add    $0x1,%eax
mov    %esi,%edx
add    $0x1,%edx
mov    %edx,%esi
cmp    $0x1,%eax
jne    1180 <is_prime+0x50>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @is_prime(i32 %0) {
%2 = xor i32 %0, -1
%3 = lshr i32 %2, 31
%4 = tail call i32 @assert(i32 %3)
%5 = icmp eq i32 %0, 1
br i1 %5, label %20, label %6
6: ; preds = %1
%7 = tail call i64 @sqrt(i32 %0)
%8 = sitofp i64 %7 to double
%9 = fadd double %8, 5.000000e-01
%10 = fptosi double %9 to i64
%11 = tail call i32 @floor(i64 %10)
%12 = icmp slt i32 %11, 2
br i1 %12, label %20, label %16
13: ; preds = %16
%14 = add nuw i32 %17, 1
%15 = icmp eq i32 %17, %11
br i1 %15, label %20, label %16
16: ; preds = %6, %13
%17 = phi i32 [ %14, %13 ], [ 2, %6 ]
%18 = srem i32 %0, %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %13
20: ; preds = %16, %13, %6, %1
%21 = phi i32 [ 0, %1 ], [ 1, %6 ], [ 0, %16 ], [ 1, %13 ]
ret i32 %21
}