#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 /*<<< orphan*/ printf(char *, unsigned long);
unsigned long sqrt(unsigned long);
int pf(unsigned long x, unsigned int q) {
  if (x > 3)
    if (x % 2 == 0 || x % 3 == 0)
      return 0;
  for (unsigned long i = 4; i <= sqrt(x); i++)
    if (x % i == 0)
      return 0;
  if (q)
    printf("%lu is a prime number!\n", x);
  return 1;
}


x86 assembly (clang, -O0):
<pf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x3,-0x10(%rbp)
jbe    1175 <pf+0x55>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1164 <pf+0x44>
mov    -0x10(%rbp),%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    1170 <pf+0x50>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <pf+0xd7>
jmp    1175 <pf+0x55>
movq   $0x4,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
ja     11d6 <pf+0xb6>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
cmp    $0x0,%rdx
jne    11c0 <pf+0xa0>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <pf+0xd7>
jmp    11c5 <pf+0xa5>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117d <pf+0x5d>
cmpl   $0x0,-0x14(%rbp)
je     11f0 <pf+0xd0>
mov    -0x10(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pf>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
cmp    $0x4,%rdi
jb     115a <pf+0x3a>
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mov    %rbx,%rax
mul    %rcx
xor    %ebp,%ebp
test   $0x1,%bl
je     11c9 <pf+0xa9>
shr    %rdx
lea    (%rdx,%rdx,2),%rax
mov    %rbx,%rcx
sub    %rax,%rcx
je     11c9 <pf+0xa9>
mov    %rbx,%rdi
call   1040 <sqrt@plt>
cmp    $0x4,%rax
jb     11ac <pf+0x8c>
mov    $0x4,%ebp
nopl   (%rax)
mov    %rbx,%rax
or     %rbp,%rax
shr    $0x20,%rax
je     1190 <pf+0x70>
mov    %rbx,%rax
xor    %edx,%edx
div    %rbp
test   %rdx,%rdx
jne    119b <pf+0x7b>
jmp    11c7 <pf+0xa7>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
test   %rdx,%rdx
je     11c7 <pf+0xa7>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <sqrt@plt>
cmp    %rax,%rbp
jbe    1170 <pf+0x50>
mov    $0x1,%ebp
test   %r14d,%r14d
je     11c9 <pf+0xa9>
lea    0xe43(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
jmp    11c9 <pf+0xa9>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"%lu is a prime number!\0A\00"
define i32 @pf(i64 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
store i64 %0, i64* %4
store i32 %1, i32* %5
%7 = load i64, i64* %4
%8 = icmp ugt i64 %7, 3
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = load i64, i64* %4
%11 = urem i64 %10, 2
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i64, i64* %4
%15 = urem i64 %14, 3
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13, %9
store i32 0, i32* %3
br label %42
18: ; preds = %13
br label %19
19: ; preds = %18, %2
store i64 4, i64* %6
br label %20
20: ; preds = %32, %19
%21 = load i64, i64* %6
%22 = load i64, i64* %4
%23 = call i64 @sqrt(i64 %22)
%24 = icmp ule i64 %21, %23
br i1 %24, label %25, label %35
25: ; preds = %20
%26 = load i64, i64* %4
%27 = load i64, i64* %6
%28 = urem i64 %26, %27
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 0, i32* %3
br label %42
31: ; preds = %25
br label %32
32: ; preds = %31
%33 = load i64, i64* %6
%34 = add i64 %33, 1
store i64 %34, i64* %6
br label %20
35: ; preds = %20
%36 = load i32, i32* %5
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i64, i64* %4
%40 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %39)
br label %41
41: ; preds = %38, %35
store i32 1, i32* %3
br label %42
42: ; preds = %41, %30, %17
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [24 x i8] c"%lu is a prime number!\0A\00"
define i32 @pf(i64 %0, i32 %1) {
%3 = icmp ugt i64 %0, 3
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = and i64 %0, 1
%6 = icmp eq i64 %5, 0
%7 = urem i64 %0, 3
%8 = icmp eq i64 %7, 0
%9 = or i1 %6, %8
br i1 %9, label %25, label %10
10: ; preds = %4, %2
%11 = tail call i64 @sqrt(i64 %0)
%12 = icmp ult i64 %11, 4
br i1 %12, label %21, label %16
13: ; preds = %16
%14 = tail call i64 @sqrt(i64 %0)
%15 = icmp ugt i64 %20, %14
br i1 %15, label %21, label %16
16: ; preds = %10, %13
%17 = phi i64 [ %20, %13 ], [ 4, %10 ]
%18 = urem i64 %0, %17
%19 = icmp eq i64 %18, 0
%20 = add i64 %17, 1
br i1 %19, label %25, label %13
21: ; preds = %13, %10
%22 = icmp eq i32 %1, 0
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %0)
br label %25
25: ; preds = %16, %21, %23, %4
%26 = phi i32 [ 0, %4 ], [ 1, %23 ], [ 1, %21 ], [ 0, %16 ]
ret i32 %26
}