#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*/ free_prime();
int /*<<< orphan*/ generate_sieve(int);
int /*<<< orphan*/ is_composite(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
void p007() {
  int counter = 0;
  int i = 0;
  generate_sieve(200000);
  while (counter < 10001) {
    if (!is_composite(i++)) {
      counter++;
    }
  }
  i--;
  free_prime();
  printf("The 10001st prime is %d", i);
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x30d40,%edi
call   1040 <generate_sieve@plt>
cmpl   $0x2711,-0x4(%rbp)
jge    1194 <p007+0x54>
mov    -0x8(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
call   1060 <is_composite@plt>
cmp    $0x0,%eax
jne    118f <p007+0x4f>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1160 <p007+0x20>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <free_prime@plt>
mov    -0x8(%rbp),%esi
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %rbx
push   %rax
mov    $0x30d40,%edi
call   1040 <generate_sieve@plt>
xor    %ebp,%ebp
mov    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
mov    %ebx,%edi
call   1060 <is_composite@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
cmp    $0x2711,%ebp
jb     1160 <p007+0x20>
xor    %eax,%eax
call   1030 <free_prime@plt>
lea    0xe7a(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <printf@plt>

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

LLVM IR (-O2):
@.str = [24 x i8] c"The 10001st prime is %d\00"
define void @p007() {
%1 = tail call i32 @generate_sieve(i32 200000)
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %5, %2 ]
%4 = phi i32 [ 0, %0 ], [ %9, %2 ]
%5 = add nuw nsw i32 %3, 1
%6 = tail call i32 @is_composite(i32 %3)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = add nuw nsw i32 %4, %8
%10 = icmp ult i32 %9, 10001
br i1 %10, label %2, label %11
11: ; preds = %2
%12 = tail call i32 (...) @free_prime()
%13 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %3)
ret void
}