// File: /workspace/github_cpp_makefile_star2_O1/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 0x900f
movl %edi, %r15d
movq 0x8(%r14), %rdi
callq 0x10e0
movl %eax, %ebx
movl %eax, 0x667c(%rip)      # 0xf0d0
movl $0x50a, %eax            # imm = 0x50A
movq %rax, -0x50(%rbp)
cmpl $0x3, %r15d
jne 0x8a72
movq 0x10(%r14), %rdi
callq 0x10e0
cltq
movq %rax, -0x50(%rbp)
leaq 0x2083(%rip), %rdi      # 0xaafc
movl %ebx, %esi
xorl %eax, %eax
callq 0x1080
movl 0x6648(%rip), %esi      # 0xf0d0
leaq 0x2086(%rip), %rdi      # 0xab15
xorl %eax, %eax
callq 0x1080
leaq 0x2975(%rip), %rbx      # 0xb412
movq %rbx, %rdi
callq 0x1060
leaq 0x2926(%rip), %rdi      # 0xb3d2
callq 0x1060
leaq 0x2931(%rip), %rdi      # 0xb3e9
callq 0x1060
movq %rbx, %rdi
callq 0x1060
movl $0x8, %ebx
movq $0x1, -0x128(%rbp,%rbx)
movl $0x8, %edi
callq *0x65bf(%rip)           # 0xf0a0
movq %rax, -0x120(%rbp,%rbx)
addq $0x10, %rbx
cmpq $0x78, %rbx
jne 0x8aca
movl $0x1, %r14d
leaq -0xb0(%rbp), %rbx
movq %r14, (%rbx)
movl $0x8, %edi
callq *0x6592(%rip)           # 0xf0a0
movq %rax, 0x8(%rbx)
movl $0x1, %r15d
movl %r15d, 0x4(%rbx)
movq %r14, (%rax)
movslq 0x65aa(%rip), %rdx      # 0xf0d0
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x364f
movl $0x1, %edx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x3076
movq %r14, -0x90(%rbp)
movl $0x8, %edi
callq *0x654d(%rip)           # 0xf0a0
movq %rax, -0x88(%rbp)
movq %r14, -0xa0(%rbp)
movl $0x8, %edi
callq *0x6534(%rip)           # 0xf0a0
movq %rax, -0x98(%rbp)
movq %r14, 0x6566(%rip)      # 0xf0e0
leaq 0x655f(%rip), %rbx      # 0xf0e0
movl $0x8, %edi
callq *0x6514(%rip)           # 0xf0a0
movq %rax, 0x6555(%rip)      # 0xf0e8
movl %r15d, 0x654a(%rip)     # 0xf0e4
movq %r14, (%rax)
movslq 0x652c(%rip), %rdx      # 0xf0d0
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x364f
leaq -0x80(%rbp), %rbx
movq %r14, (%rbx)
movl $0x8, %edi
callq *0x64df(%rip)           # 0xf0a0
movq %rax, 0x8(%rbx)
movl %r15d, 0x4(%rbx)
movq %r14, (%rax)
movslq 0x64fd(%rip), %rdx      # 0xf0d0
decq %rdx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x364f
movq %r14, -0x40(%rbp)
movl $0x8, %edi
callq *0x64b0(%rip)           # 0xf0a0
movq %rax, -0x38(%rbp)
movl %r15d, -0x3c(%rbp)
movq %r14, (%rax)
movq %r14, -0x60(%rbp)
movl $0x8, %edi
callq *0x6496(%rip)           # 0xf0a0
movq %rax, -0x58(%rbp)
leaq 0x2805(%rip), %rdi      # 0xb41a
callq 0x1060
movl $0x3, %r14d
cmpq $0x3, -0x50(%rbp)
jb 0x8dc3
movl $0x3, %ebx
leaq -0x60(%rbp), %r13
xorl %r15d, %r15d
movl $0x3, %r12d
movq %rbx, %rdi
callq 0x85fe
testl %eax, %eax
je 0x8db5
movq %r13, %rdi
leaq -0x40(%rbp), %rsi
movq %rbx, -0x48(%rbp)
movq %rbx, %rdx
callq 0x3464
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
callq 0x2d1a
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
setns %cl
js 0x8c7b
movb %cl, %al
jmp 0x8c9b
leaq -0x120(%rbp), %rdi
movq %r13, %rsi
callq 0x9017
leaq -0x100(%rbp), %rsi
movl $0x5, %edx
callq 0x938b
testl %eax, %eax
je 0x8d8f
cmpl %r15d, %r12d
ja 0x8d76
movslq %r15d, %r13
movslq %r12d, %r15
movq %r15, %rdi
callq 0x85fe
testl %eax, %eax
je 0x8d69
leaq 0x1e79(%rip), %rdi      # 0xab42
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
movslq 0x63f6(%rip), %rdx      # 0xf0d0
leaq -0xa0(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x89ad
leaq 0x1e80(%rip), %r14      # 0xab73
movq %r14, %rdi
xorl %eax, %eax
callq 0x1080
movq 0x62d4(%rip), %rbx      # 0xefd8
movq (%rbx), %rdi
movl $0x10, %esi
movq %r12, %rdx
callq 0x8146
leaq 0x2729(%rip), %rdi      # 0xb444
xorl %eax, %eax
callq 0x1080
leaq -0x90(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
leaq -0xb0(%rbp), %rdx
movq %r15, %rcx
movl $0x2, %r8d
callq 0x43f9
movq %r14, %rdi
xorl %eax, %eax
callq 0x1080
movq (%rbx), %rdi
movl $0x10, %esi
movq %r12, %rdx
callq 0x8146
leaq 0x26df(%rip), %rdi      # 0xb443
callq 0x1060
addq $0x2, %r15
cmpq %r13, %r15
jbe 0x8cb2
movq -0x48(%rbp), %rbx
testq %rbx, %rbx
je 0x8da1
movl $0x1, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movq %rbx, (%rax)
jmp 0x8da8
leaq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0x249e
movq -0x48(%rbp), %rbx
jmp 0x8db2
movl $0x0, -0x3c(%rbp)
leaq -0x60(%rbp), %r13
movl %ebx, %r12d
movl %ebx, %r14d
movl %ebx, %r15d
addq $0x2, %rbx
cmpq -0x50(%rbp), %rbx
jbe 0x8c3d
leaq 0x1d80(%rip), %rdi      # 0xab4a
movl %r14d, %esi
xorl %eax, %eax
callq 0x1080
leaq 0x2661(%rip), %rdi      # 0xb43c
callq 0x1060
leaq 0x2644(%rip), %rdi      # 0xb42b
callq 0x1060
movl $0x1, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movq $0x1, (%rax)
cmpq $0x3, -0x50(%rbp)
jb 0x8fe5
movl $0x3, %ebx
leaq 0x1d89(%rip), %rax      # 0xab9e
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %r12
movq 0x61b4(%rip), %r15      # 0xefd8
leaq 0x1d48(%rip), %r13      # 0xab73
movl $0x0, -0x48(%rbp)
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x85fe
testl %eax, %eax
je 0x8fd7
movq %r12, %rdi
leaq -0x40(%rbp), %rsi
movq %rbx, %rdx
callq 0x3464
movq %r12, %rdi
leaq -0x80(%rbp), %rsi
callq 0x2d1a
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
setns %cl
js 0x8e6f
movb %cl, %al
jmp 0x8e8f
leaq -0x120(%rbp), %rdi
movq %r12, %rsi
callq 0x9017
leaq -0x100(%rbp), %rsi
movl $0x5, %edx
callq 0x938b
testl %eax, %eax
je 0x8fac
movl %r14d, -0x6c(%rbp)
leaq -0x120(%rbp), %r14
movq %r14, %rdi
leaq -0x40(%rbp), %r12
movq %r12, %rsi
callq 0x9017
leaq 0x1cb5(%rip), %rdi      # 0xab6d
movq -0x68(%rbp), %rsi
xorl %eax, %eax
callq 0x1080
leaq 0x1ca6(%rip), %rdi      # 0xab70
xorl %eax, %eax
callq 0x1080
movq (%r15), %rdi
movl $0x10, %esi
movq %r12, %rdx
callq 0x8146
leaq 0x1c98(%rip), %rdi      # 0xab80
xorl %eax, %eax
callq 0x1080
movq (%r15), %rdi
movl $0x10, %esi
movq %r14, %rdx
callq 0x8146
movq -0x108(%rbp), %rax
movl (%rax), %esi
leaq 0x1c81(%rip), %rdi      # 0xab90
xorl %eax, %eax
callq 0x1080
movl $0x20, %r12d
movl $0x2c, %edi
callq 0x1040
movq %r13, %rdi
xorl %eax, %eax
callq 0x1080
movq (%r15), %rdi
leaq (%r12,%rbp), %rdx
addq $-0x120, %rdx           # imm = 0xFEE0
movl $0x10, %esi
callq 0x8146
movl $0x29, %edi
callq 0x1040
addq $0x10, %r12
cmpq $0x70, %r12
jne 0x8f1c
leaq 0x1c32(%rip), %rdi      # 0xab95
xorl %eax, %eax
callq 0x1080
leaq 0x1bd5(%rip), %rdi      # 0xab46
movl -0x48(%rbp), %r12d
movl %r12d, %esi
xorl %eax, %eax
callq 0x1080
movl -0x6c(%rbp), %r14d
movl %r14d, %esi
subl %r12d, %esi
leaq 0x1c08(%rip), %rdi      # 0xab98
xorl %eax, %eax
callq 0x1080
testq %rbx, %rbx
je 0x8fba
movl $0x1, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movq %rbx, (%rax)
jmp 0x8fc1
leaq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0x249e
jmp 0x8fd4
movl $0x0, -0x3c(%rbp)
leaq 0x1bd4(%rip), %rax      # 0xab9c
movq %rax, -0x68(%rbp)
movl %r14d, -0x48(%rbp)
leaq -0x60(%rbp), %r12
incl %r14d
addq $0x2, %rbx
cmpq -0x50(%rbp), %rbx
jbe 0x8e35
movl $0xa, %edi
callq 0x1040
leaq 0x2446(%rip), %rdi      # 0xb43c
callq 0x1060
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x1298