#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 */
scalar_t__ atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gmp_printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_probab_prime_p(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_ui_pow_ui(int /*<<< orphan*/, int, unsigned int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  unsigned bits;
  int counter = 0;
  mpz_t n;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <bits>\n", argv[0]);
    return 1;
  }
  bits = (unsigned)atoi(argv[1]);
  mpz_init(n);
  mpz_ui_pow_ui(n, 2, bits);
  mpz_add_ui(n, n, 1);
  while (!mpz_probab_prime_p(n, 25)) {
    mpz_add_ui(n, n, 2);
    counter++;
    if (counter % 200 == 0)
      fprintf(stderr, "tried %i numbers so far\n", counter);
  }
  gmp_printf("%Zd\n", n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c1 <main+0x51>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127d <main+0x10d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    $0x2,%esi
call   1090 <mpz_ui_pow_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
mov    -0x1c(%rbp),%edi
mov    $0x19,%esi
call   1030 <mpz_probab_prime_p@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    121b <main+0xab>
jmp    1267 <main+0xf7>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x2,%edx
call   1040 <mpz_add_ui@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xc8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1262 <main+0xf2>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    11f9 <main+0x89>
mov    -0x1c(%rbp),%esi
lea    0xdba(%rip),%rdi
call   1080 <gmp_printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jg     119e <main+0x2e>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe70(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    11e7 <main+0x77>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %rax,%rbx
call   1050 <mpz_init@plt>
mov    $0x2,%esi
mov    %ebx,%edx
call   1090 <mpz_ui_pow_ui@plt>
mov    $0x1,%r12d
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
mov    $0x19,%esi
call   1030 <mpz_probab_prime_p@plt>
test   %eax,%eax
je     11f0 <main+0x80>
lea    0xe4b(%rip),%rdi
call   1080 <gmp_printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%ebp
mov    0x2de4(%rip),%r15
lea    0xe0f(%rip),%r14
jmp    1225 <main+0xb5>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x19,%esi
call   1030 <mpz_probab_prime_p@plt>
add    $0xffffffff,%ebp
add    $0x1,%r12d
test   %eax,%eax
jne    11d9 <main+0x69>
mov    %r12d,%eax
imul   $0x51eb851f,%rax,%rax
shr    $0x26,%rax
imul   $0xc8,%eax,%ebx
mov    $0x2,%edx
call   1040 <mpz_add_ui@plt>
add    %ebp,%ebx
jne    1210 <main+0xa0>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1210 <main+0xa0>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <bits>\0A\00"
@.str.1 = [25 x i8] c"tried %i numbers so far\0A\00"
@.str.2 = [5 x i8] c"%Zd\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %53
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @atoi(i8* %20)
%22 = trunc i64 %21 to i32
store i32 %22, i32* %6
%23 = load i32, i32* %8
%24 = call i32 @mpz_init(i32 %23)
%25 = load i32, i32* %8
%26 = load i32, i32* %6
%27 = call i32 @mpz_ui_pow_ui(i32 %25, i32 2, i32 %26)
%28 = load i32, i32* %8
%29 = load i32, i32* %8
%30 = call i32 @mpz_add_ui(i32 %28, i32 %29, i32 1)
br label %31
31: ; preds = %49, %17
%32 = load i32, i32* %8
%33 = call i32 @mpz_probab_prime_p(i32 %32, i32 25)
%34 = icmp ne i32 %33, 0
%35 = xor i1 %34, true
br i1 %35, label %36, label %50
36: ; preds = %31
%37 = load i32, i32* %8
%38 = load i32, i32* %8
%39 = call i32 @mpz_add_ui(i32 %37, i32 %38, i32 2)
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = srem i32 %42, 200
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %36
%46 = load i32, i32* @stderr
%47 = load i32, i32* %7
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %45, %36
br label %31
50: ; preds = %31
%51 = load i32, i32* %8
%52 = call i32 @gmp_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %51)
store i32 0, i32* %3
br label %53
53: ; preds = %50, %11
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <bits>\0A\00"
@.str.1 = [25 x i8] c"tried %i numbers so far\0A\00"
@.str.2 = [5 x i8] c"%Zd\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %32
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atoi(i8* %10)
%12 = trunc i64 %11 to i32
%13 = tail call i32 @mpz_init(i32 undef)
%14 = tail call i32 @mpz_ui_pow_ui(i32 undef, i32 2, i32 %12)
%15 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 1)
%16 = tail call i32 @mpz_probab_prime_p(i32 undef, i32 25)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %8, %27
%19 = phi i32 [ %21, %27 ], [ 0, %8 ]
%20 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 2)
%21 = add nuw nsw i32 %19, 1
%22 = urem i32 %21, 200
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %27
27: ; preds = %24, %18
%28 = tail call i32 @mpz_probab_prime_p(i32 undef, i32 25)
%29 = icmp eq i32 %28, 0
br i1 %29, label %18, label %30
30: ; preds = %27, %8
%31 = tail call i32 @gmp_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 undef)
br label %32
32: ; preds = %30, %4
%33 = phi i32 [ 1, %4 ], [ 0, %30 ]
ret i32 %33
}