#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 /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char *argv[]) {
  int prime_count = 0;
  int num = 1;
  while (true) {
    num++;
    if (is_prime(num))
      prime_count++;
    if (prime_count == 10001)
      break;
  }
  printf("%dth prime number: %d\n", 10001, num);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     1168 <main+0x48>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2711,-0x14(%rbp)
jne    117a <main+0x5a>
jmp    117f <main+0x5f>
jmp    1144 <main+0x24>
mov    -0x18(%rbp),%edx
lea    0xe77(%rip),%rdi
mov    $0x2711,%esi
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
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %ebx,%edi
call   1040 <is_prime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
cmp    $0x2711,%ebp
jne    1130 <main+0x10>
lea    0xeb0(%rip),%rdi
mov    $0x2711,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [23 x i8] c"%dth prime number: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 0, %2 ], [ %10, %3 ]
%5 = phi i32 [ 1, %2 ], [ %6, %3 ]
%6 = add nuw nsw i32 %5, 1
%7 = tail call i64 @is_prime(i32 %6)
%8 = icmp ne i64 %7, 0
%9 = zext i1 %8 to i32
%10 = add nuw nsw i32 %4, %9
%11 = icmp eq i32 %10, 10001
br i1 %11, label %12, label %3
12: ; preds = %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 10001, i32 %6)
ret i32 0
}