#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__ is_prime(int);
int find_nst_prime(int n) {
  if (n <= 1) {
    return 2;
  }
  int i = 2;
  int k = 3;
  while (1) {
    if (is_prime(k)) {
      if (i >= n) {
        break;
      }
      i++;
    }
    k += 2;
  }
  return k;
}


x86 assembly (clang, -O0):
<find_nst_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1131 <find_nst_prime+0x21>
movl   $0x2,-0x4(%rbp)
jmp    117f <find_nst_prime+0x6f>
movl   $0x2,-0xc(%rbp)
movl   $0x3,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <is_prime@plt>
cmp    $0x0,%rax
je     116b <find_nst_prime+0x5b>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     1162 <find_nst_prime+0x52>
jmp    1179 <find_nst_prime+0x69>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    113f <find_nst_prime+0x2f>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_nst_prime>:
push   %rbp
push   %r14
push   %rbx
mov    $0x2,%ebx
cmp    $0x2,%edi
jge    1125 <find_nst_prime+0x15>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %edi,%r14d
mov    $0x3,%ebx
mov    $0x2,%ebp
jmp    1143 <find_nst_prime+0x33>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x2,%ebx
mov    %ebx,%edi
call   1030 <is_prime@plt>
test   %rax,%rax
je     1140 <find_nst_prime+0x30>
cmp    %r14d,%ebp
jge    111e <find_nst_prime+0xe>
add    $0x1,%ebp
jmp    1140 <find_nst_prime+0x30>

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

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