// File: marxn[P]pupp/3rdparty/gmp/mpn/set_str.c
// Function: _gmpn_set_str
mp_size_t
mpn_set_str (mp_ptr rp, const unsigned char *str, size_t str_len, int base)
{
  if (POW2_P (base))
    {
      /* The base is a power of 2.  Read the input string from least to most
	 significant character/digit.  */

      const unsigned char *s;
      int next_bitpos;
      mp_limb_t res_digit;
      mp_size_t size;
      int bits_per_indigit = mp_bases[base].big_base;

      size = 0;
      res_digit = 0;
      next_bitpos = 0;

      for (s = str + str_len - 1; s >= str; s--)
	{
	  int inp_digit = *s;

	  res_digit |= ((mp_limb_t) inp_digit << next_bitpos) & GMP_NUMB_MASK;
	  next_bitpos += bits_per_indigit;
	  if (next_bitpos >= GMP_NUMB_BITS)
	    {
	      rp[size++] = res_digit;
	      next_bitpos -= GMP_NUMB_BITS;
	      res_digit = inp_digit >> (bits_per_indigit - next_bitpos);
	    }
	}

      if (res_digit != 0)
	rp[size++] = res_digit;
      return size;
    }

  if (BELOW_THRESHOLD (str_len, SET_STR_PRECOMPUTE_THRESHOLD))
    return mpn_bc_set_str (rp, str, str_len, base);
  else
    {
      mp_ptr powtab_mem, tp;
      powers_t powtab[GMP_LIMB_BITS];
      int chars_per_limb;
      mp_size_t size;
      mp_size_t un;
      TMP_DECL;

      TMP_MARK;

      chars_per_limb = mp_bases[base].chars_per_limb;

      un = str_len / chars_per_limb + 1;

      /* Allocate one large block for the powers of big_base.  */
      powtab_mem = TMP_BALLOC_LIMBS (mpn_dc_set_str_powtab_alloc (un));

      mpn_set_str_compute_powtab (powtab, powtab_mem, un, base);

      tp = TMP_BALLOC_LIMBS (mpn_dc_set_str_itch (un));
      size = mpn_dc_set_str (rp, str, str_len, powtab, tp);

      TMP_FREE;
      return size;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa80, %rsp            # imm = 0xA80
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x3a5bb
movslq -0x24(%rbp), %rcx
leaq 0x26d87(%rip), %rax     # 0x61260
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movl %eax, -0x4c(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jb 0x3a58c
movq -0x30(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x50(%rbp)
movslq -0x50(%rbp), %rax
movl -0x34(%rbp), %ecx
shlq %cl, %rax
andq $-0x1, %rax
orq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x4c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x40, -0x34(%rbp)
jl 0x3a57c
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
subl $0x40, %eax
movl %eax, -0x34(%rbp)
movl -0x50(%rbp), %eax
movl -0x4c(%rbp), %ecx
subl -0x34(%rbp), %ecx
sarl %cl, %eax
cltq
movq %rax, -0x40(%rbp)
jmp 0x3a57e
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3a50e
cmpq $0x0, -0x40(%rbp)
je 0x3a5ae
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3a6d9
cmpq $0x6fb, -0x20(%rbp)     # imm = 0x6FB
jae 0x3a5e2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
callq 0x3a6f0
movq %rax, -0x8(%rbp)
jmp 0x3a6d9
movq $0x0, -0xa80(%rbp)
movslq -0x24(%rbp), %rcx
leaq 0x26c68(%rip), %rax     # 0x61260
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0xa64(%rbp)
movq -0x20(%rbp), %rax
movslq -0xa64(%rbp), %rcx
xorl %edx, %edx
divq %rcx
addq $0x1, %rax
movq %rax, -0xa78(%rbp)
movq -0xa78(%rbp), %rsi
addq $0x40, %rsi
shlq $0x3, %rsi
leaq -0xa80(%rbp), %rdi
callq 0x56430
movq %rax, -0x58(%rbp)
leaq -0xa60(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0xa78(%rbp), %rdx
movl -0x24(%rbp), %ecx
callq 0x3a9d0
movq -0xa78(%rbp), %rsi
addq $0x40, %rsi
shlq $0x3, %rsi
leaq -0xa80(%rbp), %rdi
callq 0x56430
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0xa60(%rbp), %rcx
movq -0x60(%rbp), %r8
callq 0x3ad20
movq %rax, -0xa70(%rbp)
cmpq $0x0, -0xa80(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x3a6cc
movq -0xa80(%rbp), %rdi
callq 0x564a0
jmp 0x3a6ce
movq -0xa70(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa80, %rsp            # imm = 0xA80
popq %rbp
retq
nopw %cs:(%rax,%rax)