// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5d8, %rsp            # imm = 0x5D8
movq %rcx, %r15
movq %rsi, %r14
movq %rdi, %rbx
cmpl $0xa, %r8d
jne 0x2e244
leaq 0x48(%rsp), %rdi
movq %rdx, %rsi
movq %r15, %rdx
callq 0x290c6
leaq 0x5cd(%rsp), %rbp
pushq $-0xf
popq %r12
movabsq $0xffffffffffffffe, %r13 # imm = 0xFFFFFFFFFFFFFFE
cmpq $0x2, %r15
jl 0x2e320
andl $0x0, (%rsp)
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x48(%rsp), %rdx
movq %r15, %rcx
movabsq $-0x7538dcfb76180000, %r8 # imm = 0x8AC7230489E80000
movabsq $-0x27c36b0492d53cb6, %r9 # imm = 0xD83C94FB6D2AC34A
callq 0x186d0
cmpq $0x1, 0x40(%rsp,%r15,8)
movl $0x0, %ecx
sbbq %rcx, %rcx
movq 0x40(%rsp), %rax
incq %rax
mulq 0x66c5(%rip)            # 0x348b8
movb %dl, -0x13(%rbp)
mulq 0x66bb(%rip)            # 0x348b8
movb %dl, -0x12(%rbp)
mulq 0x66b1(%rip)            # 0x348b8
movb %dl, -0x11(%rbp)
mulq 0x66a7(%rip)            # 0x348b8
movb %dl, -0x10(%rbp)
addq $0xf, %rax
shrq $0x4, %rax
addq $-0x22, %rbp
movl %r12d, %edx
imulq $0xa, %rax, %rax
movq %rax, %rsi
shrq $0x3c, %rsi
movb %sil, 0x13(%rbp)
andq %r13, %rax
incq %rbp
incl %edx
jne 0x2e223
addq %rcx, %r15
jmp 0x2e19f
movslq %r8d, %r13
imulq $0x28, %r13, %rax
leaq 0x2ece(%rip), %rcx      # 0x31120
movl (%rcx,%rax), %r12d
movq 0x18(%rcx,%rax), %rsi
movq 0x20(%rcx,%rax), %rax
movq %rax, 0x20(%rsp)
movq %rsi, 0x28(%rsp)
movq %rsi, 0x38(%rsp)
bsrq 0x38(%rsp), %rax
xorl $0x3f, %eax
movq %rax, 0x18(%rsp)
leaq 0x48(%rsp), %rdi
movq %rdx, %rsi
movq %r15, %rdx
callq 0x290c6
leaq 0x5cd(%rsp), %rbp
movq %r12, %rax
negq %rax
movq %rax, 0x10(%rsp)
leaq (%r12,%r12), %rax
negq %rax
movq %rax, 0x8(%rsp)
cmpq $0x2, %r15
jl 0x2e348
movq 0x18(%rsp), %rax
movl %eax, (%rsp)
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x48(%rsp), %rdx
movq %r15, %rcx
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
callq 0x186d0
cmpq $0x1, 0x40(%rsp,%r15,8)
movl $0x0, %ecx
sbbq %rcx, %rcx
movq 0x40(%rsp), %rax
incq %rax
movq 0x10(%rsp), %rdx
leaq (%rdx,%rbp), %rdi
xorl %esi, %esi
movq %r13, 0x30(%rsp)
mulq 0x30(%rsp)
movb %dl, (%rdi,%rsi)
incq %rsi
cmpl %esi, %r12d
jne 0x2e2fe
addq %rcx, %r15
addq 0x8(%rsp), %rbp
addq %rsi, %rbp
jmp 0x2e2ac
movq 0x48(%rsp), %rcx
pushq $0xa
popq %rsi
testq %rcx, %rcx
je 0x2e35f
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
imull $0xf6, %eax, %edx
addl %edx, %ecx
movb %cl, -0x1(%rbp)
decq %rbp
movq %rax, %rcx
jmp 0x2e328
movq 0x48(%rsp), %rax
testq %rax, %rax
je 0x2e35f
xorl %edx, %edx
divq %r13
movb %dl, -0x1(%rbp)
decq %rbp
jmp 0x2e34d
leaq 0x130(%rsp), %rax
subq %rbp, %rax
addq $0x49d, %rax            # imm = 0x49D
cmpq %r14, %rax
jae 0x2e380
movb $0x0, (%rbx)
incq %rbx
decq %r14
jmp 0x2e370
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x2e393
movb (%rbp,%rcx), %dl
movb %dl, (%rbx,%rcx)
incq %rcx
jmp 0x2e382
addq %rcx, %rbx
movq %rbx, %rax
addq $0x5d8, %rsp            # imm = 0x5D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq