#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 */
scalar_t__ isPrime(unsigned long);
unsigned long solve(int N) {
  int count = 2;
  unsigned long i;
  if (N < 2) {
    return 2;
  } else if (N == 2) {
    return 3;
  }
  for (i = 5; count < N; ++i) {
    if (isPrime(i)) {
      ++count;
    }
  }
  return i - 1;
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    1139 <solve+0x29>
movq   $0x2,-0x8(%rbp)
jmp    11a7 <solve+0x97>
cmpl   $0x2,-0xc(%rbp)
jne    1150 <solve+0x40>
movq   $0x3,-0x8(%rbp)
jmp    11a7 <solve+0x97>
jmp    1155 <solve+0x45>
movq   $0x5,-0x18(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119b <solve+0x8b>
mov    -0x18(%rbp),%rdi
call   1030 <isPrime@plt>
cmp    $0x0,%rax
je     1185 <solve+0x75>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118a <solve+0x7a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115d <solve+0x4d>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbp
push   %r14
push   %rbx
mov    $0x2,%ebx
cmp    $0x2,%edi
jl     1158 <solve+0x48>
mov    $0x3,%ebx
je     1158 <solve+0x48>
mov    %edi,%r14d
mov    $0x2,%ebp
mov    $0x4,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %rbx,%rdi
call   1030 <isPrime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
cmp    %r14d,%ebp
jl     1140 <solve+0x30>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i64 @solve(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %3
store i32 2, i32* %4
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %9
8: ; preds = %1
store i64 2, i64* %2
br label %33
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %9
store i64 3, i64* %2
br label %33
13: ; preds = %9
br label %14
14: ; preds = %13
store i64 5, i64* %5
br label %15
15: ; preds = %27, %14
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i64, i64* %5
%21 = call i64 @isPrime(i64 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %23, %19
br label %27
27: ; preds = %26
%28 = load i64, i64* %5
%29 = add i64 %28, 1
store i64 %29, i64* %5
br label %15
30: ; preds = %15
%31 = load i64, i64* %5
%32 = sub i64 %31, 1
store i64 %32, i64* %2
br label %33
33: ; preds = %30, %12, %8
%34 = load i64, i64* %2
ret i64 %34
}

LLVM IR (-O2):
define i64 @solve(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = icmp eq i32 %0, 2
br i1 %4, label %14, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %12, %5 ], [ 5, %3 ]
%7 = phi i32 [ %11, %5 ], [ 2, %3 ]
%8 = tail call i64 @isPrime(i64 %6)
%9 = icmp ne i64 %8, 0
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %7, %10
%12 = add i64 %6, 1
%13 = icmp slt i32 %11, %0
br i1 %13, label %5, label %14
14: ; preds = %5, %3, %1
%15 = phi i64 [ 2, %1 ], [ 3, %3 ], [ %6, %5 ]
ret i64 %15
}