#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; i < *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    11b4 <findNextPrime+0xb4>
movl   $0x3,-0x4(%rbp)
jmp    11b4 <findNextPrime+0xb4>
jmp    1162 <findNextPrime+0x62>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    11ad <findNextPrime+0xad>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    119a <findNextPrime+0x9a>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <findNextPrime+0xb4>
jmp    119f <findNextPrime+0x9f>
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),%rax
cmp    $0x2,%rax
jg     1119 <findNextPrime+0x19>
cmp    $0x1,%eax
je     1146 <findNextPrime+0x46>
cmp    $0x2,%eax
jne    1119 <findNextPrime+0x19>
mov    $0x3,%eax
ret
movslq (%rsi),%rcx
mov    %rax,%rsi
add    $0x2,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %rcx,%rsi
jge    1143 <findNextPrime+0x43>
add    $0x2,%eax
cmpl   $0x0,(%rdx,%rsi,4)
lea    0x2(%rsi),%rsi
jne    1130 <findNextPrime+0x30>
ret
xor    %eax,%eax
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 %41
16: ; preds = %12
store i32 3, i32* %4
br label %41
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 = %37, %18
%23 = load i32, i32* %8
%24 = load i32*, i32** %6
%25 = load i32, i32* %24
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %40
27: ; preds = %22
%28 = load i32*, i32** %7
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = icmp ne i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %27
%35 = load i32, i32* %8
store i32 %35, i32* %4
br label %41
36: ; preds = %27
br label %37
37: ; preds = %36
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 2
store i32 %39, i32* %8
br label %22
40: ; preds = %22
store i32 0, i32* %4
br label %41
41: ; preds = %40, %34, %16, %15
%42 = load i32, i32* %4
ret i32 %42
}

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 %22
i32 2, label %7
]
7: ; preds = %6
br label %22
8: ; preds = %6, %3
%9 = load i32, i32* %1
%10 = sext i32 %4 to i64
%11 = sext i32 %9 to i64
br label %12
12: ; preds = %16, %8
%13 = phi i64 [ %14, %16 ], [ %10, %8 ]
%14 = add i64 %13, 2
%15 = icmp slt i64 %14, %11
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = getelementptr inbounds i32, i32* %2, i64 %14
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %12
20: ; preds = %16
%21 = trunc i64 %14 to i32
br label %22
22: ; preds = %12, %20, %6, %7
%23 = phi i32 [ 3, %7 ], [ 2, %6 ], [ %21, %20 ], [ 0, %12 ]
ret i32 %23
}