#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(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int check = 1;
  int target = 100;
  int primeCount = 0;
  int primeWeWant = 10001;
  int result = 0;
  while (1) {
    if (isPrime(check)) {
      primeCount++;
      if (primeCount == primeWeWant) {
        result = check;
        break;
      }
    }
    check++;
  }
  printf("The prime we want is: %d", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x64,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x2711,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     1189 <main+0x69>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1184 <main+0x64>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1197 <main+0x77>
jmp    1189 <main+0x69>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1152 <main+0x32>
mov    -0x18(%rbp),%esi
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebx
xor    %ebp,%ebp
jmp    1133 <main+0x13>
nopl   0x0(%rax)
add    $0x1,%ebx
mov    %ebx,%edi
call   1040 <isPrime@plt>
test   %rax,%rax
je     1130 <main+0x10>
add    $0x1,%ebp
cmp    $0x2711,%ebp
jne    1130 <main+0x10>
lea    0xeaf(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"The prime we want is: %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
store i32 100, i32* %3
store i32 0, i32* %4
store i32 10001, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %0, %20
%8 = load i32, i32* %2
%9 = call i64 @isPrime(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i32, i32* %2
store i32 %18, i32* %6
br label %23
19: ; preds = %11
br label %20
20: ; preds = %19, %7
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %7
23: ; preds = %17
%24 = load i32, i32* %6
%25 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"The prime we want is: %d\00"
define i32 @main() {
br label %1
1: ; preds = %11, %0
%2 = phi i32 [ 0, %0 ], [ %12, %11 ]
%3 = phi i32 [ 1, %0 ], [ %13, %11 ]
%4 = tail call i64 @isPrime(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = add nsw i32 %2, 1
%8 = icmp eq i32 %7, 10001
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3)
ret i32 0
11: ; preds = %6, %1
%12 = phi i32 [ %7, %6 ], [ %2, %1 ]
%13 = add nuw nsw i32 %3, 1
br label %1
}