#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 sqrt(int);
int solve() {
  int prime_count = 2, number = 2, is_prime = 0;
  while (1) {
    for (int j = 2; j <= sqrt(number); j++) {
      if (number % j == 0) {
        is_prime = 0;
        break;
      } else {
        is_prime = 1;
      }
    }
    if (is_prime) {
      prime_count++;
      if (prime_count == 10001) {
        return number;
      }
    }
    number += 1;
  }
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x2,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     1185 <solve+0x75>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    116b <solve+0x5b>
movl   $0x0,-0xc(%rbp)
jmp    1185 <solve+0x75>
movl   $0x1,-0xc(%rbp)
jmp    1177 <solve+0x67>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <solve+0x24>
cmpl   $0x0,-0xc(%rbp)
je     11b3 <solve+0xa3>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x2711,-0x4(%rbp)
jne    11ae <solve+0x9e>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    11b3 <solve+0xa3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112d <solve+0x1d>

x86 assembly (clang, -O2):
<solve>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
mov    $0x2,%r14d
mov    $0x2,%r15d
jmp    1145 <solve+0x35>
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
je     1183 <solve+0x73>
add    $0x1,%r14d
cmp    $0x2711,%r14d
je     1187 <solve+0x77>
add    $0x1,%r15d
mov    %r15d,%edi
call   1030 <sqrt@plt>
cmp    $0x2,%eax
jl     1130 <solve+0x20>
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
xor    %ebp,%ebp
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
test   %edx,%edx
je     1141 <solve+0x31>
mov    %r15d,%edi
call   1030 <sqrt@plt>
cmp    %eax,%ebx
jl     1160 <solve+0x50>
mov    $0x1,%ebp
jmp    1134 <solve+0x24>
xor    %ebp,%ebp
jmp    1141 <solve+0x31>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @solve() {
br label %1
1: ; preds = %22, %0
%2 = phi i32 [ 2, %0 ], [ %24, %22 ]
%3 = phi i32 [ 2, %0 ], [ %25, %22 ]
%4 = phi i32 [ 0, %0 ], [ %23, %22 ]
%5 = tail call i32 @sqrt(i32 %3)
%6 = icmp slt i32 %5, 2
br i1 %6, label %15, label %11
7: ; preds = %11
%8 = add nuw nsw i32 %12, 1
%9 = tail call i32 @sqrt(i32 %3)
%10 = icmp slt i32 %12, %9
br i1 %10, label %11, label %17
11: ; preds = %1, %7
%12 = phi i32 [ %8, %7 ], [ 2, %1 ]
%13 = urem i32 %3, %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %7
15: ; preds = %1
%16 = icmp eq i32 %4, 0
br i1 %16, label %22, label %17
17: ; preds = %7, %15
%18 = phi i32 [ %4, %15 ], [ 1, %7 ]
%19 = add nsw i32 %2, 1
%20 = icmp eq i32 %19, 10001
br i1 %20, label %21, label %22
21: ; preds = %17
ret i32 %3
22: ; preds = %11, %17, %15
%23 = phi i32 [ %18, %17 ], [ 0, %15 ], [ 0, %11 ]
%24 = phi i32 [ %19, %17 ], [ %2, %15 ], [ %2, %11 ]
%25 = add nuw nsw i32 %3, 1
br label %1
}