#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 /*<<< orphan*/ check_prime(unsigned long);
int /*<<< orphan*/ printf(char *, int, unsigned long);
int main() {
  unsigned long int prime = 1, i, j;
  for (i = 1; i <= 10001; i++) {
    j = prime;
    j++;
    while (!check_prime(j))
      j++;
    prime = j;
  }
  printf("\n%d prime is %u", 10001, prime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x1,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
cmpq   $0x2711,-0x18(%rbp)
ja     11a9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <check_prime@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    117f <main+0x5f>
jmp    1190 <main+0x70>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1161 <main+0x41>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113f <main+0x1f>
mov    -0x10(%rbp),%rdx
lea    0xe4c(%rip),%rdi
mov    $0x2711,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%r14d
mov    $0x1,%ebx
nop
add    $0x1,%rbx
mov    %rbx,%rdi
call   1030 <check_prime@plt>
test   %eax,%eax
je     1130 <main+0x10>
add    $0x1,%r14
cmp    $0x2712,%r14
jne    1130 <main+0x10>
lea    0xeac(%rip),%rdi
mov    $0x2711,%esi
mov    %rbx,%rdx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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