#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ gmp_printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_nextprime(int /*<<< orphan*/, int /*<<< orphan*/);
int mpz_probab_prime_p(int /*<<< orphan*/, int);
int Problem007(void) {
  unsigned long const int max = 10001;
  unsigned long int counter;
  mpz_t prime;
  mpz_init_set_ui(prime, 1);
  for (counter = 0; counter < max; counter++) {
    do {
      mpz_nextprime(prime, prime);
    } while (mpz_probab_prime_p(prime, 20) < 2);
  }
  gmp_printf("%30Zd", prime);
  mpz_clear(prime);
  return 0;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x2711,-0x8(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1050 <mpz_init_set_ui@plt>
movq   $0x0,-0x10(%rbp)
cmpq   $0x2711,-0x10(%rbp)
jae    11bf <Problem007+0x6f>
jmp    1188 <Problem007+0x38>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <mpz_nextprime@plt>
mov    -0x14(%rbp),%edi
mov    $0x14,%esi
call   1030 <mpz_probab_prime_p@plt>
cmp    $0x2,%eax
jl     1188 <Problem007+0x38>
jmp    11ae <Problem007+0x5e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1175 <Problem007+0x25>
mov    -0x14(%rbp),%esi
lea    0xe37(%rip),%rdi
call   1070 <gmp_printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <mpz_clear@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbx
mov    $0x1,%esi
call   1050 <mpz_init_set_ui@plt>
xor    %ebx,%ebx
nopl   (%rax)
call   1040 <mpz_nextprime@plt>
mov    $0x14,%esi
call   1030 <mpz_probab_prime_p@plt>
cmp    $0x2,%eax
jl     1160 <Problem007+0x10>
add    $0x1,%rbx
cmp    $0x2711,%rbx
jne    1160 <Problem007+0x10>
lea    0xe78(%rip),%rdi
call   1070 <gmp_printf@plt>
call   1060 <mpz_clear@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%30Zd\00"
define i32 @Problem007() {
%1 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
br label %2
2: ; preds = %0, %8
%3 = phi i64 [ 0, %0 ], [ %9, %8 ]
br label %4
4: ; preds = %2, %4
%5 = tail call i32 @mpz_nextprime(i32 undef, i32 undef)
%6 = tail call i32 @mpz_probab_prime_p(i32 undef, i32 20)
%7 = icmp slt i32 %6, 2
br i1 %7, label %4, label %8
8: ; preds = %4
%9 = add nuw nsw i64 %3, 1
%10 = icmp eq i64 %9, 10001
br i1 %10, label %11, label %2
11: ; preds = %8
%12 = tail call i32 @gmp_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 undef)
%13 = tail call i32 @mpz_clear(i32 undef)
ret i32 0
}