#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 */
scalar_t__ sqrt(long);
int prime(long n) {
  if (n < 2L) {
    return 0;
  }
  if (n & 1) {
    long lim = (long)sqrt(n);
    for (long div = 3L; div <= lim; ++div) {
      if ((n % div) == 0) {
        return 0;
      }
    }
    return 1;
  }
  return n == 2L;
}


x86 assembly (clang, -O0):
<prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x2,-0x10(%rbp)
jge    1133 <prime+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11ba <prime+0xaa>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11aa <prime+0x9a>
mov    -0x10(%rbp),%rdi
call   1030 <sqrt@plt>
mov    %rax,-0x18(%rbp)
movq   $0x3,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     119e <prime+0x8e>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x20(%rbp)
cmp    $0x0,%rdx
jne    1188 <prime+0x78>
movl   $0x0,-0x4(%rbp)
jmp    11ba <prime+0xaa>
jmp    118d <prime+0x7d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115a <prime+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    11ba <prime+0xaa>
cmpq   $0x2,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime>:
push   %rbx
cmp    $0x2,%rdi
jge    111e <prime+0xe>
xor    %eax,%eax
jmp    11b6 <prime+0xa6>
mov    %rdi,%rbx
test   $0x1,%bl
jne    1132 <prime+0x22>
cmp    $0x2,%rbx
sete   %al
jmp    11b6 <prime+0xa6>
mov    %rbx,%rdi
call   1030 <sqrt@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x3,%rcx
jl     11b6 <prime+0xa6>
movabs $0xaaaaaaaaaaaaaaab,%rax
aa aa aa
imul   %rbx,%rax
movabs $0x2aaaaaaaaaaaaaaa,%rdx
aa aa 2a
add    %rax,%rdx
movabs $0x5555555555555555,%rax
55 55 55
cmp    %rax,%rdx
jb     1117 <prime+0x7>
mov    $0x3,%edi
jmp    118b <prime+0x7b>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %edi
test   %rdx,%rdx
je     11b0 <prime+0xa0>
mov    %rdi,%rsi
cmp    %rdi,%rcx
je     11b0 <prime+0xa0>
lea    0x1(%rsi),%rdi
mov    %rbx,%rax
or     %rdi,%rax
shr    $0x20,%rax
je     1180 <prime+0x70>
mov    %rbx,%rax
cqto
idiv   %rdi
test   %rdx,%rdx
jne    118b <prime+0x7b>
cmp    %rcx,%rsi
setge  %al
movzbl %al,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @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 %35
9: ; preds = %1
%10 = load i64, i64* %3
%11 = and i64 %10, 1
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = load i64, i64* %3
%15 = call i64 @sqrt(i64 %14)
store i64 %15, i64* %4
store i64 3, i64* %5
br label %16
16: ; preds = %27, %13
%17 = load i64, i64* %5
%18 = load i64, i64* %4
%19 = icmp sle i64 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i64, i64* %3
%22 = load i64, i64* %5
%23 = srem i64 %21, %22
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 0, i32* %2
br label %35
26: ; preds = %20
br label %27
27: ; preds = %26
%28 = load i64, i64* %5
%29 = add nsw i64 %28, 1
store i64 %29, i64* %5
br label %16
30: ; preds = %16
store i32 1, i32* %2
br label %35
31: ; preds = %9
%32 = load i64, i64* %3
%33 = icmp eq i64 %32, 2
%34 = zext i1 %33 to i32
store i32 %34, i32* %2
br label %35
35: ; preds = %31, %30, %25, %8
%36 = load i32, i32* %2
ret i32 %36
}

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