// File: marxn[P]pupp/3rdparty/gmp/mpn/get_str.c
// Function: mpn_sb_get_str
static unsigned char *
mpn_sb_get_str (unsigned char *str, size_t len,
		mp_ptr up, mp_size_t un, int base)
{
  mp_limb_t rl, ul;
  unsigned char *s;
  size_t l;
  /* Allocate memory for largest possible string, given that we only get here
     for operands with un < GET_STR_PRECOMPUTE_THRESHOLD and that the smallest
     base is 3.  7/11 is an approximation to 1/log2(3).  */
#if TUNE_PROGRAM_BUILD
#define BUF_ALLOC (GET_STR_THRESHOLD_LIMIT * GMP_LIMB_BITS * 7 / 11)
#else
#define BUF_ALLOC (GET_STR_PRECOMPUTE_THRESHOLD * GMP_LIMB_BITS * 7 / 11)
#endif
  unsigned char buf[BUF_ALLOC];
#if TUNE_PROGRAM_BUILD
  mp_limb_t rp[GET_STR_THRESHOLD_LIMIT];
#else
  mp_limb_t rp[GET_STR_PRECOMPUTE_THRESHOLD];
#endif

  if (base == 10)
    {
      /* Special case code for base==10 so that the compiler has a chance to
	 optimize things.  */

      MPN_COPY (rp + 1, up, un);

      s = buf + BUF_ALLOC;
      while (un > 1)
	{
	  int i;
	  mp_limb_t frac, digit;
	  MPN_DIVREM_OR_PREINV_DIVREM_1 (rp, (mp_size_t) 1, rp + 1, un,
					 MP_BASES_BIG_BASE_10,
					 MP_BASES_BIG_BASE_INVERTED_10,
					 MP_BASES_NORMALIZATION_STEPS_10);
	  un -= rp[un] == 0;
	  frac = (rp[0] + 1) << GMP_NAIL_BITS;
	  s -= MP_BASES_CHARS_PER_LIMB_10;
#if HAVE_HOST_CPU_FAMILY_x86
	  /* The code below turns out to be a bit slower for x86 using gcc.
	     Use plain code.  */
	  i = MP_BASES_CHARS_PER_LIMB_10;
	  do
	    {
	      umul_ppmm (digit, frac, frac, 10);
	      *s++ = digit;
	    }
	  while (--i);
#else
	  /* Use the fact that 10 in binary is 1010, with the lowest bit 0.
	     After a few umul_ppmm, we will have accumulated enough low zeros
	     to use a plain multiply.  */
	  if (MP_BASES_NORMALIZATION_STEPS_10 == 0)
	    {
	      umul_ppmm (digit, frac, frac, 10);
	      *s++ = digit;
	    }
	  if (MP_BASES_NORMALIZATION_STEPS_10 <= 1)
	    {
	      umul_ppmm (digit, frac, frac, 10);
	      *s++ = digit;
	    }
	  if (MP_BASES_NORMALIZATION_STEPS_10 <= 2)
	    {
	      umul_ppmm (digit, frac, frac, 10);
	      *s++ = digit;
	    }
	  if (MP_BASES_NORMALIZATION_STEPS_10 <= 3)
	    {
	      umul_ppmm (digit, frac, frac, 10);
	      *s++ = digit;
	    }
	  i = (MP_BASES_CHARS_PER_LIMB_10 - ((MP_BASES_NORMALIZATION_STEPS_10 < 4)
					     ? (4-MP_BASES_NORMALIZATION_STEPS_10)
					     : 0));
	  frac = (frac + 0xf) >> 4;
	  do
	    {
	      frac *= 10;
	      digit = frac >> (GMP_LIMB_BITS - 4);
	      *s++ = digit;
	      frac &= (~(mp_limb_t) 0) >> 4;
	    }
	  while (--i);
#endif
	  s -= MP_BASES_CHARS_PER_LIMB_10;
	}

      ul = rp[1];
      while (ul != 0)
	{
	  udiv_qrnd_unnorm (ul, rl, ul, 10);
	  *--s = rl;
	}
    }
  else /* not base 10 */
    {
      unsigned chars_per_limb;
      mp_limb_t big_base, big_base_inverted;
      unsigned normalization_steps;

      chars_per_limb = mp_bases[base].chars_per_limb;
      big_base = mp_bases[base].big_base;
      big_base_inverted = mp_bases[base].big_base_inverted;
      count_leading_zeros (normalization_steps, big_base);

      MPN_COPY (rp + 1, up, un);

      s = buf + BUF_ALLOC;
      while (un > 1)
	{
	  int i;
	  mp_limb_t frac;
	  MPN_DIVREM_OR_PREINV_DIVREM_1 (rp, (mp_size_t) 1, rp + 1, un,
					 big_base, big_base_inverted,
					 normalization_steps);
	  un -= rp[un] == 0;
	  frac = (rp[0] + 1) << GMP_NAIL_BITS;
	  s -= chars_per_limb;
	  i = chars_per_limb;
	  do
	    {
	      mp_limb_t digit;
	      umul_ppmm (digit, frac, frac, base);
	      *s++ = digit;
	    }
	  while (--i);
	  s -= chars_per_limb;
	}

      ul = rp[1];
      while (ul != 0)
	{
	  udiv_qrnd_unnorm (ul, rl, ul, base);
	  *--s = rl;
	}
    }

  l = buf + BUF_ALLOC - s;
  while (l < len)
    {
      *str++ = 0;
      len--;
    }
  while (l != 0)
    {
      *str++ = *s++;
      l--;
    }
  return str;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x670, %rsp            # imm = 0x670
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
cmpl $0xa, -0x24(%rbp)
jne 0x5e835
jmp 0x5e58b
jmp 0x5e58d
jmp 0x5e58f
jmp 0x5e591
jmp 0x5e593
jmp 0x5e595
jmp 0x5e597
jmp 0x5e599
leaq -0x5e0(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x554c6
jmp 0x5e5b3
leaq -0x4f0(%rbp), %rax
addq $0x49d, %rax            # imm = 0x49D
movq %rax, -0x40(%rbp)
cmpq $0x1, -0x20(%rbp)
jle 0x5e7c1
leaq -0x5e0(%rbp), %rdi
leaq -0x5e0(%rbp), %rdx
addq $0x8, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
movabsq $-0x7538dcfb76180000, %r8 # imm = 0x8AC7230489E80000
movabsq $-0x27c36b0492d53cb6, %r9 # imm = 0xD83C94FB6D2AC34A
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x37b70
movq -0x20(%rbp), %rax
cmpq $0x0, -0x5e0(%rbp,%rax,8)
sete %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x5e0(%rbp), %rax
addq $0x1, %rax
shlq $0x0, %rax
movq %rax, -0x5f0(%rbp)
movq -0x40(%rbp), %rax
addq $-0x13, %rax
movq %rax, -0x40(%rbp)
movq -0x5f0(%rbp), %rax
mulq 0x65d9(%rip)            # 0x64c38
movq %rax, -0x5f0(%rbp)
movq %rdx, -0x5f8(%rbp)
movq -0x5f8(%rbp), %rax
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movq -0x5f0(%rbp), %rax
mulq 0x65a3(%rip)            # 0x64c38
movq %rax, -0x5f0(%rbp)
movq %rdx, -0x5f8(%rbp)
movq -0x5f8(%rbp), %rax
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movq -0x5f0(%rbp), %rax
mulq 0x656d(%rip)            # 0x64c38
movq %rax, -0x5f0(%rbp)
movq %rdx, -0x5f8(%rbp)
movq -0x5f8(%rbp), %rax
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movq -0x5f0(%rbp), %rax
mulq 0x6537(%rip)            # 0x64c38
movq %rax, -0x5f0(%rbp)
movq %rdx, -0x5f8(%rbp)
movq -0x5f8(%rbp), %rax
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl $0xf, -0x5e4(%rbp)
movq -0x5f0(%rbp), %rax
addq $0xf, %rax
shrq $0x4, %rax
movq %rax, -0x5f0(%rbp)
imulq $0xa, -0x5f0(%rbp), %rax
movq %rax, -0x5f0(%rbp)
movq -0x5f0(%rbp), %rax
shrq $0x3c, %rax
movq %rax, -0x5f8(%rbp)
movq -0x5f8(%rbp), %rax
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movabsq $0xfffffffffffffff, %rax # imm = 0xFFFFFFFFFFFFFFF
andq -0x5f0(%rbp), %rax
movq %rax, -0x5f0(%rbp)
movl -0x5e4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x5e4(%rbp)
cmpl $0x0, %eax
jne 0x5e749
movq -0x40(%rbp), %rax
addq $-0x13, %rax
movq %rax, -0x40(%rbp)
jmp 0x5e5c4
movq -0x5d8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x5e830
jmp 0x5e7d5
movq -0x38(%rbp), %rax
movl $0xa, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x600(%rbp)
movq -0x38(%rbp), %rax
imulq $0xa, -0x600(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x608(%rbp)
movq -0x600(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x608(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $-0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, -0x1(%rax)
jmp 0x5e7cc
jmp 0x5ea82
movslq -0x24(%rbp), %rcx
leaq 0x2a20(%rip), %rax      # 0x61260
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x60c(%rbp)
movslq -0x24(%rbp), %rcx
leaq 0x2a06(%rip), %rax      # 0x61260
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq %rax, -0x618(%rbp)
movslq -0x24(%rbp), %rcx
leaq 0x29e9(%rip), %rax      # 0x61260
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq %rax, -0x620(%rbp)
jmp 0x5e88b
jmp 0x5e88d
movq -0x618(%rbp), %rax
movq %rax, -0x660(%rbp)
bsrq -0x660(%rbp), %rax
movq %rax, -0x630(%rbp)
movq -0x630(%rbp), %rax
xorq $0x3f, %rax
movl %eax, -0x624(%rbp)
jmp 0x5e8bd
jmp 0x5e8bf
jmp 0x5e8c1
jmp 0x5e8c3
jmp 0x5e8c5
jmp 0x5e8c7
jmp 0x5e8c9
jmp 0x5e8cb
leaq -0x5e0(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x554c6
jmp 0x5e8e5
leaq -0x4f0(%rbp), %rax
addq $0x49d, %rax            # imm = 0x49D
movq %rax, -0x40(%rbp)
cmpq $0x1, -0x20(%rbp)
jle 0x5ea0b
leaq -0x5e0(%rbp), %rdi
leaq -0x5e0(%rbp), %rdx
addq $0x8, %rdx
movq -0x20(%rbp), %rcx
movq -0x618(%rbp), %r8
movq -0x620(%rbp), %r9
movl -0x624(%rbp), %eax
movl $0x1, %esi
movl %eax, (%rsp)
callq 0x37b70
movq -0x20(%rbp), %rax
cmpq $0x0, -0x5e0(%rbp,%rax,8)
sete %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x5e0(%rbp), %rax
addq $0x1, %rax
shlq $0x0, %rax
movq %rax, -0x640(%rbp)
movl -0x60c(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x60c(%rbp), %eax
movl %eax, -0x634(%rbp)
movq -0x640(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq %rcx, -0x668(%rbp)
mulq -0x668(%rbp)
movq %rax, -0x640(%rbp)
movq %rdx, -0x648(%rbp)
movq -0x648(%rbp), %rax
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movl -0x634(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x634(%rbp)
cmpl $0x0, %eax
jne 0x5e997
movl -0x60c(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0x5e8f6
movq -0x5d8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x5ea80
jmp 0x5ea1f
movq -0x38(%rbp), %rax
movslq -0x24(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, -0x650(%rbp)
movq -0x38(%rbp), %rax
movq -0x650(%rbp), %rcx
movslq -0x24(%rbp), %rdx
imulq %rdx, %rcx
subq %rcx, %rax
movq %rax, -0x658(%rbp)
movq -0x650(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x658(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $-0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, -0x1(%rax)
jmp 0x5ea16
jmp 0x5ea82
leaq -0x4f0(%rbp), %rax
addq $0x49d, %rax            # imm = 0x49D
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x5eac4
movq -0x8(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x8(%rbp)
movb $0x0, (%rax)
movq -0x10(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x5ea9a
jmp 0x5eac6
cmpq $0x0, -0x48(%rbp)
je 0x5eafd
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movb (%rax), %cl
movq -0x8(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x8(%rbp)
movb %cl, (%rax)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x5eac6
movq -0x8(%rbp), %rax
addq $0x670, %rsp            # imm = 0x670
popq %rbp
retq
nopw (%rax,%rax)