// File: /workspace/github_cpp_makefile_star2_O2/marxn[P]pupp/3rdparty/gmp/mpf/set_str.c
// Function: _gmpf_set_str
int
mpf_set_str (mpf_ptr x, const char *str, int base)
{
  size_t str_size;
  char *s, *begs;
  size_t i, j;
  int c;
  int negative;
  char *dotpos = 0;
  const char *expptr;
  int exp_base;
  const char  *point = GMP_DECIMAL_POINT;
  size_t      pointlen = strlen (point);
  const unsigned char *digit_value;
  TMP_DECL;

  c = (unsigned char) *str;

  /* Skip whitespace.  */
  while (isspace (c))
    c = (unsigned char) *++str;

  negative = 0;
  if (c == '-')
    {
      negative = 1;
      c = (unsigned char) *++str;
    }

  /* Default base to decimal.  */
  if (base == 0)
    base = 10;

  exp_base = base;

  if (base < 0)
    {
      exp_base = 10;
      base = -base;
    }

  digit_value = digit_value_tab;
  if (base > 36)
    {
      /* For bases > 36, use the collating sequence
	 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.  */
      digit_value += 208;
      if (base > 62)
	return -1;		/* too large base */
    }

  /* Require at least one digit, possibly after an initial decimal point.  */
  if (digit_value[c] >= base)
    {
      /* not a digit, must be a decimal point */
      for (i = 0; i < pointlen; i++)
	if (str[i] != point[i])
	  return -1;
      if (digit_value[(unsigned char) str[pointlen]] >= base)
	return -1;
    }

  /* Locate exponent part of the input.  Look from the right of the string,
     since the exponent is usually a lot shorter than the mantissa.  */
  expptr = NULL;
  str_size = strlen (str);
  for (i = str_size - 1; i > 0; i--)
    {
      c = (unsigned char) str[i];
      if (c == '@' || (base <= 10 && (c == 'e' || c == 'E')))
	{
	  expptr = str + i + 1;
	  str_size = i;
	  break;
	}
    }

  TMP_MARK;
  s = begs = (char *) TMP_ALLOC (str_size + 1);

  /* Loop through mantissa, converting it from ASCII to raw byte values.  */
  for (i = 0; i < str_size; i++)
    {
      c = (unsigned char) *str;
      if (!isspace (c))
	{
	  int dig;

	  for (j = 0; j < pointlen; j++)
	    if (str[j] != point[j])
	      goto not_point;
	  if (1)
	    {
	      if (dotpos != 0)
		{
		  /* already saw a decimal point, another is invalid */
		  TMP_FREE;
		  return -1;
		}
	      dotpos = s;
	      str += pointlen - 1;
	      i += pointlen - 1;
	    }
	  else
	    {
	    not_point:
	      dig = digit_value[c];
	      if (dig >= base)
		{
		  TMP_FREE;
		  return -1;
		}
	      *s++ = dig;
	    }
	}
      c = (unsigned char) *++str;
    }

  str_size = s - begs;

  {
    long exp_in_base;
    mp_size_t ra, ma, rn, mn;
    int cnt;
    mp_ptr mp, tp, rp;
    mp_exp_t exp_in_limbs;
    mp_size_t prec = PREC(x) + 1;
    int divflag;
    mp_size_t madj, radj;

#if 0
    size_t n_chars_needed;

    /* This breaks things like 0.000...0001.  To safely ignore superfluous
       digits, we need to skip over leading zeros.  */
    /* Just consider the relevant leading digits of the mantissa.  */
    LIMBS_PER_DIGIT_IN_BASE (n_chars_needed, prec, base);
    if (str_size > n_chars_needed)
      str_size = n_chars_needed;
#endif

    LIMBS_PER_DIGIT_IN_BASE (ma, str_size, base);
    mp = TMP_ALLOC_LIMBS (ma);
    mn = mpn_set_str (mp, (unsigned char *) begs, str_size, base);

    if (mn == 0)
      {
	SIZ(x) = 0;
	EXP(x) = 0;
	TMP_FREE;
	return 0;
      }

    madj = 0;
    /* Ignore excess limbs in MP,MSIZE.  */
    if (mn > prec)
      {
	madj = mn - prec;
	mp += mn - prec;
	mn = prec;
      }

    if (expptr != 0)
      {
	/* Scan and convert the exponent, in base exp_base.  */
	long dig, minus, plusminus;
	c = (unsigned char) *expptr;
	minus = -(long) (c == '-');
	plusminus = minus | -(long) (c == '+');
	expptr -= plusminus;			/* conditional increment */
	c = (unsigned char) *expptr++;
	dig = digit_value[c];
	if (dig >= exp_base)
	  {
	    TMP_FREE;
	    return -1;
	  }
	exp_in_base = dig;
	c = (unsigned char) *expptr++;
	dig = digit_value[c];
	while (dig < exp_base)
	  {
	    exp_in_base = exp_in_base * exp_base;
	    exp_in_base += dig;
	    c = (unsigned char) *expptr++;
	    dig = digit_value[c];
	  }
	exp_in_base = (exp_in_base ^ minus) - minus; /* conditional negation */
      }
    else
      exp_in_base = 0;
    if (dotpos != 0)
      exp_in_base -= s - dotpos;
    divflag = exp_in_base < 0;
    exp_in_base = ABS (exp_in_base);

    if (exp_in_base == 0)
      {
	MPN_COPY (PTR(x), mp, mn);
	SIZ(x) = negative ? -mn : mn;
	EXP(x) = mn + madj;
	TMP_FREE;
	return 0;
      }

    ra = 2 * (prec + 1);
    rp = TMP_ALLOC_LIMBS (ra);
    tp = TMP_ALLOC_LIMBS (ra);
    rn = mpn_pow_1_highpart (rp, &radj, (mp_limb_t) base, exp_in_base, prec, tp);

    if (divflag)
      {
#if 0
	/* FIXME: Should use mpn_div_q here.  */
	...
	mpn_div_q (tp, mp, mn, rp, rn, scratch);
	...
#else
	mp_ptr qp;
	mp_limb_t qlimb;
	if (mn < rn)
	  {
	    /* Pad out MP,MSIZE for current divrem semantics.  */
	    mp_ptr tmp = TMP_ALLOC_LIMBS (rn + 1);
	    MPN_ZERO (tmp, rn - mn);
	    MPN_COPY (tmp + rn - mn, mp, mn);
	    mp = tmp;
	    madj -= rn - mn;
	    mn = rn;
	  }
	if ((rp[rn - 1] & GMP_NUMB_HIGHBIT) == 0)
	  {
	    mp_limb_t cy;
	    count_leading_zeros (cnt, rp[rn - 1]);
	    cnt -= GMP_NAIL_BITS;
	    mpn_lshift (rp, rp, rn, cnt);
	    cy = mpn_lshift (mp, mp, mn, cnt);
	    if (cy)
	      mp[mn++] = cy;
	  }

	qp = TMP_ALLOC_LIMBS (prec + 1);
	qlimb = mpn_divrem (qp, prec - (mn - rn), mp, mn, rp, rn);
	tp = qp;
	exp_in_limbs = qlimb + (mn - rn) + (madj - radj);
	rn = prec;
	if (qlimb != 0)
	  {
	    tp[prec] = qlimb;
	    /* Skip the least significant limb not to overrun the destination
	       variable.  */
	    tp++;
	  }
#endif
      }
    else
      {
	tp = TMP_ALLOC_LIMBS (rn + mn);
	if (rn > mn)
	  mpn_mul (tp, rp, rn, mp, mn);
	else
	  mpn_mul (tp, mp, mn, rp, rn);
	rn += mn;
	rn -= tp[rn - 1] == 0;
	exp_in_limbs = rn + madj + radj;

	if (rn > prec)
	  {
	    tp += rn - prec;
	    rn = prec;
	    exp_in_limbs += 0;
	  }
      }

    MPN_COPY (PTR(x), tp, rn);
    SIZ(x) = negative ? -rn : rn;
    EXP(x) = exp_in_limbs;
    TMP_FREE;
    return 0;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, -0x70(%rbp)
movl $0x10000, %edi          # imm = 0x10000
callq 0x6220
movq %rax, %r12
movq %rax, %rdi
callq 0x6110
movq %rax, %rbx
callq 0x62a0
movq %rax, -0x60(%rbp)
movq (%rax), %rax
movzbl (%r14), %r13d
incq %r14
testb $0x20, 0x1(%rax,%r13,2)
jne 0x16076
cmpb $0x2d, %r13b
jne 0x16090
movb (%r14), %al
jmp 0x16096
decq %r14
movl %r13d, %eax
testl %r15d, %r15d
pushq $0xa
popq %rdi
cmovel %edi, %r15d
testl %r15d, %r15d
cmovnsl %r15d, %edi
movl %r15d, %r8d
negl %r8d
cmovsl %r15d, %r8d
pushq $-0x1
popq %r15
cmpl $0x25, %r8d
jb 0x160d3
cmpl $0x3e, %r8d
ja 0x16705
movl $0xd0, %esi
addq 0x2cee7(%rip), %rsi     # 0x42fb8
jmp 0x160da
leaq 0x1d9e6(%rip), %rsi     # 0x33ac0
movzbl %al, %eax
movzbl (%rsi,%rax), %eax
cmpl %eax, %r8d
ja 0x16115
xorl %eax, %eax
cmpq %rax, %rbx
je 0x16103
movb (%r14,%rax), %cl
leaq 0x1(%rax), %rdx
cmpb (%r12,%rax), %cl
movq %rdx, %rax
je 0x160e8
jmp 0x16705
movzbl (%r14,%rbx), %eax
movzbl (%rsi,%rax), %eax
cmpl %eax, %r8d
jbe 0x16705
movl %edi, -0x80(%rbp)
movq %rsi, -0x50(%rbp)
movq %r14, %rdi
movl %r8d, -0x30(%rbp)
callq 0x6110
movl -0x30(%rbp), %ecx
leaq (%r14,%rax), %rdx
pushq $0x1
popq %rdi
movq %rax, %r15
subq %rdi, %r15
je 0x1615f
movq %rdx, %r10
movb -0x1(%rdx), %sil
cmpb $0x40, %sil
je 0x16165
leaq -0x1(%r10), %rdx
incq %rdi
cmpl $0xa, %ecx
ja 0x16132
andb $-0x21, %sil
cmpb $0x45, %sil
jne 0x16132
jmp 0x16165
xorl %r10d, %r10d
movq %rax, %r15
andq $0x0, -0x48(%rbp)
leaq 0x1(%r15), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
movq -0x50(%rbp), %rdx
ja 0x16717
movq %rsp, %rax
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %rax
movq %rax, %rsp
leaq -0x1(%rbx), %r9
movq $0x0, -0x58(%rbp)
xorl %r11d, %r11d
movq %rax, -0x38(%rbp)
movq %rax, -0x40(%rbp)
movq %rdx, %rax
cmpq %r15, %r11
jae 0x16215
movzbl (%r14), %edx
movq -0x60(%rbp), %rsi
movq (%rsi), %rsi
testb $0x20, 0x1(%rsi,%rdx,2)
jne 0x1620d
xorl %esi, %esi
cmpq %rsi, %rbx
je 0x161f4
movb (%r14,%rsi), %dil
leaq 0x1(%rsi), %r8
cmpb (%r12,%rsi), %dil
movq %r8, %rsi
je 0x161c3
movzbl (%rax,%rdx), %edx
cmpl %edx, %ecx
jbe 0x162f9
movq -0x40(%rbp), %rsi
movb %dl, (%rsi)
incq %rsi
movq %rsi, -0x40(%rbp)
jmp 0x1620d
cmpq $0x0, -0x58(%rbp)
jne 0x162f9
addq %r9, %r14
addq %r9, %r11
movq -0x40(%rbp), %rdx
movq %rdx, -0x58(%rbp)
incq %r14
incq %r11
jmp 0x161aa
movq %r10, %r12
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r8
subq %r8, %r14
movq -0x70(%rbp), %rax
movl (%rax), %r15d
movl %ecx, %eax
movq %rax, -0x90(%rbp)
imulq $0x28, %rax, %rax
leaq 0x1aee2(%rip), %rdx     # 0x31120
movq 0x10(%rdx,%rax), %rax
movq %r14, -0xb0(%rbp)
mulq -0xb0(%rbp)
movabsq $0x1ffffffffffffff8, %rax # imm = 0x1FFFFFFFFFFFFFF8
andq %rdx, %rax
leaq 0x10(%rax), %rsi
cmpq $0x7ef0, %rax           # imm = 0x7EF0
ja 0x1673b
movq %rsp, %rbx
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %rbx
movq %rbx, %rsp
movq %rbx, %rdi
movq %r8, %rsi
movq %r14, %rdx
callq 0x1a630
testq %rax, %rax
je 0x16306
incl %r15d
movslq %r15d, %rdi
xorl %edx, %edx
movq %rax, %r14
subq %rdi, %r14
movq %rdi, %rcx
cmovlq %rax, %rcx
movq %rcx, -0x38(%rbp)
cmovleq %rdx, %r14
testq %r12, %r12
movq %rdi, -0x30(%rbp)
je 0x1632a
movb (%r12), %r8b
leal -0x2b(%r8), %ecx
andb $-0x3, %cl
cmpb $0x1, %cl
adcq $0x0, %r12
movzbl (%r12), %ecx
movq -0x50(%rbp), %rdi
movzbl (%rdi,%rcx), %ecx
movl -0x80(%rbp), %edx
cmpq %rdx, %rcx
jae 0x162f9
incq %r12
movzbl (%r12), %esi
movzbl (%rdi,%rsi), %esi
cmpq %rdx, %rsi
jae 0x16318
imulq %rdx, %rcx
addq %rsi, %rcx
jmp 0x162df
movq -0x48(%rbp), %rdi
pushq $-0x1
popq %r15
jmp 0x16700
movq -0x70(%rbp), %rax
andl $0x0, 0x4(%rax)
andq $0x0, 0x8(%rax)
jmp 0x166f9
movq %rcx, %rdx
negq %rdx
cmpb $0x2d, %r8b
cmovneq %rcx, %rdx
movq -0x30(%rbp), %rdi
leaq (%rbx,%r14,8), %rsi
movq -0x58(%rbp), %rcx
movq %rcx, %r8
subq -0x40(%rbp), %r8
testq %rcx, %rcx
cmoveq %rcx, %r8
addq %rdx, %r8
movq %r8, %rcx
negq %rcx
cmovsq %r8, %rcx
movq %rcx, -0x58(%rbp)
jae 0x164fe
leaq 0x1(%rdi), %rbx
movq %rbx, -0x98(%rbp)
shlq $0x4, %rbx
cmpq $0x7f00, %rbx           # imm = 0x7F00
movq %r14, -0x78(%rbp)
movq %rax, -0x88(%rbp)
movq %rsi, -0x68(%rbp)
movq %r8, -0x80(%rbp)
ja 0x16753
movq %rsp, %rcx
addq $0xf, %rbx
andq $-0x10, %rbx
subq %rbx, %rcx
movq %rcx, %rsp
movq %rsp, %rax
subq %rbx, %rax
movq %rax, %rsp
movq -0x90(%rbp), %rdx
movq %rdx, (%rcx)
movq -0x58(%rbp), %rdx
movq %rdx, -0xa8(%rbp)
bsrq -0xa8(%rbp), %r14
xorl $-0x40, %r14d
addl $0x3f, %r14d
pushq $0x1
popq %r15
movq %rcx, %rdx
xorl %ecx, %ecx
xorl %r12d, %r12d
movq %rdx, -0x50(%rbp)
movq %rdx, %rdi
testl %r14d, %r14d
js 0x16470
movq %rax, %rbx
movq %r12, -0x60(%rbp)
movq %rdi, -0x40(%rbp)
leaq (%rdi,%rcx,8), %rsi
movq %rax, %rdi
movq %r15, %rdx
movq %r15, %r12
callq 0x196c0
addq %r15, %r15
shlq $0x4, %r12
cmpq $0x1, -0x8(%r12,%rbx)
sbbq $0x0, %r15
movq %r15, %r12
movq -0x30(%rbp), %rax
subq %rax, %r12
cmovgeq %rax, %r15
movl $0x0, %eax
cmovleq %rax, %r12
movq -0x58(%rbp), %rax
btq %r14, %rax
jae 0x16456
leaq (%rbx,%r12,8), %rsi
movq %rbx, %rdi
movq %r15, %rdx
movq -0x90(%rbp), %rcx
callq 0x18086
movq %rax, (%rbx,%r15,8)
cmpq $0x1, %rax
sbbq $-0x1, %r15
xorl %ecx, %ecx
jmp 0x16459
movq %r12, %rcx
movq -0x60(%rbp), %rax
leaq (%r12,%rax,2), %r12
decl %r14d
movq -0x40(%rbp), %rax
movq %rbx, %rdi
jmp 0x163d8
xorl %eax, %eax
movq %r15, %rdx
movq -0x30(%rbp), %rsi
subq %rsi, %rdx
cmovgeq %rsi, %r15
cmovgq %rdx, %rax
addq %rax, %r12
leaq (%rdi,%rax,8), %rax
leaq (%rax,%rcx,8), %rsi
movq -0x50(%rbp), %rdi
movq %r15, %rdx
callq 0x290c6
cmpq $0x0, -0x80(%rbp)
js 0x1652a
movq -0x38(%rbp), %r8
leaq (%r15,%r8), %rbx
leaq (,%rbx,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
movq -0x78(%rbp), %r14
movq %r15, %r9
ja 0x16778
movq %rsp, %r15
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r15
movq %r15, %rsp
movq -0x50(%rbp), %rcx
cmpq %r9, -0x88(%rbp)
jge 0x165bf
movq %r15, %rdi
movq %rcx, %rsi
movq %r9, %rdx
movq -0x68(%rbp), %rcx
jmp 0x165cc
movq -0x70(%rbp), %rbx
movq 0x10(%rbx), %rdi
movq -0x38(%rbp), %r15
movq %r15, %rdx
callq 0x290c6
movl %r15d, %eax
negl %eax
cmpb $0x2d, %r13b
cmovnel %r15d, %eax
movl %eax, 0x4(%rbx)
addq %r15, %r14
jmp 0x166f5
cmpq %r15, -0x88(%rbp)
movq -0x78(%rbp), %r14
movq -0x38(%rbp), %rax
movq %r15, %r9
jge 0x165fa
leaq 0x8(,%r9,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
ja 0x167b4
movq %rsp, %rbx
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %rbx
movq %rbx, %rsp
movq %rax, %r14
subq %r9, %r14
je 0x1658e
movq %r9, %rdx
subq %rax, %rdx
shlq $0x3, %rdx
movq %rbx, %rdi
xorl %esi, %esi
movq %r9, %r15
callq 0x6170
movq %r15, %r9
movq -0x38(%rbp), %rax
leaq (%rbx,%r9,8), %rdi
movq %rax, %rdx
leaq (,%rax,8), %rax
subq %rax, %rdi
movq -0x68(%rbp), %rsi
movq %r9, %r15
callq 0x290c6
movq %r15, %r9
movq -0x78(%rbp), %r15
addq %r14, %r15
movq %r15, %r14
movq %r9, -0x38(%rbp)
jmp 0x165fe
movq %r15, %rdi
movq -0x68(%rbp), %rsi
movq %r8, %rdx
movq %r9, %r8
callq 0x18a58
cmpq $0x1, -0x8(%r15,%rbx,8)
sbbq $0x0, %rbx
addq %r12, %r14
addq %rbx, %r14
movq %rbx, %rax
movq -0x30(%rbp), %rdx
subq %rdx, %rax
jle 0x166cf
leaq (%r15,%rax,8), %r15
jmp 0x166d2
movq -0x68(%rbp), %rbx
movq -0x30(%rbp), %r8
movq -0x50(%rbp), %rdi
movq %r12, -0x60(%rbp)
movq -0x8(%rdi,%r9,8), %rax
testq %rax, %rax
js 0x16667
movq %rax, -0xa0(%rbp)
bsrq -0xa0(%rbp), %r15
xorl $0x3f, %r15d
movq %rdi, %rsi
movq %r9, -0x40(%rbp)
movq %r9, %rdx
movl %r15d, %ecx
callq 0x181a0
movq %rbx, %rdi
movq %rbx, %rsi
movq -0x38(%rbp), %r12
movq %r12, %rdx
movl %r15d, %ecx
callq 0x181a0
testq %rax, %rax
je 0x1665a
movq %rax, (%rbx,%r12,8)
incq %r12
movq -0x30(%rbp), %r8
movq %r12, %rcx
movq -0x40(%rbp), %r9
jmp 0x1666b
movq -0x38(%rbp), %rcx
movq -0x98(%rbp), %rsi
shlq $0x3, %rsi
movq %r14, %r12
cmpq $0x7f00, %rsi           # imm = 0x7F00
ja 0x16793
movq %rsp, %r15
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r15
movq %r15, %rsp
movq %rcx, %r14
subq %r9, %r14
movq %r8, %rsi
subq %r14, %rsi
movq %r15, %rdi
movq %rbx, %rdx
movq %r8, %rbx
movq -0x50(%rbp), %r8
callq 0x183b0
subq -0x60(%rbp), %r12
addq %r14, %r12
movq %r12, %r14
addq %rax, %r14
testq %rax, %rax
je 0x166cf
movq %rax, (%r15,%rbx,8)
addq $0x8, %r15
movq %rbx, %rdx
movq -0x70(%rbp), %rbx
movq 0x10(%rbx), %rdi
movq %r15, %rsi
movq %rdx, %r15
callq 0x290c6
movl %r15d, %eax
negl %eax
cmpb $0x2d, %r13b
cmovnel %r15d, %eax
movl %eax, 0x4(%rbx)
movq %r14, 0x8(%rbx)
movq -0x48(%rbp), %rdi
xorl %r15d, %r15d
testq %rdi, %rdi
jne 0x16734
movl %r15d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x48(%rbp), %rdi
movq %r10, -0x40(%rbp)
callq 0x29dc0
movl -0x30(%rbp), %ecx
movq -0x40(%rbp), %r10
movq -0x50(%rbp), %rdx
jmp 0x16190
callq 0x29df3
jmp 0x16705
leaq -0x48(%rbp), %rdi
callq 0x29dc0
movq -0x38(%rbp), %r8
movl -0x30(%rbp), %ecx
movq %rax, %rbx
jmp 0x1627f
leaq -0x48(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x29dc0
movq %rax, %r14
movq %r15, %rdi
movq %rbx, %rsi
callq 0x29dc0
movq %r14, %rcx
jmp 0x163a0
leaq -0x48(%rbp), %rdi
movq %r9, %r15
callq 0x29dc0
movq %r15, %r9
movq %rax, %r15
movq -0x38(%rbp), %r8
jmp 0x164db
leaq -0x48(%rbp), %rdi
movq %rcx, %r14
movq %r9, %r15
callq 0x29dc0
movq %r15, %r9
movq -0x30(%rbp), %r8
movq %rax, %r15
movq %r14, %rcx
jmp 0x16697
leaq -0x48(%rbp), %rdi
movq %r9, %rbx
callq 0x29dc0
movq %rbx, %r9
movq %rax, %rbx
movq -0x38(%rbp), %rax
jmp 0x16568
nop