#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 sqrtl(unsigned long);
int IsPrime(unsigned long n) {
  int i;
  if (n == 2 || n == 1)
    return 0;
  if (n % 2 == 0)
    return 0;
  for (i = 3; i <= sqrtl(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)
cmpq   $0x2,-0x10(%rbp)
je     1132 <IsPrime+0x22>
cmpq   $0x1,-0x10(%rbp)
jne    113e <IsPrime+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11bc <IsPrime+0xac>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    115c <IsPrime+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    11bc <IsPrime+0xac>
movl   $0x3,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sqrtl@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jg     11b5 <IsPrime+0xa5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    11a2 <IsPrime+0x92>
movl   $0x0,-0x4(%rbp)
jmp    11bc <IsPrime+0xac>
jmp    11a7 <IsPrime+0x97>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1163 <IsPrime+0x53>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IsPrime>:
push   %rbp
push   %r14
push   %rbx
lea    -0x1(%rdi),%rax
xor    %r14d,%r14d
cmp    $0x2,%rax
jb     1190 <IsPrime+0x80>
mov    %rdi,%rbx
mov    %ebx,%eax
and    $0x1,%eax
test   %rax,%rax
je     1190 <IsPrime+0x80>
mov    %rbx,%rdi
call   1030 <sqrtl@plt>
mov    $0x1,%r14d
cmp    $0x3,%eax
jl     1190 <IsPrime+0x80>
mov    $0x3,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rax
or     %rbp,%rax
shr    $0x20,%rax
je     1170 <IsPrime+0x60>
mov    %rbx,%rax
xor    %edx,%edx
div    %rbp
test   %rdx,%rdx
jne    117b <IsPrime+0x6b>
jmp    118d <IsPrime+0x7d>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
test   %rdx,%rdx
je     118d <IsPrime+0x7d>
add    $0x2,%rbp
mov    %rbx,%rdi
call   1030 <sqrtl@plt>
cmp    %ebp,%eax
jge    1150 <IsPrime+0x40>
jmp    1190 <IsPrime+0x80>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @IsPrime(i64 %0) {
%2 = add i64 %0, -1
%3 = icmp ult i64 %2, 2
%4 = and i64 %0, 1
%5 = icmp eq i64 %4, 0
%6 = or i1 %3, %5
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = tail call i32 @sqrtl(i64 %0)
%9 = icmp slt i32 %8, 3
br i1 %9, label %19, label %14
10: ; preds = %14
%11 = tail call i32 @sqrtl(i64 %0)
%12 = trunc i64 %18 to i32
%13 = icmp slt i32 %11, %12
br i1 %13, label %19, label %14
14: ; preds = %7, %10
%15 = phi i64 [ %18, %10 ], [ 3, %7 ]
%16 = urem i64 %0, %15
%17 = icmp eq i64 %16, 0
%18 = add nuw i64 %15, 2
br i1 %17, label %19, label %10
19: ; preds = %14, %10, %7, %1
%20 = phi i32 [ 0, %1 ], [ 1, %7 ], [ 0, %14 ], [ 1, %10 ]
ret i32 %20
}