#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 uint32_t;
typedef scalar_t__ time_t;
typedef int BN_ULONG;
typedef int /*<<< orphan*/ BN_CTX;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
int /*<<< orphan*/ BN_add_word(int /*<<< orphan*/ *, unsigned long);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_hex2bn(int /*<<< orphan*/ **, char *);
scalar_t__ BN_is_prime(int /*<<< orphan*/ *, int, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_lshift(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int BN_mod_word(int /*<<< orphan*/ *, unsigned long);
int /*<<< orphan*/ *BN_new();
scalar_t__ BN_num_bits(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_rshift(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
char *ctime(scalar_t__ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, int, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(unsigned long);
scalar_t__ qfileout(int /*<<< orphan*/, int, int, int, int, int,
                    int /*<<< orphan*/ *);
int /*<<< orphan*/ setprogname(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
size_t strlen(char *);
int /*<<< orphan*/ strspn(char *, char *);
int strtoul(char *, char **, int);
int /*<<< orphan*/ time(scalar_t__ *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  BIGNUM *q, *p, *a;
  BN_CTX *ctx;
  char *cp;
  char *lp;
  uint32_t count_in = 0;
  uint32_t count_out = 0;
  uint32_t count_possible = 0;
  uint32_t generator_known;
  uint32_t generator_wanted = 0;
  uint32_t in_tests;
  uint32_t in_tries;
  uint32_t in_type;
  uint32_t in_size;
  int trials;
  time_t time_start;
  time_t time_stop;
  setprogname(argv[0]);
  if (argc < 2) {
    usage();
  }
  if ((trials = strtoul(argv[1], NULL, 10)) < (4)) {
    trials = (4);
  }
  if (argc > 2) {
    generator_wanted = strtoul(argv[2], NULL, 16);
  }
  time(&time_start);
  p = BN_new();
  q = BN_new();
  ctx = BN_CTX_new();
  (void)fprintf(stderr, "%.24s Final %d Miller-Rabin trials (%x generator)\n",
                ctime(&time_start), trials, generator_wanted);
  lp = (char *)malloc((unsigned long)(100 + 8192) + 1);
  while (fgets(lp, (100 + 8192), stdin) != NULL) {
    size_t ll = strlen(lp);
    count_in++;
    if (ll < 14 || *lp == '!' || *lp == '#') {
      continue;
    }
    cp = &lp[14];
    in_type = strtoul(cp, &cp, 10);
    in_tests = strtoul(cp, &cp, 10);
    if (in_tests & (0x01)) {
      continue;
    }
    in_tries = (uint32_t)strtoul(cp, &cp, 10);
    in_size = (uint32_t)strtoul(cp, &cp, 10);
    generator_known = (uint32_t)strtoul(cp, &cp, 16);
    cp += strspn(cp, " ");
    switch (in_type) {
    case (4):
      a = q;
      BN_hex2bn(&a, cp);
      BN_lshift(p, q, 1);
      BN_add_word(p, 1UL);
      in_size += 1;
      generator_known = 0;
      break;
    default:
      a = p;
      BN_hex2bn(&a, cp);
      BN_rshift(q, p, 1);
      break;
    }
    if ((uint32_t)BN_num_bits(p) != (in_size + 1)) {
      continue;
    }
    if (in_size < (511)) {
      continue;
    }
    if (in_tests & (0x04))
      in_tries += trials;
    else
      in_tries = trials;
    if (generator_known == 0) {
      if (BN_mod_word(p, 24UL) == 11)
        generator_known = 2;
      else if (BN_mod_word(p, 12UL) == 5)
        generator_known = 3;
      else {
        BN_ULONG r = BN_mod_word(p, 10UL);
        if (r == 3 || r == 7) {
          generator_known = 5;
        }
      }
    }
    if (generator_wanted > 0 && generator_wanted != generator_known) {
      continue;
    }
    count_possible++;
    if (BN_is_prime(q, 1, NULL, ctx, NULL) <= 0) {
      continue;
    }
    if (!BN_is_prime(p, trials, NULL, ctx, NULL)) {
      continue;
    }
    if (!BN_is_prime(q, trials - 1, NULL, ctx, NULL)) {
      continue;
    }
    if (0 > qfileout(stdout, (2), (in_tests | (0x04)), in_tries, in_size,
                     generator_known, p)) {
      break;
    }
    count_out++;
  }
  time(&time_stop);
  free(lp);
  BN_free(p);
  BN_free(q);
  BN_CTX_free(ctx);
  fflush(stdout);
  (void)fprintf(stderr,
                "%.24s Found %u safe primes of %u candidates in %lu seconds\n",
                ctime(&time_stop), count_out, count_possible,
                (long)(time_stop - time_start));
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   11a0 <setprogname@plt>
cmpl   $0x2,-0x8(%rbp)
jge    12d2 <main+0x52>
mov    $0x0,%al
call   1140 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1190 <strtoul@plt>
mov    %eax,-0x68(%rbp)
cmp    $0x4,%eax
jge    12fb <main+0x7b>
movl   $0x4,-0x68(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    131e <main+0x9e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1190 <strtoul@plt>
mov    %eax,-0x54(%rbp)
lea    -0x70(%rbp),%rdi
call   1110 <time@plt>
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1100 <BN_CTX_new@plt>
mov    %rax,-0x30(%rbp)
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <ctime@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
mov    -0x68(%rbp),%ecx
mov    -0x54(%rbp),%r8d
lea    0xc89(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
mov    $0x2065,%edi
call   1120 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2c51(%rip),%rax
mov    (%rax),%edx
mov    $0x2064,%esi
call   10c0 <fgets@plt>
cmp    $0x0,%rax
je     1702 <main+0x482>
mov    -0x40(%rbp),%rdi
call   1080 <strlen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
cmpq   $0xe,-0x80(%rbp)
jb     13ee <main+0x16e>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x21,%eax
je     13ee <main+0x16e>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    13f3 <main+0x173>
jmp    138c <main+0x10c>
mov    -0x40(%rbp),%rax
add    $0xe,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1190 <strtoul@plt>
mov    %eax,-0x60(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1190 <strtoul@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     143d <main+0x1bd>
jmp    138c <main+0x10c>
mov    -0x38(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    %rsi,-0x90(%rbp)
mov    $0xa,%edx
mov    %edx,-0x94(%rbp)
call   1190 <strtoul@plt>
mov    -0x94(%rbp),%edx
mov    -0x90(%rbp),%rsi
mov    %eax,-0x5c(%rbp)
mov    -0x38(%rbp),%rdi
call   1190 <strtoul@plt>
mov    -0x90(%rbp),%rsi
mov    %eax,-0x64(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x10,%edx
call   1190 <strtoul@plt>
mov    %eax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xb98(%rip),%rsi
call   10a0 <strspn@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x60(%rbp),%eax
sub    $0x4,%eax
jne    150b <main+0x28b>
jmp    14c1 <main+0x241>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1040 <BN_hex2bn@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1170 <BN_lshift@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   10b0 <BN_add_word@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
movl   $0x0,-0x50(%rbp)
jmp    1532 <main+0x2b2>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1040 <BN_hex2bn@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1160 <BN_rshift@plt>
mov    -0x20(%rbp),%rdi
call   1070 <BN_num_bits@plt>
mov    -0x64(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     154e <main+0x2ce>
jmp    138c <main+0x10c>
cmpl   $0x1ff,-0x64(%rbp)
jge    1560 <main+0x2e0>
jmp    138c <main+0x10c>
mov    -0x58(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     157d <main+0x2fd>
mov    -0x68(%rbp),%eax
add    -0x5c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    1583 <main+0x303>
mov    -0x68(%rbp),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x50(%rbp)
jne    1617 <main+0x397>
mov    -0x20(%rbp),%rdi
mov    $0x18,%esi
call   1180 <BN_mod_word@plt>
cmp    $0xb,%eax
jne    15b0 <main+0x330>
movl   $0x2,-0x50(%rbp)
jmp    1612 <main+0x392>
mov    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1180 <BN_mod_word@plt>
cmp    $0x5,%eax
jne    15d3 <main+0x353>
movl   $0x3,-0x50(%rbp)
jmp    160d <main+0x38d>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1180 <BN_mod_word@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x3,-0x84(%rbp)
je     1601 <main+0x381>
cmpl   $0x7,-0x84(%rbp)
jne    1608 <main+0x388>
movl   $0x5,-0x50(%rbp)
jmp    160d <main+0x38d>
jmp    1612 <main+0x392>
jmp    1617 <main+0x397>
cmpl   $0x0,-0x54(%rbp)
jle    1632 <main+0x3b2>
mov    -0x54(%rbp),%eax
cmp    -0x50(%rbp),%eax
je     1632 <main+0x3b2>
jmp    138c <main+0x10c>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1150 <BN_is_prime@plt>
cmp    $0x0,%rax
jg     1664 <main+0x3e4>
jmp    138c <main+0x10c>
mov    -0x20(%rbp),%rdi
mov    -0x68(%rbp),%esi
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1150 <BN_is_prime@plt>
cmp    $0x0,%rax
jne    168b <main+0x40b>
jmp    138c <main+0x10c>
mov    -0x18(%rbp),%rdi
mov    -0x68(%rbp),%esi
sub    $0x1,%esi
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1150 <BN_is_prime@plt>
cmp    $0x0,%rax
jne    16b5 <main+0x435>
jmp    138c <main+0x10c>
mov    0x2914(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%edx
or     $0x4,%edx
mov    -0x5c(%rbp),%ecx
mov    -0x64(%rbp),%r8d
mov    -0x50(%rbp),%r9d
mov    -0x20(%rbp),%rax
mov    $0x2,%esi
mov    %rax,(%rsp)
call   10d0 <qfileout@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    16f4 <main+0x474>
jmp    1702 <main+0x482>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    138c <main+0x10c>
lea    -0x78(%rbp),%rdi
call   1110 <time@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   10e0 <BN_free@plt>
mov    -0x18(%rbp),%rdi
call   10e0 <BN_free@plt>
mov    -0x30(%rbp),%rdi
call   1090 <BN_CTX_free@plt>
mov    0x289a(%rip),%rax
mov    (%rax),%edi
call   1130 <fflush@plt>
mov    0x2894(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
lea    -0x78(%rbp),%rdi
call   1060 <ctime@plt>
mov    -0x98(%rbp),%edi
mov    %rax,%rdx
mov    -0x48(%rbp),%ecx
mov    -0x4c(%rbp),%r8d
mov    -0x78(%rbp),%r9
sub    -0x70(%rbp),%r9
lea    0x8c1(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
mov    (%rsi),%rdi
call   11a0 <setprogname@plt>
cmp    $0x1,%r14d
jg     12a9 <main+0x29>
xor    %eax,%eax
call   1140 <usage@plt>
mov    0x8(%rbp),%rdi
xor    %eax,%eax
mov    %rax,0x20(%rsp)
xor    %esi,%esi
mov    $0xa,%edx
call   1190 <strtoul@plt>
cmp    $0x5,%eax
mov    $0x4,%ebx
cmovge %eax,%ebx
mov    $0x0,%r13d
cmp    $0x3,%r14d
jl     12ea <main+0x6a>
mov    0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1190 <strtoul@plt>
mov    %eax,%r13d
lea    0x70(%rsp),%r14
mov    %r14,%rdi
call   1110 <time@plt>
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,0x18(%rsp)
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,0x28(%rsp)
xor    %eax,%eax
call   1100 <BN_CTX_new@plt>
mov    %rax,0x40(%rsp)
mov    0x2cb6(%rip),%rax
mov    (%rax),%ebp
mov    %r14,%rdi
call   1060 <ctime@plt>
lea    0xccd(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %rbx,0x38(%rsp)
mov    %ebx,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   10f0 <fprintf@plt>
mov    $0x2065,%edi
call   1120 <malloc@plt>
mov    %rax,%r14
mov    0x2c8b(%rip),%rbx
mov    (%rbx),%edx
mov    %rax,%rdi
mov    $0x2064,%esi
call   10c0 <fgets@plt>
mov    $0x0,%ecx
mov    %rcx,0x30(%rsp)
test   %rax,%rax
je     1657 <main+0x3d7>
mov    %r14,%rax
add    $0xe,%rax
mov    %rax,0x60(%rsp)
mov    0x38(%rsp),%rax
add    $0xffffffff,%eax
mov    %eax,0x50(%rsp)
xor    %eax,%eax
mov    %rax,0x30(%rsp)
lea    0x10(%rsp),%rbp
xor    %eax,%eax
mov    %rax,0x20(%rsp)
mov    %r13d,0x54(%rsp)
jmp    13e8 <main+0x168>
mov    %rbp,0x20(%rsp)
mov    0x2c2b(%rip),%rbx
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx),%edx
mov    %r14,%rdi
mov    $0x2064,%esi
call   10c0 <fgets@plt>
test   %rax,%rax
je     1657 <main+0x3d7>
mov    %r14,%rdi
call   1080 <strlen@plt>
cmp    $0xe,%rax
jb     13d0 <main+0x150>
movzbl (%r14),%eax
or     $0x2,%al
cmp    $0x23,%al
je     13d0 <main+0x150>
mov    0x60(%rsp),%rdi
mov    %rdi,0x10(%rsp)
mov    %rbp,%rsi
mov    $0xa,%edx
call   1190 <strtoul@plt>
mov    %eax,%r15d
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1190 <strtoul@plt>
test   $0x1,%al
jne    13d0 <main+0x150>
mov    %eax,0x5c(%rsp)
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1190 <strtoul@plt>
mov    %eax,0x58(%rsp)
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1190 <strtoul@plt>
mov    %eax,%r12d
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1190 <strtoul@plt>
mov    %eax,%ebx
mov    0x10(%rsp),%r13
mov    %r13,%rdi
lea    0xbb1(%rip),%rsi
call   10a0 <strspn@plt>
movslq %eax,%rsi
add    %r13,%rsi
mov    %rsi,0x10(%rsp)
cmp    $0x4,%r15d
jne    14d6 <main+0x256>
mov    0x28(%rsp),%rbx
mov    %rbx,0x48(%rsp)
lea    0x48(%rsp),%rdi
call   1040 <BN_hex2bn@plt>
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1170 <BN_lshift@plt>
mov    $0x1,%esi
mov    %rbp,%rdi
call   10b0 <BN_add_word@plt>
add    $0x1,%r12d
xor    %ebx,%ebx
jmp    14fc <main+0x27c>
mov    0x18(%rsp),%rbp
mov    %rbp,0x48(%rsp)
lea    0x48(%rsp),%rdi
call   1040 <BN_hex2bn@plt>
mov    0x28(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1160 <BN_rshift@plt>
mov    0x40(%rsp),%r15
mov    %rbp,%rdi
call   1070 <BN_num_bits@plt>
cmp    $0x1ff,%r12d
mov    0x20(%rsp),%rbp
jl     13b1 <main+0x131>
lea    0x1(%r12),%ecx
cmp    %eax,%ecx
jne    13b1 <main+0x131>
test   %ebx,%ebx
mov    0x54(%rsp),%r13d
jne    1580 <main+0x300>
mov    $0x18,%esi
mov    0x18(%rsp),%rdi
call   1180 <BN_mod_word@plt>
mov    $0x2,%ebx
cmp    $0xb,%eax
je     1580 <main+0x300>
mov    $0xc,%esi
mov    0x18(%rsp),%rdi
call   1180 <BN_mod_word@plt>
mov    $0x3,%ebx
cmp    $0x5,%eax
je     1580 <main+0x300>
mov    $0xa,%esi
mov    0x18(%rsp),%rdi
call   1180 <BN_mod_word@plt>
and    $0xfffffffb,%eax
xor    %ecx,%ecx
cmp    $0x3,%eax
sete   %cl
lea    (%rcx,%rcx,4),%ebx
test   %r13d,%r13d
jle    158e <main+0x30e>
cmp    %ebx,%r13d
jne    13b1 <main+0x131>
add    $0x1,%ebp
mov    0x28(%rsp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1150 <BN_is_prime@plt>
test   %rax,%rax
mov    %rbp,0x20(%rsp)
jle    13b6 <main+0x136>
mov    0x18(%rsp),%rdi
mov    0x38(%rsp),%rsi
xor    %edx,%edx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1150 <BN_is_prime@plt>
test   %rax,%rax
je     13b6 <main+0x136>
mov    0x28(%rsp),%rdi
mov    0x50(%rsp),%esi
xor    %edx,%edx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1150 <BN_is_prime@plt>
test   %rax,%rax
je     13b6 <main+0x136>
mov    0x5c(%rsp),%edx
mov    %edx,%ecx
shl    $0x1d,%ecx
sar    $0x1f,%ecx
and    0x58(%rsp),%ecx
add    0x38(%rsp),%ecx
mov    0x29c0(%rip),%rax
mov    (%rax),%edi
or     $0x4,%edx
mov    0x18(%rsp),%rax
mov    %rax,(%rsp)
mov    $0x2,%esi
mov    %r12d,%r8d
mov    %ebx,%r9d
call   10d0 <qfileout@plt>
xor    %ecx,%ecx
test   %rax,%rax
setns  %cl
mov    0x30(%rsp),%rdx
add    %ecx,%edx
mov    %rdx,0x30(%rsp)
test   %rax,%rax
mov    0x299c(%rip),%rbx
lea    0x10(%rsp),%rbp
jns    13d0 <main+0x150>
lea    0x68(%rsp),%rbx
mov    %rbx,%rdi
call   1110 <time@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   10e0 <BN_free@plt>
mov    0x28(%rsp),%rdi
call   10e0 <BN_free@plt>
mov    0x40(%rsp),%rdi
call   1090 <BN_CTX_free@plt>
mov    0x293f(%rip),%rax
mov    (%rax),%edi
call   1130 <fflush@plt>
mov    0x2939(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1060 <ctime@plt>
mov    0x68(%rsp),%r9
sub    0x70(%rsp),%r9
lea    0x97b(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    0x30(%rsp),%rcx
mov    0x20(%rsp),%r8
xor    %eax,%eax
call   10f0 <fprintf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"%.24s Final %d Miller-Rabin trials (%x generator)\0A\00"
@stdin = global i32 0
@.str.1 = [2 x i8] c" \00"
@stdout = global i32 0
@.str.2 = [60 x i8] c"%.24s Found %u safe primes of %u candidates in %lu seconds\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 i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i64
%23 = alloca i64
%24 = alloca i64
%25 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %16
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @setprogname(i8* %28)
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 2
br i1 %31, label %32, label %34
32: ; preds = %2
%33 = call i32 (...) @usage()
br label %34
34: ; preds = %32, %2
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @strtoul(i8* %37, i8** null, i32 10)
store i32 %38, i32* %21
%39 = icmp slt i32 %38, 4
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 4, i32* %21
br label %41
41: ; preds = %40, %34
%42 = load i32, i32* %4
%43 = icmp sgt i32 %42, 2
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @strtoul(i8* %47, i8** null, i32 16)
store i32 %48, i32* %16
br label %49
49: ; preds = %44, %41
%50 = call i32 @time(i64* %22)
%51 = call i32* (...) @BN_new()
store i32* %51, i32** %7
%52 = call i32* (...) @BN_new()
store i32* %52, i32** %6
%53 = call i32* (...) @BN_CTX_new()
store i32* %53, i32** %9
%54 = load i32, i32* @stderr
%55 = call i8* @ctime(i64* %22)
%56 = load i32, i32* %21
%57 = load i32, i32* %16
%58 = call i32 (i32, i8*, i8*, i32, i32, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %55, i32 %56, i32 %57)
%59 = call i64 @malloc(i64 8293)
%60 = inttoptr i64 %59 to i8*
store i8* %60, i8** %11
br label %61
61: ; preds = %215, %203, %195, %188, %180, %137, %133, %94, %83, %49
%62 = load i8*, i8** %11
%63 = load i32, i32* @stdin
%64 = call i32* @fgets(i8* %62, i32 8292, i32 %63)
%65 = icmp ne i32* %64, null
br i1 %65, label %66, label %218
66: ; preds = %61
%67 = load i8*, i8** %11
%68 = call i64 @strlen(i8* %67)
store i64 %68, i64* %24
%69 = load i32, i32* %12
%70 = add nsw i32 %69, 1
store i32 %70, i32* %12
%71 = load i64, i64* %24
%72 = icmp ult i64 %71, 14
br i1 %72, label %83, label %73
73: ; preds = %66
%74 = load i8*, i8** %11
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp eq i32 %76, 33
br i1 %77, label %83, label %78
78: ; preds = %73
%79 = load i8*, i8** %11
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 35
br i1 %82, label %83, label %84
83: ; preds = %78, %73, %66
br label %61
84: ; preds = %78
%85 = load i8*, i8** %11
%86 = getelementptr inbounds i8, i8* %85, i64 14
store i8* %86, i8** %10
%87 = load i8*, i8** %10
%88 = call i32 @strtoul(i8* %87, i8** %10, i32 10)
store i32 %88, i32* %19
%89 = load i8*, i8** %10
%90 = call i32 @strtoul(i8* %89, i8** %10, i32 10)
store i32 %90, i32* %17
%91 = load i32, i32* %17
%92 = and i32 %91, 1
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %95
94: ; preds = %84
br label %61
95: ; preds = %84
%96 = load i8*, i8** %10
%97 = call i32 @strtoul(i8* %96, i8** %10, i32 10)
store i32 %97, i32* %18
%98 = load i8*, i8** %10
%99 = call i32 @strtoul(i8* %98, i8** %10, i32 10)
store i32 %99, i32* %20
%100 = load i8*, i8** %10
%101 = call i32 @strtoul(i8* %100, i8** %10, i32 16)
store i32 %101, i32* %15
%102 = load i8*, i8** %10
%103 = call i32 @strspn(i8* %102, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%104 = load i8*, i8** %10
%105 = sext i32 %103 to i64
%106 = getelementptr inbounds i8, i8* %104, i64 %105
store i8* %106, i8** %10
%107 = load i32, i32* %19
switch i32 %107, label %119 [
i32 4, label %108
]
108: ; preds = %95
%109 = load i32*, i32** %6
store i32* %109, i32** %8
%110 = load i8*, i8** %10
%111 = call i32 @BN_hex2bn(i32** %8, i8* %110)
%112 = load i32*, i32** %7
%113 = load i32*, i32** %6
%114 = call i32 @BN_lshift(i32* %112, i32* %113, i32 1)
%115 = load i32*, i32** %7
%116 = call i32 @BN_add_word(i32* %115, i64 1)
%117 = load i32, i32* %20
%118 = add nsw i32 %117, 1
store i32 %118, i32* %20
store i32 0, i32* %15
br label %126
119: ; preds = %95
%120 = load i32*, i32** %7
store i32* %120, i32** %8
%121 = load i8*, i8** %10
%122 = call i32 @BN_hex2bn(i32** %8, i8* %121)
%123 = load i32*, i32** %6
%124 = load i32*, i32** %7
%125 = call i32 @BN_rshift(i32* %123, i32* %124, i32 1)
br label %126
126: ; preds = %119, %108
%127 = load i32*, i32** %7
%128 = call i64 @BN_num_bits(i32* %127)
%129 = trunc i64 %128 to i32
%130 = load i32, i32* %20
%131 = add nsw i32 %130, 1
%132 = icmp ne i32 %129, %131
br i1 %132, label %133, label %134
133: ; preds = %126
br label %61
134: ; preds = %126
%135 = load i32, i32* %20
%136 = icmp slt i32 %135, 511
br i1 %136, label %137, label %138
137: ; preds = %134
br label %61
138: ; preds = %134
%139 = load i32, i32* %17
%140 = and i32 %139, 4
%141 = icmp ne i32 %140, 0
br i1 %141, label %142, label %146
142: ; preds = %138
%143 = load i32, i32* %21
%144 = load i32, i32* %18
%145 = add nsw i32 %144, %143
store i32 %145, i32* %18
br label %148
146: ; preds = %138
%147 = load i32, i32* %21
store i32 %147, i32* %18
br label %148
148: ; preds = %146, %142
%149 = load i32, i32* %15
%150 = icmp eq i32 %149, 0
br i1 %150, label %151, label %173
151: ; preds = %148
%152 = load i32*, i32** %7
%153 = call i32 @BN_mod_word(i32* %152, i64 24)
%154 = icmp eq i32 %153, 11
br i1 %154, label %155, label %156
155: ; preds = %151
store i32 2, i32* %15
br label %172
156: ; preds = %151
%157 = load i32*, i32** %7
%158 = call i32 @BN_mod_word(i32* %157, i64 12)
%159 = icmp eq i32 %158, 5
br i1 %159, label %160, label %161
160: ; preds = %156
store i32 3, i32* %15
br label %171
161: ; preds = %156
%162 = load i32*, i32** %7
%163 = call i32 @BN_mod_word(i32* %162, i64 10)
store i32 %163, i32* %25
%164 = load i32, i32* %25
%165 = icmp eq i32 %164, 3
br i1 %165, label %169, label %166
166: ; preds = %161
%167 = load i32, i32* %25
%168 = icmp eq i32 %167, 7
br i1 %168, label %169, label %170
169: ; preds = %166, %161
store i32 5, i32* %15
br label %170
170: ; preds = %169, %166
br label %171
171: ; preds = %170, %160
br label %172
172: ; preds = %171, %155
br label %173
173: ; preds = %172, %148
%174 = load i32, i32* %16
%175 = icmp sgt i32 %174, 0
br i1 %175, label %176, label %181
176: ; preds = %173
%177 = load i32, i32* %16
%178 = load i32, i32* %15
%179 = icmp ne i32 %177, %178
br i1 %179, label %180, label %181
180: ; preds = %176
br label %61
181: ; preds = %176, %173
%182 = load i32, i32* %14
%183 = add nsw i32 %182, 1
store i32 %183, i32* %14
%184 = load i32*, i32** %6
%185 = load i32*, i32** %9
%186 = call i64 @BN_is_prime(i32* %184, i32 1, i32* null, i32* %185, i32* null)
%187 = icmp sle i64 %186, 0
br i1 %187, label %188, label %189
188: ; preds = %181
br label %61
189: ; preds = %181
%190 = load i32*, i32** %7
%191 = load i32, i32* %21
%192 = load i32*, i32** %9
%193 = call i64 @BN_is_prime(i32* %190, i32 %191, i32* null, i32* %192, i32* null)
%194 = icmp ne i64 %193, 0
br i1 %194, label %196, label %195
195: ; preds = %189
br label %61
196: ; preds = %189
%197 = load i32*, i32** %6
%198 = load i32, i32* %21
%199 = sub nsw i32 %198, 1
%200 = load i32*, i32** %9
%201 = call i64 @BN_is_prime(i32* %197, i32 %199, i32* null, i32* %200, i32* null)
%202 = icmp ne i64 %201, 0
br i1 %202, label %204, label %203
203: ; preds = %196
br label %61
204: ; preds = %196
%205 = load i32, i32* @stdout
%206 = load i32, i32* %17
%207 = or i32 %206, 4
%208 = load i32, i32* %18
%209 = load i32, i32* %20
%210 = load i32, i32* %15
%211 = load i32*, i32** %7
%212 = call i64 @qfileout(i32 %205, i32 2, i32 %207, i32 %208, i32 %209, i32 %210, i32* %211)
%213 = icmp sgt i64 0, %212
br i1 %213, label %214, label %215
214: ; preds = %204
br label %218
215: ; preds = %204
%216 = load i32, i32* %13
%217 = add nsw i32 %216, 1
store i32 %217, i32* %13
br label %61
218: ; preds = %214, %61
%219 = call i32 @time(i64* %23)
%220 = load i8*, i8** %11
%221 = call i32 @free(i8* %220)
%222 = load i32*, i32** %7
%223 = call i32 @BN_free(i32* %222)
%224 = load i32*, i32** %6
%225 = call i32 @BN_free(i32* %224)
%226 = load i32*, i32** %9
%227 = call i32 @BN_CTX_free(i32* %226)
%228 = load i32, i32* @stdout
%229 = call i32 @fflush(i32 %228)
%230 = load i32, i32* @stderr
%231 = call i8* @ctime(i64* %23)
%232 = load i32, i32* %13
%233 = load i32, i32* %14
%234 = load i64, i64* %23
%235 = load i64, i64* %22
%236 = sub nsw i64 %234, %235
%237 = call i32 (i32, i8*, i8*, i32, i32, ...) @fprintf(i32 %230, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i8* %231, i32 %232, i32 %233, i64 %236)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"%.24s Final %d Miller-Rabin trials (%x generator)\0A\00"
@stdin = global i32 0
@.str.1 = [2 x i8] c" \00"
@stdout = global i32 0
@.str.2 = [60 x i8] c"%.24s Found %u safe primes of %u candidates in %lu seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = bitcast i32** %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = bitcast i64* %5 to i8*
%10 = bitcast i64* %6 to i8*
%11 = load i8*, i8** %1
%12 = tail call i32 @setprogname(i8* %11)
%13 = icmp slt i32 %0, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = tail call i32 (...) @usage()
br label %16
16: ; preds = %14, %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @strtoul(i8* nocapture %18, i8** null, i32 10)
%20 = icmp sgt i32 %19, 4
%21 = select i1 %20, i32 %19, i32 4
%22 = icmp sgt i32 %0, 2
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32 @strtoul(i8* nocapture %25, i8** null, i32 16)
br label %27
27: ; preds = %23, %16
%28 = phi i32 [ %26, %23 ], [ 0, %16 ]
%29 = call i32 @time(i64* %5)
%30 = call i32* (...) @BN_new()
%31 = call i32* (...) @BN_new()
%32 = call i32* (...) @BN_CTX_new()
%33 = load i32, i32* @stderr
%34 = call i8* @ctime(i64* %5)
%35 = call i32 (i32, i8*, i8*, i32, i32, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %34, i32 %21, i32 %28)
%36 = call i64 @malloc(i64 8293)
%37 = inttoptr i64 %36 to i8*
%38 = getelementptr inbounds i8, i8* %37, i64 14
%39 = icmp slt i32 %28, 1
%40 = add nsw i32 %21, -1
%41 = load i32, i32* @stdin
%42 = call i32* @fgets(i8* %37, i32 8292, i32 %41)
%43 = icmp eq i32* %42, null
br i1 %43, label %131, label %44
44: ; preds = %27, %125
%45 = phi i32 [ %127, %125 ], [ 0, %27 ]
%46 = phi i32 [ %126, %125 ], [ 0, %27 ]
%47 = call i64 @strlen(i8* dereferenceable(1) %37)
%48 = icmp ult i64 %47, 14
br i1 %48, label %125, label %49
49: ; preds = %44
%50 = load i8, i8* %37
switch i8 %50, label %51 [
i8 33, label %125
i8 35, label %125
]
51: ; preds = %49
store i8* %38, i8** %4
%52 = call i32 @strtoul(i8* %38, i8** %4, i32 10)
%53 = load i8*, i8** %4
%54 = call i32 @strtoul(i8* %53, i8** %4, i32 10)
%55 = and i32 %54, 1
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %125
57: ; preds = %51
%58 = load i8*, i8** %4
%59 = call i32 @strtoul(i8* %58, i8** %4, i32 10)
%60 = load i8*, i8** %4
%61 = call i32 @strtoul(i8* %60, i8** %4, i32 10)
%62 = load i8*, i8** %4
%63 = call i32 @strtoul(i8* %62, i8** %4, i32 16)
%64 = load i8*, i8** %4
%65 = call i32 @strspn(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
store i8* %67, i8** %4
%68 = icmp eq i32 %52, 4
br i1 %68, label %69, label %74
69: ; preds = %57
store i32* %31, i32** %3
%70 = call i32 @BN_hex2bn(i32** %3, i8* %67)
%71 = call i32 @BN_lshift(i32* %30, i32* %31, i32 1)
%72 = call i32 @BN_add_word(i32* %30, i64 1)
%73 = add nsw i32 %61, 1
br label %77
74: ; preds = %57
store i32* %30, i32** %3
%75 = call i32 @BN_hex2bn(i32** %3, i8* %67)
%76 = call i32 @BN_rshift(i32* %31, i32* %30, i32 1)
br label %77
77: ; preds = %74, %69
%78 = phi i32 [ 0, %69 ], [ %63, %74 ]
%79 = phi i32 [ %73, %69 ], [ %61, %74 ]
%80 = call i64 @BN_num_bits(i32* %30)
%81 = trunc i64 %80 to i32
%82 = add nsw i32 %79, 1
%83 = icmp ne i32 %82, %81
%84 = icmp slt i32 %79, 511
%85 = or i1 %84, %83
br i1 %85, label %125, label %86
86: ; preds = %77
%87 = and i32 %54, 4
%88 = icmp eq i32 %87, 0
%89 = select i1 %88, i32 0, i32 %59
%90 = add nsw i32 %89, %21
%91 = icmp eq i32 %78, 0
br i1 %91, label %92, label %103
92: ; preds = %86
%93 = call i32 @BN_mod_word(i32* %30, i64 24)
%94 = icmp eq i32 %93, 11
br i1 %94, label %103, label %95
95: ; preds = %92
%96 = call i32 @BN_mod_word(i32* %30, i64 12)
%97 = icmp eq i32 %96, 5
br i1 %97, label %103, label %98
98: ; preds = %95
%99 = call i32 @BN_mod_word(i32* %30, i64 10)
%100 = and i32 %99, -5
%101 = icmp eq i32 %100, 3
%102 = select i1 %101, i32 5, i32 0
br label %103
103: ; preds = %95, %92, %98, %86
%104 = phi i32 [ %102, %98 ], [ %78, %86 ], [ 2, %92 ], [ 3, %95 ]
%105 = icmp eq i32 %28, %104
%106 = select i1 %39, i1 true, i1 %105
br i1 %106, label %107, label %125
107: ; preds = %103
%108 = add nsw i32 %46, 1
%109 = call i64 @BN_is_prime(i32* %31, i32 1, i32* null, i32* %32, i32* null)
%110 = icmp slt i64 %109, 1
br i1 %110, label %125, label %111
111: ; preds = %107
%112 = call i64 @BN_is_prime(i32* %30, i32 %21, i32* null, i32* %32, i32* null)
%113 = icmp eq i64 %112, 0
br i1 %113, label %125, label %114
114: ; preds = %111
%115 = call i64 @BN_is_prime(i32* %31, i32 %40, i32* null, i32* %32, i32* null)
%116 = icmp eq i64 %115, 0
br i1 %116, label %125, label %117
117: ; preds = %114
%118 = load i32, i32* @stdout
%119 = or i32 %54, 4
%120 = call i64 @qfileout(i32 %118, i32 2, i32 %119, i32 %90, i32 %79, i32 %104, i32* %30)
%121 = icmp slt i64 %120, 0
%122 = xor i1 %121, true
%123 = zext i1 %122 to i32
%124 = add nsw i32 %45, %123
br i1 %121, label %131, label %125
125: ; preds = %117, %114, %111, %107, %103, %77, %51, %44, %49, %49
%126 = phi i32 [ %46, %49 ], [ %46, %49 ], [ %46, %44 ], [ %46, %51 ], [ %46, %77 ], [ %46, %103 ], [ %108, %107 ], [ %108, %111 ], [ %108, %114 ], [ %108, %117 ]
%127 = phi i32 [ %45, %49 ], [ %45, %49 ], [ %45, %44 ], [ %45, %51 ], [ %45, %77 ], [ %45, %103 ], [ %45, %107 ], [ %45, %111 ], [ %45, %114 ], [ %124, %117 ]
%128 = load i32, i32* @stdin
%129 = call i32* @fgets(i8* %37, i32 8292, i32 %128)
%130 = icmp eq i32* %129, null
br i1 %130, label %131, label %44
131: ; preds = %125, %117, %27
%132 = phi i32 [ 0, %27 ], [ %126, %125 ], [ %108, %117 ]
%133 = phi i32 [ 0, %27 ], [ %127, %125 ], [ %124, %117 ]
%134 = call i32 @time(i64* %6)
%135 = call i32 @free(i8* %37)
%136 = call i32 @BN_free(i32* %30)
%137 = call i32 @BN_free(i32* %31)
%138 = call i32 @BN_CTX_free(i32* %32)
%139 = load i32, i32* @stdout
%140 = call i32 @fflush(i32 %139)
%141 = load i32, i32* @stderr
%142 = call i8* @ctime(i64* %6)
%143 = load i64, i64* %6
%144 = load i64, i64* %5
%145 = sub nsw i64 %143, %144
%146 = call i32 (i32, i8*, i8*, i32, i32, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i8* %142, i32 %133, i32 %132, i64 %145)
ret i32 0
}