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

/* Variables and functions */
unsigned int atoi(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gmp_printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ gmp_randclear(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_randinit_mt(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_randseed_ui(int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_inp_raw(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_urandomb(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, unsigned int);
int main(int argc, char *argv[]) {
  FILE *pub;
  int i;
  int bits = 4096;
  mpz_t n, p, q, pm1, pm2, pm3;
  unsigned int seed = atoi(argv[1]);
  unsigned int scount = atoi(argv[2]);
  unsigned int loops = 0;
  mpz_init(n);
  mpz_init(p);
  mpz_init(q);
  mpz_init(pm1);
  mpz_init(pm2);
  mpz_init(pm3);
  pub = fopen("gmp2.pub", "r");
  mpz_inp_raw(n, pub);
  gmp_randstate_t state;
  gmp_randinit_mt(state);
  int j = 0;
  for (; loops < scount; loops++) {
    gmp_randseed_ui(state, seed + loops);
    mpz_urandomb(p, state, bits);
    mpz_urandomb(q, state, bits);
    mpz_mul(pm1, p, q);
    mpz_set(pm2, pm1);
    mpz_mul_ui(pm3, p, 1600000000);
    mpz_add(pm2, pm2, pm3);
    if (mpz_cmp(n, pm1) >= 0) {
      if (mpz_cmp(pm2, n) >= 0) {
        printf("Found seed candidate: %u\n", seed + loops);
        gmp_printf("%Zd\n", p);
      }
    }
  }
  mpz_clear(n);
  mpz_clear(p);
  mpz_clear(q);
  mpz_clear(pm1);
  mpz_clear(pm2);
  mpz_clear(pm3);
  gmp_randclear(state);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1000,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x28(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x2c(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x30(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x34(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x38(%rbp),%edi
call   1060 <mpz_init@plt>
lea    0xd85(%rip),%rdi
lea    0xd87(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   10a0 <mpz_inp_raw@plt>
mov    -0x48(%rbp),%edi
call   10f0 <gmp_randinit_mt@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x40(%rbp),%eax
jae    1376 <main+0x176>
mov    -0x48(%rbp),%edi
mov    -0x3c(%rbp),%esi
add    -0x44(%rbp),%esi
call   10e0 <gmp_randseed_ui@plt>
mov    -0x28(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1070 <mpz_urandomb@plt>
mov    -0x2c(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1070 <mpz_urandomb@plt>
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1090 <mpz_mul@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x38(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    $0x5f5e1000,%edx
call   1120 <mpz_mul_ui@plt>
mov    -0x34(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
call   1080 <mpz_add@plt>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%esi
call   10b0 <mpz_cmp@plt>
cmp    $0x0,%rax
jl     1363 <main+0x163>
mov    -0x34(%rbp),%edi
mov    -0x24(%rbp),%esi
call   10b0 <mpz_cmp@plt>
cmp    $0x0,%rax
jl     135e <main+0x15e>
mov    -0x3c(%rbp),%esi
add    -0x44(%rbp),%esi
lea    0xcc1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xccc(%rip),%rdi
call   1110 <gmp_printf@plt>
jmp    1363 <main+0x163>
jmp    1368 <main+0x168>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12a6 <main+0xa6>
mov    -0x24(%rbp),%edi
call   10c0 <mpz_clear@plt>
mov    -0x28(%rbp),%edi
call   10c0 <mpz_clear@plt>
mov    -0x2c(%rbp),%edi
call   10c0 <mpz_clear@plt>
mov    -0x30(%rbp),%edi
call   10c0 <mpz_clear@plt>
mov    -0x34(%rbp),%edi
call   10c0 <mpz_clear@plt>
mov    -0x38(%rbp),%edi
call   10c0 <mpz_clear@plt>
mov    -0x48(%rbp),%edi
call   1030 <gmp_randclear@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1100 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%ebp
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
lea    0xdbb(%rip),%rdi
lea    0xdbd(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rsi
call   10a0 <mpz_inp_raw@plt>
call   10f0 <gmp_randinit_mt@plt>
test   %ebp,%ebp
je     12e4 <main+0xe4>
lea    0xd9e(%rip),%r14
lea    0xdb1(%rip),%r15
jmp    1288 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebx
add    $0xffffffff,%ebp
je     12e4 <main+0xe4>
mov    %ebx,%esi
call   10e0 <gmp_randseed_ui@plt>
mov    $0x1000,%edx
call   1070 <mpz_urandomb@plt>
mov    $0x1000,%edx
call   1070 <mpz_urandomb@plt>
call   1090 <mpz_mul@plt>
call   1040 <mpz_set@plt>
mov    $0x5f5e1000,%edx
call   1120 <mpz_mul_ui@plt>
call   1080 <mpz_add@plt>
call   10b0 <mpz_cmp@plt>
test   %rax,%rax
js     1280 <main+0x80>
call   10b0 <mpz_cmp@plt>
test   %rax,%rax
js     1280 <main+0x80>
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1110 <gmp_printf@plt>
jmp    1280 <main+0x80>
call   10c0 <mpz_clear@plt>
call   10c0 <mpz_clear@plt>
call   10c0 <mpz_clear@plt>
call   10c0 <mpz_clear@plt>
call   10c0 <mpz_clear@plt>
call   10c0 <mpz_clear@plt>
call   1030 <gmp_randclear@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"gmp2.pub\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Found seed candidate: %u\0A\00"
@.str.3 = [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
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4096, i32* %8
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %15
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %16
store i32 0, i32* %17
%28 = load i32, i32* %9
%29 = call i32 @mpz_init(i32 %28)
%30 = load i32, i32* %10
%31 = call i32 @mpz_init(i32 %30)
%32 = load i32, i32* %11
%33 = call i32 @mpz_init(i32 %32)
%34 = load i32, i32* %12
%35 = call i32 @mpz_init(i32 %34)
%36 = load i32, i32* %13
%37 = call i32 @mpz_init(i32 %36)
%38 = load i32, i32* %14
%39 = call i32 @mpz_init(i32 %38)
%40 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %40, i32** %6
%41 = load i32, i32* %9
%42 = load i32*, i32** %6
%43 = call i32 @mpz_inp_raw(i32 %41, i32* %42)
%44 = load i32, i32* %18
%45 = call i32 @gmp_randinit_mt(i32 %44)
store i32 0, i32* %19
br label %46
46: ; preds = %96, %2
%47 = load i32, i32* %17
%48 = load i32, i32* %16
%49 = icmp ult i32 %47, %48
br i1 %49, label %50, label %99
50: ; preds = %46
%51 = load i32, i32* %18
%52 = load i32, i32* %15
%53 = load i32, i32* %17
%54 = add i32 %52, %53
%55 = call i32 @gmp_randseed_ui(i32 %51, i32 %54)
%56 = load i32, i32* %10
%57 = load i32, i32* %18
%58 = load i32, i32* %8
%59 = call i32 @mpz_urandomb(i32 %56, i32 %57, i32 %58)
%60 = load i32, i32* %11
%61 = load i32, i32* %18
%62 = load i32, i32* %8
%63 = call i32 @mpz_urandomb(i32 %60, i32 %61, i32 %62)
%64 = load i32, i32* %12
%65 = load i32, i32* %10
%66 = load i32, i32* %11
%67 = call i32 @mpz_mul(i32 %64, i32 %65, i32 %66)
%68 = load i32, i32* %13
%69 = load i32, i32* %12
%70 = call i32 @mpz_set(i32 %68, i32 %69)
%71 = load i32, i32* %14
%72 = load i32, i32* %10
%73 = call i32 @mpz_mul_ui(i32 %71, i32 %72, i32 1600000000)
%74 = load i32, i32* %13
%75 = load i32, i32* %13
%76 = load i32, i32* %14
%77 = call i32 @mpz_add(i32 %74, i32 %75, i32 %76)
%78 = load i32, i32* %9
%79 = load i32, i32* %12
%80 = call i64 @mpz_cmp(i32 %78, i32 %79)
%81 = icmp sge i64 %80, 0
br i1 %81, label %82, label %95
82: ; preds = %50
%83 = load i32, i32* %13
%84 = load i32, i32* %9
%85 = call i64 @mpz_cmp(i32 %83, i32 %84)
%86 = icmp sge i64 %85, 0
br i1 %86, label %87, label %94
87: ; preds = %82
%88 = load i32, i32* %15
%89 = load i32, i32* %17
%90 = add i32 %88, %89
%91 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %90)
%92 = load i32, i32* %10
%93 = call i32 @gmp_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %92)
br label %94
94: ; preds = %87, %82
br label %95
95: ; preds = %94, %50
br label %96
96: ; preds = %95
%97 = load i32, i32* %17
%98 = add i32 %97, 1
store i32 %98, i32* %17
br label %46
99: ; preds = %46
%100 = load i32, i32* %9
%101 = call i32 @mpz_clear(i32 %100)
%102 = load i32, i32* %10
%103 = call i32 @mpz_clear(i32 %102)
%104 = load i32, i32* %11
%105 = call i32 @mpz_clear(i32 %104)
%106 = load i32, i32* %12
%107 = call i32 @mpz_clear(i32 %106)
%108 = load i32, i32* %13
%109 = call i32 @mpz_clear(i32 %108)
%110 = load i32, i32* %14
%111 = call i32 @mpz_clear(i32 %110)
%112 = load i32, i32* %18
%113 = call i32 @gmp_randclear(i32 %112)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"gmp2.pub\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Found seed candidate: %u\0A\00"
@.str.3 = [5 x i8] c"%Zd\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = tail call i32 @mpz_init(i32 undef)
%10 = tail call i32 @mpz_init(i32 undef)
%11 = tail call i32 @mpz_init(i32 undef)
%12 = tail call i32 @mpz_init(i32 undef)
%13 = tail call i32 @mpz_init(i32 undef)
%14 = tail call i32 @mpz_init(i32 undef)
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @mpz_inp_raw(i32 undef, i32* %15)
%17 = tail call i32 @gmp_randinit_mt(i32 undef)
%18 = icmp eq i32 %8, 0
br i1 %18, label %40, label %19
19: ; preds = %2, %37
%20 = phi i32 [ %38, %37 ], [ 0, %2 ]
%21 = add i32 %20, %5
%22 = tail call i32 @gmp_randseed_ui(i32 undef, i32 %21)
%23 = tail call i32 @mpz_urandomb(i32 undef, i32 undef, i32 4096)
%24 = tail call i32 @mpz_urandomb(i32 undef, i32 undef, i32 4096)
%25 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%26 = tail call i32 @mpz_set(i32 undef, i32 undef)
%27 = tail call i32 @mpz_mul_ui(i32 undef, i32 undef, i32 1600000000)
%28 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%29 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%30 = icmp sgt i64 %29, -1
br i1 %30, label %31, label %37
31: ; preds = %19
%32 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%33 = icmp sgt i64 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%36 = tail call i32 @gmp_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 undef)
br label %37
37: ; preds = %19, %34, %31
%38 = add nuw i32 %20, 1
%39 = icmp eq i32 %38, %8
br i1 %39, label %40, label %19
40: ; preds = %37, %2
%41 = tail call i32 @mpz_clear(i32 undef)
%42 = tail call i32 @mpz_clear(i32 undef)
%43 = tail call i32 @mpz_clear(i32 undef)
%44 = tail call i32 @mpz_clear(i32 undef)
%45 = tail call i32 @mpz_clear(i32 undef)
%46 = tail call i32 @mpz_clear(i32 undef)
%47 = tail call i32 @gmp_randclear(i32 undef)
ret i32 0
}