#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 *, char);
long long sqrt(long long);
int findPrime(long long int num) {
  int i = 3;
  int ch = 0;
  long long int lim = 0;
  if (num < 10)
    ch = !(num % 2) + !(num % 3);
  else if (num % 2 == 0)
    ch = 1;
  else {
    lim = sqrt(num);
    while (i <= lim && ch == 0) {
      ch = (num % i == 0) ? 1 : 0;
      i += 2;
    }
  }
  printf("\nIs it prime? %c", (!ch) ? 'Y' : 'N');
  return !ch;
}


x86 assembly (clang, -O0):
<findPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0xa,-0x8(%rbp)
jge    1197 <findPrime+0x77>
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    -0x1c(%rbp),%eax
cmp    $0x0,%rdx
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    122b <findPrime+0x10b>
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11bb <findPrime+0x9b>
movl   $0x1,-0x10(%rbp)
jmp    1226 <findPrime+0x106>
mov    -0x8(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %rax,-0x18(%rbp)
movslq -0xc(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x1d(%rbp)
jg     11e5 <findPrime+0xc5>
cmpl   $0x0,-0x10(%rbp)
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11f5 <findPrime+0xd5>
jmp    1221 <findPrime+0x101>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    11c8 <findPrime+0xa8>
jmp    1226 <findPrime+0x106>
jmp    122b <findPrime+0x10b>
cmpl   $0x0,-0x10(%rbp)
setne  %dl
xor    $0xff,%dl
mov    $0x4e,%eax
mov    $0x59,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
lea    0xdb4(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findPrime>:
push   %rbx
mov    %rdi,%rbx
cmp    $0x9,%rdi
jg     115e <findPrime+0x3e>
mov    %ebx,%eax
not    %eax
and    $0x1,%eax
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
imul   %rbx,%rcx
movabs $0x2aaaaaaaaaaaaaaa,%rdx
aa aa 2a
add    %rcx,%rdx
movabs $0x5555555555555555,%rcx
55 55 55
cmp    %rcx,%rdx
adc    $0x0,%eax
jmp    11bc <findPrime+0x9c>
mov    $0x1,%eax
test   $0x1,%bl
je     11bc <findPrime+0x9c>
mov    %rbx,%rdi
call   1040 <sqrt@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x3,%rcx
jl     11bc <findPrime+0x9c>
mov    $0x3,%esi
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     11a0 <findPrime+0x80>
mov    %rbx,%rax
cqto
idiv   %rsi
jmp    11a6 <findPrime+0x86>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
add    $0x2,%rsi
cmp    %rsi,%rcx
jl     11b4 <findPrime+0x94>
test   %rdx,%rdx
jne    1180 <findPrime+0x60>
xor    %eax,%eax
test   %rdx,%rdx
sete   %al
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    $0x59,%eax
mov    $0x4e,%esi
cmove  %eax,%esi
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"\0AIs it prime? %c\00"
define i32 @findPrime(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i64 %0, i64* %2
store i32 3, i32* %3
store i32 0, i32* %4
store i64 0, i64* %5
%6 = load i64, i64* %2
%7 = icmp slt i64 %6, 10
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = load i64, i64* %2
%10 = srem i64 %9, 2
%11 = icmp ne i64 %10, 0
%12 = xor i1 %11, true
%13 = zext i1 %12 to i32
%14 = load i64, i64* %2
%15 = srem i64 %14, 3
%16 = icmp ne i64 %15, 0
%17 = xor i1 %16, true
%18 = zext i1 %17 to i32
%19 = add nsw i32 %13, %18
store i32 %19, i32* %4
br label %50
20: ; preds = %1
%21 = load i64, i64* %2
%22 = srem i64 %21, 2
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 1, i32* %4
br label %49
25: ; preds = %20
%26 = load i64, i64* %2
%27 = call i64 @sqrt(i64 %26)
store i64 %27, i64* %5
br label %28
28: ; preds = %38, %25
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = load i64, i64* %5
%32 = icmp sle i64 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 0
br label %36
36: ; preds = %33, %28
%37 = phi i1 [ false, %28 ], [ %35, %33 ]
br i1 %37, label %38, label %48
38: ; preds = %36
%39 = load i64, i64* %2
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = srem i64 %39, %41
%43 = icmp eq i64 %42, 0
%44 = zext i1 %43 to i64
%45 = select i1 %43, i32 1, i32 0
store i32 %45, i32* %4
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 2
store i32 %47, i32* %3
br label %28
48: ; preds = %36
br label %49
49: ; preds = %48, %24
br label %50
50: ; preds = %49, %8
%51 = load i32, i32* %4
%52 = icmp ne i32 %51, 0
%53 = xor i1 %52, true
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 89, i32 78
%56 = trunc i32 %55 to i8
%57 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %56)
%58 = load i32, i32* %4
%59 = icmp ne i32 %58, 0
%60 = xor i1 %59, true
%61 = zext i1 %60 to i32
ret i32 %61
}

LLVM IR (-O2):
@.str = [17 x i8] c"\0AIs it prime? %c\00"
define i32 @findPrime(i64 %0) {
%2 = icmp slt i64 %0, 10
br i1 %2, label %3, label %11
3: ; preds = %1
%4 = trunc i64 %0 to i32
%5 = and i32 %4, 1
%6 = xor i32 %5, 1
%7 = srem i64 %0, 3
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
%10 = add nuw nsw i32 %6, %9
br label %27
11: ; preds = %1
%12 = and i64 %0, 1
%13 = icmp eq i64 %12, 0
br i1 %13, label %27, label %14
14: ; preds = %11
%15 = tail call i64 @sqrt(i64 %0)
%16 = icmp sgt i64 %15, 2
br i1 %16, label %17, label %27
17: ; preds = %14, %17
%18 = phi i64 [ %21, %17 ], [ 3, %14 ]
%19 = srem i64 %0, %18
%20 = icmp eq i64 %19, 0
%21 = add nuw i64 %18, 2
%22 = icmp sge i64 %15, %21
%23 = xor i1 %20, true
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %17, label %25
25: ; preds = %17
%26 = zext i1 %20 to i32
br label %27
27: ; preds = %25, %14, %11, %3
%28 = phi i32 [ %10, %3 ], [ 1, %11 ], [ 0, %14 ], [ %26, %25 ]
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i8 89, i8 78
%31 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8 signext %30)
%32 = zext i1 %29 to i32
ret i32 %32
}