#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 sqrt(long);
long slow_prime(long n) {
  long i;
  if (n == 0) {
    return 0;
  }
  if (n == 1) {
    return 0;
  }
  if (n == 2) {
    return 1;
  }
  if (n % 2 == 0) {
    return 0;
  }
  for (i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<slow_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <slow_prime+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <slow_prime+0xe1>
cmpq   $0x1,-0x10(%rbp)
jne    114c <slow_prime+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <slow_prime+0xe1>
cmpq   $0x2,-0x10(%rbp)
jne    1164 <slow_prime+0x54>
movq   $0x1,-0x8(%rbp)
jmp    11f1 <slow_prime+0xe1>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1189 <slow_prime+0x79>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <slow_prime+0xe1>
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sqrt@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jg     11e9 <slow_prime+0xd9>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    11d3 <slow_prime+0xc3>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <slow_prime+0xe1>
jmp    11d8 <slow_prime+0xc8>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1191 <slow_prime+0x81>
movq   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slow_prime>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
cmp    $0x3,%rdi
jae    112b <slow_prime+0x1b>
lea    0xedb(%rip),%rax
mov    (%rax,%r15,8),%r14
jmp    119f <slow_prime+0x8f>
test   $0x1,%r15b
jne    1136 <slow_prime+0x26>
xor    %r14d,%r14d
jmp    119f <slow_prime+0x8f>
mov    %r15,%rdi
call   1030 <sqrt@plt>
mov    $0x1,%r14d
cmp    $0x2,%rax
jl     119f <slow_prime+0x8f>
mov    $0x1,%ebx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     1180 <slow_prime+0x70>
mov    %r15,%rax
cqto
idiv   %rbx
jmp    1187 <slow_prime+0x77>
nopw   0x0(%rax,%rax,1)
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
je     119f <slow_prime+0x8f>
mov    %r15,%rdi
call   1030 <sqrt@plt>
cmp    %rax,%rbx
jl     1160 <slow_prime+0x50>
mov    $0x1,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@switch.table.slow_prime = [3 x i64] [i64 0, i64 0, i64 1]
define i64 @slow_prime(i64 %0) {
%2 = icmp ult i64 %0, 3
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = and i64 %0, 1
%5 = icmp eq i64 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = tail call i64 @sqrt(i64 %0)
%8 = icmp slt i64 %7, 2
br i1 %8, label %20, label %13
9: ; preds = %13
%10 = add nuw nsw i64 %14, 1
%11 = tail call i64 @sqrt(i64 %0)
%12 = icmp slt i64 %14, %11
br i1 %12, label %13, label %20
13: ; preds = %6, %9
%14 = phi i64 [ %10, %9 ], [ 2, %6 ]
%15 = srem i64 %0, %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %9
17: ; preds = %1
%18 = getelementptr inbounds [3 x i64], [3 x i64]* @switch.table.slow_prime, i64 0, i64 %0
%19 = load i64, i64* %18
br label %20
20: ; preds = %13, %9, %17, %6, %3
%21 = phi i64 [ 0, %3 ], [ 1, %6 ], [ %19, %17 ], [ 0, %13 ], [ 1, %9 ]
ret i64 %21
}