// File: /workspace/github_cpp_makefile_star2_O3/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, %r14d
movq %rsi, %rbx
movq %rdi, -0x50(%rbp)
movl $0x10000, %edi          # imm = 0x10000
callq 0x6230
movq %rax, %r15
movq %rax, %rdi
callq 0x6120
movq %rax, %r12
callq 0x62b0
movq (%rax), %rcx
movzbl (%rbx), %r13d
incq %rbx
testb $0x20, 0x1(%rcx,%r13,2)
jne 0x19ad6
cmpb $0x2d, %r13b
jne 0x19aef
movb (%rbx), %cl
jmp 0x19af5
decq %rbx
movl %r13d, %ecx
testl %r14d, %r14d
movl $0xa, %esi
cmovel %esi, %r14d
testl %r14d, %r14d
cmovnsl %r14d, %esi
movl %r14d, %r8d
negl %r8d
cmovsl %r14d, %r8d
cmpl $0x25, %r8d
jb 0x19b36
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x3e, %r8d
ja 0x1a1a2
movl $0xd0, %edx
addq 0x2d484(%rip), %rdx     # 0x46fb8
jmp 0x19b3d
leaq 0x1ff83(%rip), %rdx     # 0x39ac0
movzbl %cl, %ecx
movzbl (%rdx,%rcx), %ecx
cmpl %ecx, %r8d
ja 0x19b7d
testq %r12, %r12
je 0x19b65
xorl %edi, %edi
movb (%rbx,%rdi), %cl
cmpb (%r15,%rdi), %cl
jne 0x19f11
incq %rdi
cmpq %rdi, %r12
jne 0x19b50
movzbl (%rbx,%r12), %ecx
movzbl (%rdx,%rcx), %ecx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl %ecx, %r8d
jbe 0x1a1a2
movq %rax, -0x58(%rbp)
movl %esi, -0x48(%rbp)
movq %rdx, -0x78(%rbp)
movq %rbx, %rdi
movl %r8d, -0x38(%rbp)
callq 0x6120
movl -0x38(%rbp), %ecx
leaq (%rbx,%rax), %rdx
movl $0x1, %edi
movq %rax, %r14
subq %rdi, %r14
je 0x19bcd
movq %rdx, %r9
movb -0x1(%rdx), %sil
cmpb $0x40, %sil
je 0x19bd3
leaq -0x1(%r9), %rdx
incq %rdi
cmpl $0xa, %ecx
ja 0x19ba0
andb $-0x21, %sil
cmpb $0x45, %sil
jne 0x19ba0
jmp 0x19bd3
xorl %r9d, %r9d
movq %rax, %r14
movq $0x0, -0x30(%rbp)
leaq 0x1(%r14), %rsi
cmpq $0x7f01, %rsi           # imm = 0x7F01
jae 0x1a1b4
movq %rsp, %r8
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r8
movq %r8, %rsp
testq %r14, %r14
je 0x19c8e
leaq -0x1(%r12), %rax
xorl %r10d, %r10d
movq %r8, -0x70(%rbp)
movq %r8, %rdi
movq $0x0, -0x40(%rbp)
movq -0x58(%rbp), %r11
movzbl (%rbx), %edx
movq (%r11), %rsi
testb $0x20, 0x1(%rsi,%rdx,2)
jne 0x19c7d
movq %rdi, %r8
testq %r12, %r12
je 0x19c4a
xorl %esi, %esi
movb (%rbx,%rsi), %dil
cmpb (%r15,%rsi), %dil
jne 0x19c64
incq %rsi
cmpq %rsi, %r12
jne 0x19c38
cmpq $0x0, -0x40(%rbp)
jne 0x19eea
addq %rax, %rbx
addq %rax, %r10
movq %r8, %rdi
movq %r8, -0x40(%rbp)
jmp 0x19c7d
movq -0x78(%rbp), %rsi
movzbl (%rsi,%rdx), %edx
cmpl %edx, %ecx
jbe 0x19eea
movq %r8, %rdi
movb %dl, (%r8)
incq %rdi
incq %rbx
incq %r10
cmpq %r14, %r10
jb 0x19c21
movq -0x70(%rbp), %r8
jmp 0x19c99
movq $0x0, -0x40(%rbp)
movq %r8, %rdi
movq %r9, %r12
movq %rdi, -0x58(%rbp)
movq %rdi, %rbx
subq %r8, %rbx
movq -0x50(%rbp), %rax
movl (%rax), %r14d
movl %ecx, %eax
movq %rax, -0x70(%rbp)
leaq (%rax,%rax,4), %rax
leaq 0x1d462(%rip), %rdx     # 0x37120
movq 0x10(%rdx,%rax,8), %rax
movq %rbx, -0xb0(%rbp)
mulq -0xb0(%rbp)
movabsq $0x1ffffffffffffff8, %rax # imm = 0x1FFFFFFFFFFFFFF8
andq %rdx, %rax
leaq 0x10(%rax), %rsi
cmpq $0x7ef0, %rax           # imm = 0x7EF0
ja 0x1a1d7
movq %rsp, %r15
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r15
movq %r15, %rsp
movq %r15, %rdi
movq %r8, %rsi
movq %rbx, %rdx
callq 0x1e494
testq %rax, %rax
je 0x19ef9
incl %r14d
movslq %r14d, %r14
xorl %edi, %edi
movq %rax, %rbx
subq %r14, %rbx
movq %r14, %rdx
cmovlq %rax, %rdx
cmovleq %rdi, %rbx
testq %r12, %r12
je 0x19d9b
movb (%r12), %r9b
leal -0x2b(%r9), %ecx
andb $-0x3, %cl
cmpb $0x1, %cl
adcq $0x0, %r12
movzbl (%r12), %ecx
movq -0x78(%rbp), %r8
movzbl (%r8,%rcx), %ecx
movl -0x48(%rbp), %edi
cmpq %rdi, %rcx
jae 0x19eea
movzbl 0x1(%r12), %esi
movzbl (%r8,%rsi), %esi
cmpq %rdi, %rsi
jae 0x19d8d
addq $0x2, %r12
imulq %rdi, %rcx
addq %rsi, %rcx
movzbl (%r12), %esi
incq %r12
movzbl (%r8,%rsi), %esi
cmpq %rdi, %rsi
jb 0x19d74
movq %rcx, %rdi
negq %rdi
cmpb $0x2d, %r9b
cmovneq %rcx, %rdi
leaq (%r15,%rbx,8), %rsi
movq -0x40(%rbp), %rcx
movq %rcx, %r8
subq -0x58(%rbp), %r8
testq %rcx, %rcx
cmoveq %rcx, %r8
addq %rdi, %r8
movq %r8, %rcx
negq %rcx
cmovsq %r8, %rcx
movq %rcx, -0x58(%rbp)
jae 0x19f1c
movq %rbx, -0x88(%rbp)
leaq 0x1(%r14), %rbx
movq %rbx, -0x90(%rbp)
shlq $0x4, %rbx
cmpq $0x7f00, %rbx           # imm = 0x7F00
movq %rdx, -0x60(%rbp)
movq %rax, -0x80(%rbp)
movq %rsi, -0x68(%rbp)
movq %r8, -0x98(%rbp)
ja 0x1a1f1
movq %rsp, %rcx
addq $0xf, %rbx
andq $-0x10, %rbx
subq %rbx, %rcx
movq %rcx, %rsp
movq %rsp, %rdx
subq %rbx, %rdx
movq %rdx, %rsp
movq %r14, -0x38(%rbp)
movq -0x70(%rbp), %rax
movq %rax, (%rcx)
movq -0x58(%rbp), %rax
movq %rax, -0xa8(%rbp)
bsrq -0xa8(%rbp), %rax
xorl $-0x40, %eax
addl $0x3f, %eax
movq %rcx, -0x48(%rbp)
js 0x19f49
movl %eax, %r14d
movl $0x1, %r15d
xorl %edi, %edi
xorl %eax, %eax
movq %rdi, -0x40(%rbp)
movq %rdx, %r12
movq %rcx, -0x78(%rbp)
leaq (%rcx,%rax,8), %rsi
movq %rdx, %rdi
movq %r15, %rdx
callq 0x1d514
leaq (%r15,%r15), %rbx
shlq $0x4, %r15
cmpq $0x1, -0x8(%r15,%r12)
sbbq $0x0, %rbx
movq %rbx, %r15
movq -0x38(%rbp), %rax
subq %rax, %r15
cmovgeq %rax, %rbx
movl $0x0, %eax
cmovleq %rax, %r15
movq -0x58(%rbp), %rax
btq %r14, %rax
jae 0x19ec3
leaq (%r12,%r15,8), %rsi
movq %r12, %rdi
movq %rbx, %rdx
movq -0x70(%rbp), %rcx
callq 0x1be66
movq %rax, (%r12,%rbx,8)
cmpq $0x1, %rax
sbbq $-0x1, %rbx
xorl %eax, %eax
jmp 0x19ec6
movq %r15, %rax
movq -0x40(%rbp), %rdi
leaq (%r15,%rdi,2), %rdi
leaq -0x1(%r14), %rdx
movq %r12, %rcx
movq %rbx, %r15
testq %r14, %r14
movq %rdx, %r14
movq -0x78(%rbp), %rdx
jg 0x19e53
jmp 0x19f55
movq -0x30(%rbp), %rdi
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x1a19d
movq -0x50(%rbp), %rax
movl $0x0, 0x4(%rax)
movq $0x0, 0x8(%rax)
jmp 0x1a196
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x1a1a2
movq -0x50(%rbp), %r15
movq 0x10(%r15), %rdi
movq %rdx, %r14
callq 0x2f106
movl %r14d, %eax
negl %eax
cmpb $0x2d, %r13b
cmovnel %r14d, %eax
movl %eax, 0x4(%r15)
addq %r14, %rbx
movq %rbx, 0x8(%r15)
jmp 0x1a196
xorl %eax, %eax
movl $0x1, %ebx
xorl %edi, %edi
movq %rcx, %r12
xorl %ecx, %ecx
movq %rbx, %rdx
movq -0x38(%rbp), %rsi
subq %rsi, %rdx
cmovgeq %rsi, %rbx
cmovgq %rdx, %rcx
addq %rcx, %rdi
movq %rdi, -0x40(%rbp)
leaq (%r12,%rcx,8), %rcx
leaq (%rcx,%rax,8), %rsi
movq -0x48(%rbp), %rdi
movq %rbx, %rdx
callq 0x2f106
cmpq $0x0, -0x98(%rbp)
js 0x19fe3
movq -0x60(%rbp), %r8
leaq (%rbx,%r8), %r14
leaq (,%r14,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
movq -0x50(%rbp), %r12
movq -0x80(%rbp), %rdx
ja 0x1a219
movq %rsp, %r15
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r15
movq %r15, %rsp
movq -0x48(%rbp), %rcx
movq %r15, %rdi
cmpq %rbx, %rdx
jge 0x1a05e
movq %rcx, %rsi
movq %rbx, %rdx
movq -0x68(%rbp), %rcx
jmp 0x1a068
cmpq %rbx, -0x80(%rbp)
movq -0x60(%rbp), %r9
jge 0x1a09b
leaq 0x8(,%rbx,8), %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
ja 0x1a24f
movq %rsp, %r12
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r12
movq %r12, %rsp
movq %r9, %r14
subq %rbx, %r14
je 0x1a037
movq %rbx, %rdx
subq %r9, %rdx
shlq $0x3, %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x6170
movq -0x60(%rbp), %r9
leaq (%r12,%rbx,8), %rdi
leaq (,%r9,8), %rax
subq %rax, %rdi
movq -0x68(%rbp), %rsi
movq %r9, %rdx
callq 0x2f106
addq %r14, -0x88(%rbp)
movq %rbx, %r9
jmp 0x1a09f
movq -0x68(%rbp), %rsi
movq %r8, %rdx
movq %rbx, %r8
callq 0x1c838
cmpq $0x1, -0x8(%r15,%r14,8)
sbbq $0x0, %r14
movq -0x88(%rbp), %rbx
addq -0x40(%rbp), %rbx
addq %r14, %rbx
movq %r14, %rax
subq -0x38(%rbp), %rax
jle 0x1a16f
leaq (%r15,%rax,8), %r15
jmp 0x1a16b
movq -0x68(%rbp), %r12
movq -0x48(%rbp), %r8
movq -0x8(%r8,%rbx,8), %rax
testq %rax, %rax
js 0x1a0f8
movq %rax, -0xa0(%rbp)
bsrq -0xa0(%rbp), %r15
xorl $0x3f, %r15d
movq %r8, %rdi
movq %r8, %rsi
movq %rbx, %rdx
movl %r15d, %ecx
movq %r9, %r14
callq 0x1bf80
movq %r12, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x1bf80
testq %rax, %rax
je 0x1a0f1
movq %rax, (%r12,%r14,8)
incq %r14
movq %r14, %r9
movq -0x48(%rbp), %r8
movq -0x90(%rbp), %rsi
shlq $0x3, %rsi
cmpq $0x7f00, %rsi           # imm = 0x7F00
ja 0x1a232
movq %rsp, %r15
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r15
movq %r15, %rsp
movq %r9, %r14
subq %rbx, %r14
movq -0x38(%rbp), %rsi
subq %r14, %rsi
movq %r15, %rdi
movq %r12, %rdx
movq %r9, %rcx
movq %rbx, %r9
callq 0x1c190
movq -0x88(%rbp), %rbx
subq -0x40(%rbp), %rbx
addq %r14, %rbx
addq %rax, %rbx
testq %rax, %rax
je 0x1a167
movq -0x38(%rbp), %r14
movq %rax, (%r15,%r14,8)
addq $0x8, %r15
movq -0x50(%rbp), %r12
jmp 0x1a16f
movq -0x50(%rbp), %r12
movq -0x38(%rbp), %r14
movq 0x10(%r12), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x2f106
movl %r14d, %eax
negl %eax
cmpb $0x2d, %r13b
cmovnel %r14d, %eax
movl %eax, 0x4(%r12)
movq %rbx, 0x8(%r12)
movq -0x30(%rbp), %rdi
xorl %r14d, %r14d
testq %rdi, %rdi
jne 0x1a1d0
movl %r14d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x30(%rbp), %rdi
movq %r9, -0x40(%rbp)
callq 0x2fdb0
movl -0x38(%rbp), %ecx
movq -0x40(%rbp), %r9
movq %rax, %r8
jmp 0x19c06
callq 0x2fde3
jmp 0x1a1a2
leaq -0x30(%rbp), %rdi
movq %r8, %r15
callq 0x2fdb0
movq %r15, %r8
movl -0x38(%rbp), %ecx
movq %rax, %r15
jmp 0x19cff
leaq -0x30(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2fdb0
movq %rax, %r12
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2fdb0
movq %r12, %rcx
movq %rax, %rdx
jmp 0x19e18
leaq -0x30(%rbp), %rdi
callq 0x2fdb0
movq -0x80(%rbp), %rdx
movq -0x60(%rbp), %r8
movq %rax, %r15
jmp 0x19fc4
leaq -0x30(%rbp), %rdi
movq %r9, %r14
movq %r8, %r15
callq 0x2fdb0
movq %r15, %r8
movq %r14, %r9
movq %rax, %r15
jmp 0x1a121
leaq -0x30(%rbp), %rdi
callq 0x2fdb0
movq -0x60(%rbp), %r9
movq %rax, %r12
jmp 0x1a017