// File: /workspace/github_c_makefile_star2_O1/cktan[P]tomlc99/toml.c
// Function: toml_rtod_ex
int toml_rtod_ex(toml_raw_t src, double *ret_, char *buf, int buflen) {
  if (!src)
    return -1;

  char *p = buf;
  char *q = p + buflen;
  const char *s = src;
  double dummy;
  double *ret = ret_ ? ret_ : &dummy;

  /* allow +/- */
  if (s[0] == '+' || s[0] == '-')
    *p++ = *s++;

  /* disallow +_1.00 */
  if (s[0] == '_')
    return -1;

  /* decimal point, if used, must be surrounded by at least one digit on each
   * side */
  {
    char *dot = strchr(s, '.');
    if (dot) {
      if (dot == s || !isdigit(dot[-1]) || !isdigit(dot[1]))
        return -1;
    }
  }

  /* zero must be followed by . or 'e', or NUL */
  if (s[0] == '0' && s[1] && !strchr("eE.", s[1]))
    return -1;

  /* just strip underscores and pass to strtod */
  while (*s && p < q) {
    int ch = *s++;
    if (ch == '_') {
      // disallow '__'
      if (s[0] == '_')
        return -1;
      // disallow last char '_'
      if (s[0] == 0)
        return -1;
      continue; /* skip _ */
    }
    *p++ = ch;
  }
  if (*s || p == q)
    return -1; /* reached end of string or buffer is full? */

  /* cap with NUL */
  *p = 0;

  /* Run strtod on buf to get the value */
  char *endp;
  errno = 0;
  *ret = strtod(buf, &endp);
  return (errno || *endp) ? -1 : 0;
}

// Assembly:
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x411c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movq %rdi, %r12
movzbl (%rdi), %ecx
cmpl $0x2d, %ecx
je 0x3fc3
cmpl $0x2b, %ecx
jne 0x3fcf
incq %r12
leaq 0x1(%r14), %r15
movb %cl, (%r14)
jmp 0x3fd2
movq %r14, %r15
movb (%r12), %bl
cmpb $0x5f, %bl
je 0x410e
movq %rsi, 0x8(%rsp)
movq %r12, %rdi
movl $0x2e, %esi
callq 0x10d0
testq %rax, %rax
je 0x402a
movq %rax, %r13
cmpq %r12, %rax
je 0x4109
callq 0x1200
movq (%rax), %rax
movsbq -0x1(%r13), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x4109
movsbq 0x1(%r13), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x4109
cmpb $0x30, %bl
jne 0x4053
movsbl 0x1(%r12), %esi
testl %esi, %esi
je 0x4053
leaq 0x2176(%rip), %rdi      # 0x61b6
movl $0x4, %edx
callq 0x1140
testq %rax, %rax
je 0x4109
movslq %ebp, %rax
addq %r14, %rax
movb (%r12), %cl
testb %cl, %cl
setne %dl
cmpq %rax, %r15
setb %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x40b4
incq %r12
cmpb $0x5f, %cl
jne 0x4094
movzbl (%r12), %edx
movl $0x1, %ecx
testl %edx, %edx
je 0x409c
cmpl $0x5f, %edx
je 0x409c
movl $0x2, %ecx
jmp 0x409c
movb %cl, (%r15)
incq %r15
xorl %ecx, %ecx
testb $0x1, %cl
jne 0x4109
movb (%r12), %cl
testb %cl, %cl
setne %dl
je 0x40b4
incq %r12
cmpq %rax, %r15
jb 0x4075
cmpq %rax, %r15
sete %al
orb %dl, %al
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jne 0x410e
movb $0x0, (%r15)
callq 0x1050
movq %rax, %r12
movl $0x0, (%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x10a0
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x40f0
movsd %xmm0, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x0, (%r12)
jne 0x410e
movq 0x10(%rsp), %rcx
xorl %eax, %eax
cmpb (%rcx), %al
sbbl %eax, %eax
jmp 0x410e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq