#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__ checkPrime(unsigned long);
int /*<<< orphan*/ printf(char *, int, unsigned long);
int main(void) {
  int count = 0;
  for (unsigned long int i = 2; count < 10001; i++) {
    if (checkPrime(i)) {
      count++;
      printf("Prime #%d is %lu\n", count, i);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x2,-0x10(%rbp)
cmpl   $0x2711,-0x8(%rbp)
jge    1190 <main+0x70>
mov    -0x10(%rbp),%rdi
call   1030 <checkPrime@plt>
cmp    $0x0,%rax
je     117a <main+0x5a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
jmp    117f <main+0x5f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113e <main+0x1e>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
mov    $0x2,%ebx
lea    0xece(%rip),%r14
jmp    114c <main+0x2c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    $0x2711,%ebp
jge    116b <main+0x4b>
mov    %rbx,%rdi
call   1030 <checkPrime@plt>
test   %rax,%rax
je     1140 <main+0x20>
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1040 <printf@plt>
jmp    1140 <main+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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