#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 */
unsigned long sqrt(double);
unsigned long _findPrime(unsigned long start, int dir) {
  static int unit[] = {0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0};
  unsigned long t;
  while (start > 1) {
    if (!unit[start & 0x0f]) {
      start += dir;
      continue;
    }
    for (t = 2; t < sqrt((double)start); t++) {
      if (!start % t)
        break;
    }
    if (t >= sqrt((double)start)) {
      break;
    }
    start += dir;
  }
  return start;
}


x86 assembly (clang, -O0):
<_findPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x1,-0x8(%rbp)
jbe    1238 <_findPrime+0x128>
mov    -0x8(%rbp),%rcx
and    $0xf,%rcx
lea    0x2ef7(%rip),%rax
cmpl   $0x0,(%rax,%rcx,4)
jne    1154 <_findPrime+0x44>
movslq -0xc(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    111f <_findPrime+0xf>
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movaps 0xe95(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe94(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jae    11de <_findPrime+0xce>
cmpq   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cltq
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
je     11c8 <_findPrime+0xb8>
jmp    11de <_findPrime+0xce>
jmp    11cd <_findPrime+0xbd>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115c <_findPrime+0x4c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movaps 0xe13(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe12(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jb     1227 <_findPrime+0x117>
jmp    1238 <_findPrime+0x128>
movslq -0xc(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    111f <_findPrime+0xf>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_findPrime>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
cmp    $0x2,%rdi
jb     11a0 <_findPrime+0x90>
movslq %esi,%r14
mov    $0xd575,%r15d
jmp    1139 <_findPrime+0x29>
xchg   %ax,%ax
add    %r14,%rbx
cmp    $0x1,%rbx
jbe    11a0 <_findPrime+0x90>
mov    %ebx,%eax
and    $0xf,%al
movzbl %al,%eax
bt     %eax,%r15d
jb     1130 <_findPrime+0x20>
movq   %rbx,%xmm0
punpckldq 0xead(%rip),%xmm0
subpd  0xeb5(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movaps (%rsp),%xmm0
call   1030 <sqrt@plt>
add    $0x1,%rbp
cmp    %rax,%rbp
jb     1180 <_findPrime+0x70>
movaps (%rsp),%xmm0
call   1030 <sqrt@plt>
cmp    %rax,%rbp
jb     1130 <_findPrime+0x20>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_findPrime.unit = internal global [16 x i32] [i32 0, i32 1, i32 0, i32 1, i32 0, i32 0, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 0]
define i64 @_findPrime(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
store i64 %0, i64* %3
store i32 %1, i32* %4
br label %6
6: ; preds = %48, %15, %2
%7 = load i64, i64* %3
%8 = icmp ugt i64 %7, 1
br i1 %8, label %9, label %53
9: ; preds = %6
%10 = load i64, i64* %3
%11 = and i64 %10, 15
%12 = getelementptr inbounds [16 x i32], [16 x i32]* @_findPrime.unit, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %9
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = load i64, i64* %3
%19 = add i64 %18, %17
store i64 %19, i64* %3
br label %6
20: ; preds = %9
store i64 2, i64* %5
br label %21
21: ; preds = %38, %20
%22 = load i64, i64* %5
%23 = load i64, i64* %3
%24 = uitofp i64 %23 to double
%25 = call i64 @sqrt(double %24)
%26 = icmp ult i64 %22, %25
br i1 %26, label %27, label %41
27: ; preds = %21
%28 = load i64, i64* %3
%29 = icmp ne i64 %28, 0
%30 = xor i1 %29, true
%31 = zext i1 %30 to i32
%32 = sext i32 %31 to i64
%33 = load i64, i64* %5
%34 = urem i64 %32, %33
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %27
br label %41
37: ; preds = %27
br label %38
38: ; preds = %37
%39 = load i64, i64* %5
%40 = add i64 %39, 1
store i64 %40, i64* %5
br label %21
41: ; preds = %36, %21
%42 = load i64, i64* %5
%43 = load i64, i64* %3
%44 = uitofp i64 %43 to double
%45 = call i64 @sqrt(double %44)
%46 = icmp uge i64 %42, %45
br i1 %46, label %47, label %48
47: ; preds = %41
br label %53
48: ; preds = %41
%49 = load i32, i32* %4
%50 = sext i32 %49 to i64
%51 = load i64, i64* %3
%52 = add i64 %51, %50
store i64 %52, i64* %3
br label %6
53: ; preds = %47, %6
%54 = load i64, i64* %3
ret i64 %54
}

LLVM IR (-O2):
define i64 @_findPrime(i64 %0, i32 %1) {
%3 = icmp ugt i64 %0, 1
br i1 %3, label %4, label %25
4: ; preds = %2
%5 = sext i32 %1 to i64
br label %6
6: ; preds = %4, %14
%7 = phi i64 [ %0, %4 ], [ %15, %14 ]
%8 = and i64 %7, 15
%9 = lshr i64 54645, %8
%10 = and i64 %9, 1
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = uitofp i64 %7 to double
br label %17
14: ; preds = %22, %6
%15 = add i64 %7, %5
%16 = icmp ugt i64 %15, 1
br i1 %16, label %6, label %25
17: ; preds = %17, %12
%18 = phi i64 [ %21, %17 ], [ 2, %12 ]
%19 = tail call i64 @sqrt(double %13)
%20 = icmp ult i64 %18, %19
%21 = add nuw i64 %18, 1
br i1 %20, label %17, label %22
22: ; preds = %17
%23 = tail call i64 @sqrt(double %13)
%24 = icmp ult i64 %18, %23
br i1 %24, label %14, label %25
25: ; preds = %14, %22, %2
%26 = phi i64 [ %0, %2 ], [ %7, %22 ], [ %15, %14 ]
ret i64 %26
}