// File: /workspace/github_cpp_makefile_star2_O3/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 0x8ecb
movl %edi, %r15d
movq 0x8(%r14), %rdi
callq 0x10e0
movl %eax, %ebx
movl %eax, 0x67e6(%rip)      # 0xf0d0
movl $0x50a, %eax            # imm = 0x50A
movq %rax, -0x50(%rbp)
cmpl $0x3, %r15d
jne 0x8908
movq 0x10(%r14), %rdi
callq 0x10e0
cltq
movq %rax, -0x50(%rbp)
leaq 0x21ed(%rip), %rdi      # 0xaafc
movl %ebx, %esi
xorl %eax, %eax
callq 0x1080
movl 0x67b2(%rip), %esi      # 0xf0d0
leaq 0x21f0(%rip), %rdi      # 0xab15
xorl %eax, %eax
callq 0x1080
leaq 0x2ad7(%rip), %rbx      # 0xb40a
movq %rbx, %rdi
callq 0x1060
leaq 0x2a88(%rip), %rdi      # 0xb3ca
callq 0x1060
leaq 0x2a93(%rip), %rdi      # 0xb3e1
callq 0x1060
movq %rbx, %rdi
callq 0x1060
movl $0x8, %ebx
movq $0x1, -0x128(%rbp,%rbx)
movl $0x8, %edi
callq *0x6729(%rip)           # 0xf0a0
movq %rax, -0x120(%rbp,%rbx)
addq $0x10, %rbx
cmpq $0x78, %rbx
jne 0x8960
movl $0x1, %r14d
leaq -0xb0(%rbp), %rbx
movl %r14d, (%rbx)
movl $0x8, %edi
callq *0x66fc(%rip)           # 0xf0a0
movq %rax, 0x8(%rbx)
movl $0x1, %r15d
movq %r15, (%rax)
movl %r14d, 0x4(%rbx)
movslq 0x6714(%rip), %rdx      # 0xf0d0
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x360c
movl $0x1, %edx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x303d
movq %r15, -0x90(%rbp)
movl $0x8, %edi
callq *0x66b7(%rip)           # 0xf0a0
movq %rax, -0x88(%rbp)
movq %r15, -0xa0(%rbp)
movl $0x8, %edi
callq *0x669e(%rip)           # 0xf0a0
movq %rax, -0x98(%rbp)
movq %r15, 0x66d0(%rip)      # 0xf0e0
leaq 0x66c9(%rip), %rbx      # 0xf0e0
movl $0x8, %edi
callq *0x667e(%rip)           # 0xf0a0
movq %rax, 0x66bf(%rip)      # 0xf0e8
movq %r15, (%rax)
movl %r14d, 0x66b1(%rip)     # 0xf0e4
movslq 0x6696(%rip), %rdx      # 0xf0d0
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x360c
leaq -0x80(%rbp), %rbx
movl %r14d, (%rbx)
movl $0x8, %edi
callq *0x6649(%rip)           # 0xf0a0
movq %rax, 0x8(%rbx)
movq %r15, (%rax)
movl %r14d, 0x4(%rbx)
movslq 0x6667(%rip), %rdx      # 0xf0d0
decq %rdx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x360c
movl %r14d, -0x40(%rbp)
movl $0x8, %edi
callq *0x661a(%rip)           # 0xf0a0
movq %rax, -0x38(%rbp)
movq %r15, (%rax)
movl %r14d, -0x3c(%rbp)
movq %r15, -0x70(%rbp)
movl $0x8, %edi
callq *0x6600(%rip)           # 0xf0a0
movq %rax, -0x68(%rbp)
leaq 0x2967(%rip), %rdi      # 0xb412
callq 0x1060
cmpq $0x3, -0x50(%rbp)
jae 0x8af9
leaq 0x208c(%rip), %rdi      # 0xab4a
movl $0x3, %esi
xorl %eax, %eax
callq 0x1080
leaq 0x2963(%rip), %rdi      # 0xb434
callq 0x1060
leaq 0x2946(%rip), %rdi      # 0xb423
callq 0x1060
movq -0x38(%rbp), %rax
movq $0x1, (%rax)
movl $0x1, -0x3c(%rbp)
jmp 0x8ccd
movl $0x3, %ebx
movl $0x3, %r14d
xorl %r13d, %r13d
movl $0x3, %r15d
movq %rbx, %rdi
callq 0x8499
testl %eax, %eax
je 0x8c66
leaq -0x70(%rbp), %r12
movq %r12, %rdi
leaq -0x40(%rbp), %rsi
movq %rbx, -0x48(%rbp)
movq %rbx, %rdx
callq 0x3421
movq %r12, %rdi
leaq -0x80(%rbp), %rsi
callq 0x2cdb
testl %eax, %eax
jns 0x8b6c
leaq -0x120(%rbp), %rdi
movq %r12, %rsi
callq 0x8ed3
leaq -0x100(%rbp), %rsi
movl $0x5, %edx
callq 0x924f
testl %eax, %eax
je 0x8c76
cmpl %r13d, %r15d
ja 0x8c41
movslq %r13d, %r13
movslq %r15d, %r15
movq %r15, %rdi
callq 0x8499
testl %eax, %eax
je 0x8c34
leaq 0x1fb0(%rip), %rdi      # 0xab42
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
movslq 0x652d(%rip), %rdx      # 0xf0d0
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x8848
leaq 0x1fb7(%rip), %rbx      # 0xab73
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1080
movq 0x640b(%rip), %r12      # 0xefd8
movq (%r12), %rdi
movl $0x10, %esi
movq %r14, %rdx
callq 0x7fdf
leaq 0x2857(%rip), %rdi      # 0xb43c
xorl %eax, %eax
callq 0x1080
leaq -0x90(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
leaq -0xb0(%rbp), %rdx
movq %r15, %rcx
movl $0x2, %r8d
callq 0x4387
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1080
movq (%r12), %rdi
movl $0x10, %esi
movq %r14, %rdx
callq 0x7fdf
leaq 0x280c(%rip), %rdi      # 0xb43b
callq 0x1060
addq $0x2, %r15
cmpq %r13, %r15
jbe 0x8b7b
movq -0x48(%rbp), %rbx
testq %rbx, %rbx
je 0x8c58
movq -0x38(%rbp), %rax
movq %rbx, (%rax)
movl $0x1, %eax
jmp 0x8c5a
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
movl %ebx, %r15d
movl %ebx, %r13d
movl %ebx, %r14d
addq $0x2, %rbx
cmpq -0x50(%rbp), %rbx
jbe 0x8b0d
jmp 0x8c8b
leaq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0x2482
movq -0x48(%rbp), %rbx
movl %ebx, %r13d
jmp 0x8c66
leaq 0x1eb8(%rip), %rdi      # 0xab4a
movl %r14d, %esi
xorl %eax, %eax
callq 0x1080
leaq 0x2791(%rip), %rdi      # 0xb434
callq 0x1060
leaq 0x2774(%rip), %rdi      # 0xb423
callq 0x1060
movq -0x38(%rbp), %rax
movq $0x1, (%rax)
movl $0x1, -0x3c(%rbp)
cmpq $0x3, -0x50(%rbp)
jae 0x8cf7
movl $0xa, %edi
callq 0x1040
leaq 0x2756(%rip), %rdi      # 0xb434
callq 0x1060
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x3, %ebx
leaq 0x1e9b(%rip), %rax      # 0xab9e
movq %rax, -0x60(%rbp)
leaq -0x70(%rbp), %r12
leaq 0x1e61(%rip), %r13      # 0xab73
movl $0x0, -0x48(%rbp)
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x8499
testl %eax, %eax
je 0x8eab
movq %r12, %rdi
leaq -0x40(%rbp), %r15
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3421
movq %r12, %rdi
leaq -0x80(%rbp), %rsi
callq 0x2cdb
testl %eax, %eax
jns 0x8d76
leaq -0x120(%rbp), %rdi
movq %r12, %rsi
callq 0x8ed3
leaq -0x100(%rbp), %rsi
movl $0x5, %edx
callq 0x924f
testl %eax, %eax
je 0x8ebe
movl %r14d, -0x54(%rbp)
leaq -0x120(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x8ed3
leaq 0x1dda(%rip), %rdi      # 0xab6d
movq -0x60(%rbp), %rsi
xorl %eax, %eax
callq 0x1080
leaq 0x1dcb(%rip), %rdi      # 0xab70
xorl %eax, %eax
callq 0x1080
movq 0x6225(%rip), %r12      # 0xefd8
movq (%r12), %rdi
movl $0x10, %esi
movq %r15, %rdx
callq 0x7fdf
leaq 0x1db5(%rip), %rdi      # 0xab80
xorl %eax, %eax
callq 0x1080
movq (%r12), %rdi
movl $0x10, %esi
movq %r14, %rdx
callq 0x7fdf
movq -0x108(%rbp), %rax
movl (%rax), %esi
leaq 0x1d9d(%rip), %rdi      # 0xab90
xorl %eax, %eax
callq 0x1080
movl $0x20, %r15d
movl $0x2c, %edi
callq 0x1040
movq %r13, %rdi
xorl %eax, %eax
callq 0x1080
movq (%r12), %rdi
leaq (%r15,%rbp), %rdx
addq $-0x120, %rdx           # imm = 0xFEE0
movl $0x10, %esi
callq 0x7fdf
movl $0x29, %edi
callq 0x1040
addq $0x10, %r15
cmpq $0x70, %r15
jne 0x8e00
xorl %r15d, %r15d
leaq 0x1d4a(%rip), %rdi      # 0xab95
xorl %eax, %eax
callq 0x1080
leaq 0x1ced(%rip), %rdi      # 0xab46
movl -0x48(%rbp), %r12d
movl %r12d, %esi
xorl %eax, %eax
callq 0x1080
movl -0x54(%rbp), %r14d
movl %r14d, %esi
subl %r12d, %esi
leaq 0x1d20(%rip), %rdi      # 0xab98
xorl %eax, %eax
callq 0x1080
testq %rbx, %rbx
je 0x8e91
movq -0x38(%rbp), %rax
movq %rbx, (%rax)
movl $0x1, %r15d
movl %r15d, -0x3c(%rbp)
leaq 0x1d00(%rip), %rax      # 0xab9c
movq %rax, -0x60(%rbp)
movl %r14d, -0x48(%rbp)
leaq -0x70(%rbp), %r12
incl %r14d
addq $0x2, %rbx
cmpq -0x50(%rbp), %rbx
jbe 0x8d1c
jmp 0x8ccd
movq %r15, %rdi
movq %r12, %rsi
callq 0x2482
jmp 0x8ea8
movq %r14, %rdi
callq 0x1298