#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 ceil(int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(unsigned long);
short int isPrime(unsigned long int n) {
  long int i;
  if (n % 2 == 0)
    return 0;
  for (i = 3; i < ceil(sqrt(n)); i += 2) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<isPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    1149 <isPrime+0x29>
movw   $0x0,-0x2(%rbp)
jmp    11b6 <isPrime+0x96>
movq   $0x3,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jge    11b0 <isPrime+0x90>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
jne    119a <isPrime+0x7a>
movw   $0x0,-0x2(%rbp)
jmp    11b6 <isPrime+0x96>
jmp    119f <isPrime+0x7f>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <isPrime+0x31>
movw   $0x1,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isPrime>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
test   $0x1,%bl
jne    1131 <isPrime+0x11>
xor    %r14d,%r14d
jmp    1193 <isPrime+0x73>
mov    %rbx,%rdi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    $0x1,%r14w
cmp    $0x4,%rax
jl     1193 <isPrime+0x73>
mov    $0x3,%ebp
mov    %rbx,%rax
or     %rbp,%rax
shr    $0x20,%rax
je     1170 <isPrime+0x50>
mov    %rbx,%rax
xor    %edx,%edx
div    %rbp
test   %rdx,%rdx
jne    117b <isPrime+0x5b>
jmp    112c <isPrime+0xc>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
test   %rdx,%rdx
je     112c <isPrime+0xc>
add    $0x2,%rbp
mov    %rbx,%rdi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
cmp    %rax,%rbp
jl     1150 <isPrime+0x30>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i16 @isPrime(i64 %0) {
%2 = alloca i16
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = urem i64 %5, 2
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i16 0, i16* %2
br label %27
9: ; preds = %1
store i64 3, i64* %4
br label %10
10: ; preds = %23, %9
%11 = load i64, i64* %4
%12 = load i64, i64* %3
%13 = call i32 @sqrt(i64 %12)
%14 = call i64 @ceil(i32 %13)
%15 = icmp slt i64 %11, %14
br i1 %15, label %16, label %26
16: ; preds = %10
%17 = load i64, i64* %3
%18 = load i64, i64* %4
%19 = urem i64 %17, %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i16 0, i16* %2
br label %27
22: ; preds = %16
br label %23
23: ; preds = %22
%24 = load i64, i64* %4
%25 = add nsw i64 %24, 2
store i64 %25, i64* %4
br label %10
26: ; preds = %10
store i16 1, i16* %2
br label %27
27: ; preds = %26, %21, %8
%28 = load i16, i16* %2
ret i16 %28
}

LLVM IR (-O2):
define signext i16 @isPrime(i64 %0) {
%2 = and i64 %0, 1
%3 = icmp eq i64 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i32 @sqrt(i64 %0)
%6 = tail call i64 @ceil(i32 %5)
%7 = icmp sgt i64 %6, 3
br i1 %7, label %12, label %17
8: ; preds = %12
%9 = tail call i32 @sqrt(i64 %0)
%10 = tail call i64 @ceil(i32 %9)
%11 = icmp slt i64 %16, %10
br i1 %11, label %12, label %17
12: ; preds = %4, %8
%13 = phi i64 [ %16, %8 ], [ 3, %4 ]
%14 = urem i64 %0, %13
%15 = icmp eq i64 %14, 0
%16 = add nuw nsw i64 %13, 2
br i1 %15, label %17, label %8
17: ; preds = %12, %8, %4, %1
%18 = phi i16 [ 0, %1 ], [ 1, %4 ], [ 0, %12 ], [ 1, %8 ]
ret i16 %18
}