// File: /workspace/github_cpp_makefile_star2_O3/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 $0x5e8, %rsp            # imm = 0x5E8
movq %rcx, %r15
movq %rsi, %r12
movq %rdi, %r14
cmpl $0xa, %r8d
jne 0x34c30
movq %r12, 0x10(%rsp)
movq %r14, 0x8(%rsp)
leaq 0x58(%rsp), %rdi
movq %rdi, %rbx
movq %rdx, %rsi
movq %r15, %rdx
callq 0x2f106
leaq 0x5dd(%rsp), %r13
cmpq $0x2, %r15
jl 0x34be7
movabsq $-0x7538dcfb76180000, %rbp # imm = 0x8AC7230489E80000
movabsq $-0x27c36b0492d53cb6, %r14 # imm = 0xD83C94FB6D2AC34A
movabsq $0xffffffffffffffe, %r12 # imm = 0xFFFFFFFFFFFFFFE
movl $0x0, (%rsp)
movl $0x1, %esi
leaq 0x50(%rsp), %rdi
movq %rbx, %rdx
movq %r15, %rcx
movq %rbp, %r8
movq %r14, %r9
callq 0x1c4b0
cmpq $0x1, 0x50(%rsp,%r15,8)
movl $0x0, %ecx
sbbq %rcx, %rcx
movq 0x50(%rsp), %rax
incq %rax
mulq 0x5d30(%rip)            # 0x3a8b8
movb %dl, -0x13(%r13)
mulq 0x5d25(%rip)            # 0x3a8b8
movb %dl, -0x12(%r13)
mulq 0x5d1a(%rip)            # 0x3a8b8
movb %dl, -0x11(%r13)
mulq 0x5d0f(%rip)            # 0x3a8b8
movb %dl, -0x10(%r13)
addq $0xf, %rax
shrq $0x4, %rax
addq $-0x22, %r13
movl $0xfffffff1, %edx       # imm = 0xFFFFFFF1
addq %rax, %rax
leaq (%rax,%rax,4), %rax
movq %rax, %rsi
shrq $0x3c, %rsi
movb %sil, 0x13(%r13)
andq %r12, %rax
incq %r13
incl %edx
jne 0x34bbe
addq %rcx, %r15
cmpq $0x1, %r15
jg 0x34b49
movq 0x58(%rsp), %rcx
testq %rcx, %rcx
movq 0x10(%rsp), %r12
je 0x34d6e
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
movq 0x8(%rsp), %r14
movq %rcx, %rax
mulq %rsi
shrq $0x3, %rdx
imull $0xf6, %edx, %eax
addl %ecx, %eax
movb %al, -0x1(%r13)
decq %r13
cmpq $0xa, %rcx
movq %rdx, %rcx
jae 0x34c09
jmp 0x34d73
movslq %r8d, %rbp
leaq (,%rbp,4), %rax
addq %rbp, %rax
leaq 0x24db(%rip), %rcx      # 0x37120
movl (%rcx,%rax,8), %ebx
movq 0x18(%rcx,%rax,8), %rsi
movq 0x20(%rcx,%rax,8), %rax
movq %rax, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
movq %rsi, 0x48(%rsp)
bsrq 0x48(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x58(%rsp), %rdi
movq %rdx, %rsi
movq %r15, %rdx
callq 0x2f106
leaq 0x5dd(%rsp), %r13
cmpq $0x2, %r15
jl 0x34d4b
movq %r12, 0x10(%rsp)
movq %r14, 0x8(%rsp)
movq 0x18(%rsp), %rcx
xorl $0x3f, %ecx
movq %rbx, %rax
negq %rax
movq %rax, 0x18(%rsp)
leaq (%rbx,%rbx), %rax
movq %rax, 0x20(%rsp)
negq %rax
movq %rax, 0x28(%rsp)
movq %rcx, %rax
movq %r13, %r14
movq %rax, %r12
movl %eax, (%rsp)
movl $0x1, %esi
leaq 0x50(%rsp), %rdi
leaq 0x58(%rsp), %rdx
movq %r15, %rcx
movq 0x38(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0x1c4b0
cmpq $0x1, 0x50(%rsp,%r15,8)
movl $0x0, %esi
sbbq %rsi, %rsi
movq 0x50(%rsp), %rax
incq %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%r13), %rdi
xorl %ecx, %ecx
movq %rbp, 0x40(%rsp)
mulq 0x40(%rsp)
movb %dl, (%rdi,%rcx)
incq %rcx
cmpl %ecx, %ebx
jne 0x34d0a
addq %rsi, %r15
movq 0x28(%rsp), %rax
leaq (%r14,%rax), %r13
addq %rcx, %r13
cmpq $0x1, %r15
movq %r12, %rax
jg 0x34cbf
subq 0x20(%rsp), %r14
addq %rcx, %r14
movq %r14, %r13
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %r12
movq 0x58(%rsp), %rcx
testq %rcx, %rcx
je 0x34d73
movq %rcx, %rax
xorl %edx, %edx
divq %rbp
movb %dl, -0x1(%r13)
decq %r13
cmpq %rbp, %rcx
movq %rax, %rcx
jae 0x34d55
jmp 0x34d73
movq 0x8(%rsp), %r14
leaq 0x140(%rsp), %rax
movq %rax, %rbx
subq %r13, %rbx
addq $0x49d, %rbx            # imm = 0x49D
cmpq %r12, %rbx
jae 0x34daf
addq %r13, %r12
subq %rax, %r12
leaq -0x49d(%r12), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x6170
addq %r12, %r14
addq $-0x49d, %r14           # imm = 0xFB63
testq %rbx, %rbx
je 0x34dca
xorl %eax, %eax
movb (%r13,%rax), %cl
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %rbx
jne 0x34db6
addq %rax, %r14
movq %r14, %rax
addq $0x5e8, %rsp            # imm = 0x5E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq