#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(unsigned long);
int /*<<< orphan*/ printf(char *, unsigned long);
int main() {
  unsigned long p;
  int n = 1;
  for (p = 3; p < -1; p += 2) {
    if (is_prime(p)) {
      n++;
    }
    if (n == 10001) {
      printf("%ld\n", p);
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x14(%rbp)
movq   $0x3,-0x10(%rbp)
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jae    11a4 <main+0x84>
mov    -0x10(%rbp),%rdi
call   1040 <is_prime@plt>
cmp    $0x0,%rax
je     1165 <main+0x45>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2711,-0x14(%rbp)
jne    118e <main+0x6e>
mov    -0x10(%rbp),%rsi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ab <main+0x8b>
jmp    1193 <main+0x73>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    113e <main+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x3,%ebx
mov    $0x1,%ebp
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <is_prime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
cmp    $0x2711,%ebp
je     1153 <main+0x33>
add    $0x2,%rbx
cmp    $0xffffffffffffffff,%rbx
jne    1130 <main+0x10>
jmp    1162 <main+0x42>
lea    0xea6(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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