#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(volatile uint32_t *curPrime, uint32_t *searchLimit,
                       volatile uint8_t *isComposite) {
  if (*curPrime == 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
mov    (%rax),%eax
cmp    $0x2,%eax
jne    112b <findNextPrime+0x2b>
movl   $0x3,-0x4(%rbp)
jmp    117f <findNextPrime+0x7f>
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    1178 <findNextPrime+0x78>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    $0x0,%eax
jne    1165 <findNextPrime+0x65>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117f <findNextPrime+0x7f>
jmp    116a <findNextPrime+0x6a>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    1137 <findNextPrime+0x37>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<findNextPrime>:
mov    (%rdi),%ecx
mov    $0x3,%eax
cmp    $0x2,%ecx
je     1132 <findNextPrime+0x32>
movslq (%rdi),%rax
movslq (%rsi),%rcx
mov    %rax,%rsi
add    $0x2,%rsi
nopl   0x0(%rax)
cmp    %rcx,%rsi
jge    1133 <findNextPrime+0x33>
add    $0x2,%eax
cmpl   $0x0,(%rdx,%rsi,4)
lea    0x2(%rsi),%rsi
jne    1120 <findNextPrime+0x20>
ret
xor    %eax,%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 volatile i32, i32* %9
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 3, i32* %4
br label %36
13: ; preds = %3
%14 = load i32*, i32** %5
%15 = load volatile i32, i32* %14
%16 = add nsw i32 %15, 2
store i32 %16, i32* %8
br label %17
17: ; preds = %32, %13
%18 = load i32, i32* %8
%19 = load i32*, i32** %6
%20 = load i32, i32* %19
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %35
22: ; preds = %17
%23 = load i32*, i32** %7
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load volatile i32, i32* %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %22
%30 = load i32, i32* %8
store i32 %30, i32* %4
br label %36
31: ; preds = %22
br label %32
32: ; preds = %31
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 2
store i32 %34, i32* %8
br label %17
35: ; preds = %17
store i32 0, i32* %4
br label %36
36: ; preds = %35, %29, %12
%37 = load i32, i32* %4
ret i32 %37
}

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