// File: /workspace/github_cpp_makefile_star2_O2/marxn[P]pupp/3rdparty/gmp/gen-trialdivtab.c
// Function: main
int
main (int argc, char *argv[])
{
  unsigned long t, p;
  mpz_t ppp, acc, inv, gmp_numb_max, tmp, Bhalf;
  mpz_t pre[7];
  int i;
  int start_p, end_p, interval_start, interval_end, omitted_p;
  const char *endtok;
  int stop;
  int np, start_idx;

  if (argc < 2)
    {
      fprintf (stderr, "usage: %s bits endprime\n", argv[0]);
      exit (1);
    }

  limb_bits = atoi (argv[1]);

  end_p = 1290;			/* default end prime */
  if (argc == 3)
    end_p = atoi (argv[2]);

  printf ("#if GMP_LIMB_BITS != %d\n", limb_bits);
  printf ("#error This table is for GMP_LIMB_BITS = %d\n", limb_bits);
  printf ("#endif\n\n");

  printf ("#if GMP_NAIL_BITS != 0\n");
  printf ("#error This table does not support nails\n");
  printf ("#endif\n\n");

  for (i = 0; i < 7; i++)
    mpz_init (pre[i]);

  mpz_init_set_ui (gmp_numb_max, 1);
  mpz_mul_2exp (gmp_numb_max, gmp_numb_max, limb_bits);
  mpz_sub_ui (gmp_numb_max, gmp_numb_max, 1);

  mpz_init (tmp);
  mpz_init (inv);

  mpz_init_set_ui (B, 1);  mpz_mul_2exp (B, B, limb_bits);
  mpz_init_set_ui (Bhalf, 1);  mpz_mul_2exp (Bhalf, Bhalf, limb_bits - 1);

  start_p = 3;

  mpz_init_set_ui (ppp, 1);
  mpz_init (acc);
  interval_start = start_p;
  omitted_p = 3;
  interval_end = 0;

/*  printf ("static struct gmp_primes_dtab gmp_primes_dtab[] = {\n"); */

  printf ("#ifdef WANT_dtab\n");

  for (t = start_p; t <= end_p; t += 2)
    {
      if (! isprime (t))
	continue;

      mpz_mul_ui (acc, ppp, t);
      stop = mpz_cmp (acc, Bhalf) >= 0;
      if (!stop)
	{
	  mpn_mod_1s_4p_cps (pre, acc);
	  stop = sumspills (acc, pre + 2, 5);
	}

      if (stop)
	{
	  for (p = interval_start; p <= interval_end; p += 2)
	    {
	      if (! isprime (p))
		continue;

	      printf ("  P(%d,", (int) p);
	      mpz_invert_ui_2exp (inv, p, limb_bits);
	      printf ("CNST_LIMB(0x");  mpz_out_str (stdout, 16, inv);  printf ("),");

	      mpz_tdiv_q_ui (tmp, gmp_numb_max, p);
	      printf ("CNST_LIMB(0x");  mpz_out_str (stdout, 16, tmp);
	      printf (")),\n");
	    }
	  mpz_set_ui (ppp, t);
	  interval_start = t;
	  omitted_p = t;
	}
      else
	{
	  mpz_set (ppp, acc);
	}
      interval_end = t;
    }
  printf ("#define SMALLEST_OMITTED_PRIME %d\n", (int) omitted_p);
  printf ("#endif\n");

  printf ("#ifdef WANT_ptab\n");

/*  printf ("static struct gmp_primes_ptab gmp_primes_ptab[] = {\n"); */

  endtok = "";

  mpz_set_ui (ppp, 1);
  interval_start = start_p;
  interval_end = 0;
  np = 0;
  start_idx = 0;
  for (t = start_p; t <= end_p; t += 2)
    {
      if (! isprime (t))
	continue;

      mpz_mul_ui (acc, ppp, t);

      stop = mpz_cmp (acc, Bhalf) >= 0;
      if (!stop)
	{
	  mpn_mod_1s_4p_cps (pre, acc);
	  stop = sumspills (acc, pre + 2, 5);
	}

      if (stop)
	{
	  mpn_mod_1s_4p_cps (pre, ppp);
	  printf ("%s", endtok);
	  printf ("  {CNST_LIMB(0x");  mpz_out_str (stdout, 16, ppp);
	  printf ("),{CNST_LIMB(0x");  mpz_out_str (stdout, 16, pre[0]);
	  printf ("),%d", (int) PTR(pre[1])[0]);
	  for (i = 0; i < 5; i++)
	    {
	      printf (",");
	      printf ("CNST_LIMB(0x");  mpz_out_str (stdout, 16, pre[2 + i]);
	      printf (")");
	    }
	  printf ("},");
	  printf ("%d,", start_idx);
	  printf ("%d}", np - start_idx);

	  endtok = ",\n";
	  mpz_set_ui (ppp, t);
	  interval_start = t;
	  start_idx = np;
	}
      else
	{
	  mpz_set (ppp, acc);
	}
      interval_end = t;
      np++;
    }

  printf ("\n");
  printf ("#endif\n");

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %r14
cmpl $0x1, %edi
jle 0x7e41
movl %edi, %r15d
movq 0x8(%r14), %rdi
callq 0x10d0
movl %eax, %ebx
movl %eax, 0x680e(%rip)      # 0xe0c0
movl $0x50a, %eax            # imm = 0x50A
movq %rax, -0x50(%rbp)
cmpl $0x3, %r15d
jne 0x78d0
movq 0x10(%r14), %rdi
callq 0x10d0
cltq
movq %rax, -0x50(%rbp)
leaq 0x2225(%rip), %rdi      # 0x9afc
movl %ebx, %esi
xorl %eax, %eax
callq 0x1080
movl 0x67da(%rip), %esi      # 0xe0c0
leaq 0x2228(%rip), %rdi      # 0x9b15
xorl %eax, %eax
callq 0x1080
leaq 0x2b0f(%rip), %rbx      # 0xa40a
movq %rbx, %rdi
callq 0x1060
leaq 0x2ac0(%rip), %rdi      # 0xa3ca
callq 0x1060
leaq 0x2acb(%rip), %rdi      # 0xa3e1
callq 0x1060
movq %rbx, %rdi
callq 0x1060
pushq $0x8
popq %rbx
movq %rbx, %r14
cmpq $0x78, %r14
je 0x7952
movq $0x1, -0x128(%rbp,%r14)
movq %rbx, %rdi
callq *0x6754(%rip)           # 0xe098
movq %rax, -0x120(%rbp,%r14)
addq $0x10, %r14
jmp 0x7929
pushq $0x1
popq %r15
leaq -0x90(%rbp), %r12
movl %r15d, (%r12)
pushq $0x8
popq %rbx
movq %rbx, %rdi
callq *0x672b(%rip)           # 0xe098
movq %rax, 0x8(%r12)
pushq $0x1
popq %r14
movq %r14, (%rax)
movl %r15d, 0x4(%r12)
movslq 0x673b(%rip), %rdx      # 0xe0c0
movq %r12, %rdi
movq %r12, %rsi
callq 0x304c
movq %r12, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2bd7
leaq -0x80(%rbp), %r12
movq %r14, (%r12)
movq %rbx, %rdi
callq *0x66e9(%rip)           # 0xe098
movq %rax, 0x8(%r12)
leaq -0xa0(%rbp), %r12
movq %r14, (%r12)
movq %rbx, %rdi
callq *0x66d0(%rip)           # 0xe098
movq %rax, 0x8(%r12)
movq %r14, 0x66fc(%rip)      # 0xe0d0
leaq 0x66f5(%rip), %r13      # 0xe0d0
movq %rbx, %rdi
callq *0x66b4(%rip)           # 0xe098
movq %rax, 0x66ed(%rip)      # 0xe0d8
movq %r14, (%rax)
movl %r15d, 0x66df(%rip)     # 0xe0d4
movslq 0x66c4(%rip), %rdx      # 0xe0c0
movq %r13, %rdi
movq %r13, %rsi
callq 0x304c
leaq -0x70(%rbp), %r12
movl %r15d, (%r12)
movq %rbx, %rdi
callq *0x6680(%rip)           # 0xe098
movq %rax, 0x8(%r12)
movq %r14, (%rax)
movl %r15d, 0x4(%r12)
movslq 0x6694(%rip), %rdx      # 0xe0c0
decq %rdx
movq %r12, %rdi
movq %r12, %rsi
callq 0x304c
leaq -0x40(%rbp), %r12
movl %r15d, (%r12)
movq %rbx, %rdi
callq *0x664d(%rip)           # 0xe098
movq %rax, 0x8(%r12)
movq %r14, (%rax)
movl %r15d, 0x4(%r12)
leaq -0xb0(%rbp), %r15
movq %r14, (%r15)
movq %rbx, %rdi
callq *0x662d(%rip)           # 0xe098
movq %rax, 0x8(%r15)
leaq 0x299c(%rip), %rdi      # 0xa412
callq 0x1060
pushq $0x3
popq %rbx
pushq $0x3
popq %r14
xorl %r12d, %r12d
movl %ebx, %r13d
cmpq -0x50(%rbp), %r14
ja 0x7bf6
movq %r14, %rdi
callq 0x74dd
testl %eax, %eax
je 0x7bd8
movq %r15, %rdi
leaq -0x40(%rbp), %rsi
movq %r14, -0x48(%rbp)
movq %r14, %rdx
callq 0x2ec3
movq %r15, %rdi
leaq -0x70(%rbp), %rsi
callq 0x2963
testl %eax, %eax
jns 0x7aeb
leaq -0x120(%rbp), %rdi
movq %r15, %rsi
callq 0x7e64
leaq -0x100(%rbp), %rsi
pushq $0x5
popq %rdx
callq 0x817a
testl %eax, %eax
je 0x7be1
movslq %ebx, %rbx
movslq %r12d, %rax
movq %rax, -0x30(%rbp)
cmpq -0x30(%rbp), %rbx
ja 0x7bb5
movq %rbx, %rdi
callq 0x74dd
testl %eax, %eax
je 0x7bac
leaq 0x202c(%rip), %rdi      # 0x9b42
movl %ebx, %esi
xorl %eax, %eax
callq 0x1080
movslq 0x659a(%rip), %rdx      # 0xe0c0
movq %r15, %r13
leaq -0xa0(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7814
leaq 0x2031(%rip), %r12      # 0x9b73
movq %r12, %rdi
xorl %eax, %eax
callq 0x1080
movq 0x6485(%rip), %r14      # 0xdfd8
movq (%r14), %rdi
pushq $0x10
popq %rsi
movq %r15, %rdx
callq 0x7096
leaq 0x28d4(%rip), %rdi      # 0xa43c
xorl %eax, %eax
callq 0x1080
leaq -0x80(%rbp), %r15
movq %r15, %rdi
leaq -0x90(%rbp), %rsi
movq %rbx, %rdx
callq 0x3dfc
movq %r12, %rdi
xorl %eax, %eax
callq 0x1080
movq (%r14), %rdi
pushq $0x10
popq %rsi
movq %r15, %rdx
movq %r13, %r15
callq 0x7096
leaq 0x2894(%rip), %rdi      # 0xa43b
callq 0x1060
addq $0x2, %rbx
jmp 0x7af5
movq -0x48(%rbp), %r14
testq %r14, %r14
je 0x7bca
movq -0x38(%rbp), %rax
movq %r14, (%rax)
pushq $0x1
popq %rax
jmp 0x7bcc
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
movl %r14d, %ebx
movl %r14d, %r12d
movl %r14d, %r13d
addq $0x2, %r14
jmp 0x7a88
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x2236
movq -0x48(%rbp), %r14
movl %r14d, %r12d
jmp 0x7bd8
leaq 0x1f4d(%rip), %rdi      # 0x9b4a
movl %r13d, %esi
xorl %eax, %eax
callq 0x1080
leaq 0x2826(%rip), %rdi      # 0xa434
callq 0x1060
leaq 0x2809(%rip), %rdi      # 0xa423
callq 0x1060
leaq -0x40(%rbp), %r15
movq 0x8(%r15), %rax
movq $0x1, (%rax)
movl $0x1, 0x4(%r15)
leaq 0x1f61(%rip), %rax      # 0x9b9e
movq %rax, -0x58(%rbp)
pushq $0x3
popq %rbx
pushq $0x10
popq %r13
leaq 0x1f24(%rip), %r12      # 0x9b73
pushq $0x29
popq %r14
xorl %eax, %eax
movl $0x0, -0x48(%rbp)
cmpq -0x50(%rbp), %rbx
ja 0x7e19
movl %eax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x74dd
testl %eax, %eax
je 0x7dfc
movq %r15, %rsi
leaq -0xb0(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rdx
callq 0x2ec3
movq %r15, %rdi
leaq -0x70(%rbp), %rsi
callq 0x2963
testl %eax, %eax
jns 0x7cc4
leaq -0x120(%rbp), %rdi
movq %r15, %rsi
callq 0x7e64
leaq -0x100(%rbp), %rsi
pushq $0x5
popq %rdx
callq 0x817a
testl %eax, %eax
je 0x7e08
leaq -0x40(%rbp), %r15
movq %rbx, -0x60(%rbp)
leaq -0x120(%rbp), %rdi
movq %r15, %rsi
callq 0x7e64
leaq 0x1e8b(%rip), %rdi      # 0x9b6d
movq -0x58(%rbp), %rsi
xorl %eax, %eax
callq 0x1080
leaq 0x1e7c(%rip), %rdi      # 0x9b70
xorl %eax, %eax
callq 0x1080
movq 0x62d6(%rip), %rbx      # 0xdfd8
movq (%rbx), %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0x7096
leaq 0x1e69(%rip), %rdi      # 0x9b80
xorl %eax, %eax
callq 0x1080
movq (%rbx), %rdi
movl %r13d, %esi
leaq -0x120(%rbp), %rdx
callq 0x7096
movq -0x108(%rbp), %rax
movl (%rax), %esi
leaq 0x1e50(%rip), %rdi      # 0x9b90
xorl %eax, %eax
callq 0x1080
pushq $0x20
popq %rbx
pushq $0x2c
popq %r15
cmpq $0x70, %rbx
je 0x7d91
movl %r15d, %edi
callq 0x1040
movq %r12, %rdi
xorl %eax, %eax
callq 0x1080
movq 0x626b(%rip), %rax      # 0xdfd8
movq (%rax), %rdi
leaq (%rbx,%rbp), %rdx
addq $-0x120, %rdx           # imm = 0xFEE0
movl %r13d, %esi
callq 0x7096
movl %r14d, %edi
callq 0x1040
addq $0x10, %rbx
jmp 0x7d4e
xorl %ebx, %ebx
leaq 0x1dfb(%rip), %rdi      # 0x9b95
xorl %eax, %eax
callq 0x1080
leaq 0x1d9e(%rip), %rdi      # 0x9b46
movl -0x48(%rbp), %r15d
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
movl -0x30(%rbp), %esi
subl %r15d, %esi
leaq 0x1dd5(%rip), %rdi      # 0x9b98
xorl %eax, %eax
callq 0x1080
movq -0x60(%rbp), %r15
testq %r15, %r15
je 0x7ddd
movq -0x38(%rbp), %rax
movq %r15, (%rax)
pushq $0x1
popq %rbx
movl %ebx, -0x3c(%rbp)
leaq 0x1db5(%rip), %rax      # 0x9b9c
movq %rax, -0x58(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x48(%rbp)
movq %r15, %rbx
leaq -0x40(%rbp), %r15
incl %eax
jmp 0x7dff
movl -0x30(%rbp), %eax
addq $0x2, %rbx
jmp 0x7c5c
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x2236
movl -0x30(%rbp), %eax
jmp 0x7df4
pushq $0xa
popq %rdi
callq 0x1040
leaq 0x260c(%rip), %rdi      # 0xa434
callq 0x1060
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x61b0(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq (%r14), %rdx
leaq 0x1c8e(%rip), %rsi      # 0x9ae3
xorl %eax, %eax
callq 0x10a0
pushq $0x1
popq %rdi
callq 0x10e0