// File: /workspace/github_c_makefile_star2_O3/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 0x3efa
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), %ebx
cmpl $0x2d, %ebx
je 0x3db9
cmpl $0x2b, %ebx
jne 0x3dca
leaq 0x1(%r14), %r15
movb %bl, (%r14)
movb 0x1(%r12), %bl
incq %r12
jmp 0x3dcd
movq %r14, %r15
cmpb $0x5f, %bl
je 0x3eec
movq %rsi, 0x8(%rsp)
movq %r12, %rdi
movl $0x2e, %esi
callq 0x10c0
testq %rax, %rax
je 0x3e1d
movq %rax, %r13
cmpq %r12, %rax
je 0x3e92
callq 0x11f0
movq (%rax), %rax
movsbq -0x1(%r13), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x3e92
movsbq 0x1(%r13), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x3e92
cmpb $0x30, %bl
jne 0x3e42
movsbl 0x1(%r12), %esi
testl %esi, %esi
je 0x3e42
leaq 0x23a7(%rip), %rdi      # 0x61da
movl $0x4, %edx
callq 0x1130
testq %rax, %rax
je 0x3e92
movslq %ebp, %rsi
addq %r14, %rsi
testb %bl, %bl
setne %cl
cmpq %rsi, %r15
setb %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x3e99
incq %r12
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpb $0x5f, %bl
jne 0x3e77
movzbl (%r12), %ebx
testl %ebx, %ebx
je 0x3eec
cmpl $0x5f, %ebx
jne 0x3e81
jmp 0x3eec
movb %bl, (%r15)
incq %r15
movb (%r12), %bl
testb %bl, %bl
setne %cl
je 0x3e9e
incq %r12
cmpq %rsi, %r15
jb 0x3e62
jmp 0x3e9e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3eec
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rsi, %r15
sete %dl
orb %cl, %dl
jne 0x3eec
movb $0x0, (%r15)
callq 0x1050
movq %rax, %r12
movl $0x0, (%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x1090
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x3ed5
movsd %xmm0, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x0, (%r12)
jne 0x3eec
movq 0x10(%rsp), %rcx
xorl %eax, %eax
cmpb (%rcx), %al
sbbl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq