#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
uint32_t findNextPrime(uint32_t *curPrime, uint32_t *searchLimit,
                       uint8_t *isComposite) {
  if (*curPrime < 3) {
    switch (*curPrime) {
    case 1:
      return 2;
    case 2:
      return 3;
    }
  }
  for (uint32_t i = *curPrime + 2; *curPrime < *searchLimit; i += 2)
    if (!isComposite[i])
      return i;
  return 0;
}


x86 assembly (clang, -O0):
<findNextPrime>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x3,(%rax)
jge    1162 <findNextPrime+0x62>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     1145 <findNextPrime+0x45>
jmp    1134 <findNextPrime+0x34>
mov    -0x28(%rbp),%eax
sub    $0x2,%eax
je     1151 <findNextPrime+0x51>
jmp    115d <findNextPrime+0x5d>
movl   $0x2,-0x4(%rbp)
jmp    11b7 <findNextPrime+0xb7>
movl   $0x3,-0x4(%rbp)
jmp    11b7 <findNextPrime+0xb7>
jmp    1162 <findNextPrime+0x62>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    11b0 <findNextPrime+0xb0>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    119d <findNextPrime+0x9d>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <findNextPrime+0xb7>
jmp    11a2 <findNextPrime+0xa2>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    116e <findNextPrime+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<findNextPrime>:
movslq (%rdi),%rcx
cmp    $0x2,%rcx
jg     1119 <findNextPrime+0x19>
cmp    $0x1,%ecx
je     113d <findNextPrime+0x3d>
cmp    $0x2,%ecx
jne    1119 <findNextPrime+0x19>
mov    $0x3,%eax
ret
xor    %eax,%eax
cmp    (%rsi),%ecx
jge    113c <findNextPrime+0x3c>
lea    (%rdx,%rcx,4),%rdx
add    $0x8,%rdx
mov    %ecx,%eax
nopl   0x0(%rax)
add    $0x2,%eax
cmpl   $0x0,(%rdx)
lea    0x8(%rdx),%rdx
jne    1130 <findNextPrime+0x30>
ret
mov    $0x2,%eax
ret

LLVM IR (-O0):
define i32 @findNextPrime(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32*, i32** %5
%14 = load i32, i32* %13
switch i32 %14, label %17 [
i32 1, label %15
i32 2, label %16
]
15: ; preds = %12
store i32 2, i32* %4
br label %42
16: ; preds = %12
store i32 3, i32* %4
br label %42
17: ; preds = %12
br label %18
18: ; preds = %17, %3
%19 = load i32*, i32** %5
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 2
store i32 %21, i32* %8
br label %22
22: ; preds = %38, %18
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = load i32*, i32** %6
%26 = load i32, i32* %25
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %41
28: ; preds = %22
%29 = load i32*, i32** %7
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %28
%36 = load i32, i32* %8
store i32 %36, i32* %4
br label %42
37: ; preds = %28
br label %38
38: ; preds = %37
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 2
store i32 %40, i32* %8
br label %22
41: ; preds = %22
store i32 0, i32* %4
br label %42
42: ; preds = %41, %35, %16, %15
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
define i32 @findNextPrime(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2) {
%4 = load i32, i32* %0
%5 = icmp slt i32 %4, 3
br i1 %5, label %6, label %8
6: ; preds = %3
switch i32 %4, label %8 [
i32 1, label %21
i32 2, label %7
]
7: ; preds = %6
br label %21
8: ; preds = %6, %3
%9 = load i32, i32* %1
%10 = icmp slt i32 %4, %9
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = sext i32 %4 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ %12, %11 ], [ %15, %13 ]
%15 = add i64 %14, 2
%16 = getelementptr inbounds i32, i32* %2, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %13
19: ; preds = %13
%20 = trunc i64 %15 to i32
br label %21
21: ; preds = %19, %8, %6, %7
%22 = phi i32 [ 3, %7 ], [ 2, %6 ], [ 0, %8 ], [ %20, %19 ]
ret i32 %22
}