#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 */
int check_if_prime(int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int nth, i = 3, count, c;
  nth = 10001;
  printf("[*] Locating the %dst prime...\n\n", nth);
  for (count = 2; count <= nth;) {
    c = check_if_prime(count, i);
    if (c == i) {
      if (count == nth) {
        printf("[+] Success!\nThe %dst prime is: %d\n", count, i);
      }
      count++;
    }
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0xc(%rbp)
movl   $0x2711,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11b2 <main+0x92>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <check_if_prime@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11a4 <main+0x84>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    119b <main+0x7b>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1155 <main+0x35>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xed5(%rip),%rdi
mov    $0x2711,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%ebx
mov    $0x3,%ebp
lea    0xed9(%rip),%r14
jmp    115e <main+0x3e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
add    $0x1,%ebp
cmp    $0x2712,%ebx
jge    1186 <main+0x66>
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <check_if_prime@plt>
cmp    %eax,%ebp
jne    1153 <main+0x33>
cmp    $0x2711,%ebx
jne    1150 <main+0x30>
mov    %r14,%rdi
mov    $0x2711,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1150 <main+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"[*] Locating the %dst prime...\0A\0A\00"
@.str.1 = [36 x i8] c"[+] Success!\0AThe %dst prime is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 3, i32* %3
store i32 10001, i32* %2
%6 = load i32, i32* %2
%7 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 2, i32* %4
br label %8
8: ; preds = %30, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %33
12: ; preds = %8
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = call i32 @check_if_prime(i32 %13, i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = load i32, i32* %3
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %12
%20 = load i32, i32* %4
%21 = load i32, i32* %2
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25)
br label %27
27: ; preds = %23, %19
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %30
30: ; preds = %27, %12
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %8
33: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"[*] Locating the %dst prime...\0A\0A\00"
@.str.1 = [36 x i8] c"[+] Success!\0AThe %dst prime is: %d\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 10001)
br label %2
2: ; preds = %0, %13
%3 = phi i32 [ 3, %0 ], [ %15, %13 ]
%4 = phi i32 [ 2, %0 ], [ %14, %13 ]
%5 = tail call i32 @check_if_prime(i32 %4, i32 %3)
%6 = icmp eq i32 %5, %3
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = icmp eq i32 %4, 10001
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 10001, i32 %3)
br label %11
11: ; preds = %9, %7
%12 = add nsw i32 %4, 1
br label %13
13: ; preds = %11, %2
%14 = phi i32 [ %12, %11 ], [ %4, %2 ]
%15 = add nuw nsw i32 %3, 1
%16 = icmp slt i32 %14, 10002
br i1 %16, label %2, label %17
17: ; preds = %13
ret i32 0
}