#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 sqrt(int);
int slow_prime(int n) {
  int 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    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1131 <slow_prime+0x21>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <slow_prime+0xc5>
cmpl   $0x1,-0x8(%rbp)
jne    1147 <slow_prime+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <slow_prime+0xc5>
cmpl   $0x2,-0x8(%rbp)
jne    115d <slow_prime+0x4d>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <slow_prime+0xc5>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117d <slow_prime+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <slow_prime+0xc5>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jg     11ce <slow_prime+0xbe>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11bb <slow_prime+0xab>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <slow_prime+0xc5>
jmp    11c0 <slow_prime+0xb0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1184 <slow_prime+0x74>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slow_prime>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cmp    $0x3,%edi
jae    1129 <slow_prime+0x19>
movslq %ebx,%rax
lea    0xedc(%rip),%rcx
mov    (%rcx,%rax,4),%eax
jmp    116c <slow_prime+0x5c>
test   $0x1,%bl
jne    1132 <slow_prime+0x22>
xor    %eax,%eax
jmp    116c <slow_prime+0x5c>
mov    %ebx,%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x2,%ecx
jl     116c <slow_prime+0x5c>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     112e <slow_prime+0x1e>
mov    %ebx,%edi
call   1030 <sqrt@plt>
cmp    %eax,%ebp
jl     1150 <slow_prime+0x40>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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