// File: tomfunkhouser[P]gaps/pkgs/RNBasics/json.cpp
// Function: Json::OurReader::decodeDouble(Json::OurReader::Token&, Json::Value&)
bool OurReader::decodeDouble(Token& token, Value& decoded) {
  double value = 0;
  const int bufferSize = 32;
  int count;
  ptrdiff_t const length = token.end_ - token.start_;

  // Sanity check to avoid buffer overflow exploits.
  if (length < 0) {
    return addError("Unable to parse token length", token);
  }
  size_t const ulength = static_cast<size_t>(length);

  // Avoid using a string constant for the format control string given to
  // sscanf, as this can cause hard to debug crashes on OS X. See here for more
  // info:
  //
  //     http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/Incompatibilities.html
  char format[] = "%lf";

  if (length <= bufferSize) {
    Char buffer[bufferSize + 1];
    memcpy(buffer, token.start_, ulength);
    buffer[length] = 0;
    count = sscanf(buffer, format, &value);
  } else {
    std::string buffer(token.start_, token.end_);
    count = sscanf(buffer.c_str(), format, &value);
  }

  if (count != 1)
    return addError("'" + std::string(token.start_, token.end_) +
                        "' is not a number.",
                    token);
  decoded = value;
  return true;
}

// Assembly:
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, 0x1a8(%rsp)
movq %rsi, 0x1a0(%rsp)
movq %rdx, 0x198(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x190(%rsp)
movl $0x20, 0x18c(%rsp)
movq 0x1a0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x1a0(%rsp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movq %rax, 0x180(%rsp)
cmpq $0x0, 0x180(%rsp)
jge 0xe82bb
leaq 0x15f(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x12c30
movq 0x48(%rsp), %rdx
leaq 0x8235a(%rip), %rsi     # 0x16a56d
leaq 0x160(%rsp), %rdi
callq 0x22830
jmp 0xe8222
movq 0x50(%rsp), %rdi
movq 0x1a0(%rsp), %rdx
xorl %eax, %eax
movl %eax, %ecx
leaq 0x160(%rsp), %rsi
callq 0xe5c50
movb %al, 0x47(%rsp)
jmp 0xe8246
movb 0x47(%rsp), %al
andb $0x1, %al
movb %al, 0x1b7(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x12430
leaq 0x15f(%rsp), %rdi
callq 0x12760
jmp 0xe85e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xe82a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x12430
leaq 0x15f(%rsp), %rdi
callq 0x12760
jmp 0xe85f2
movq 0x180(%rsp), %rax
movq %rax, 0x140(%rsp)
movl 0x80bbd(%rip), %eax     # 0x168e8e
movl %eax, 0x13c(%rsp)
cmpq $0x20, 0x180(%rsp)
jg 0xe833f
leaq 0x110(%rsp), %rdi
movq 0x1a0(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x140(%rsp), %rdx
callq 0x12590
movq 0x180(%rsp), %rax
movb $0x0, 0x110(%rsp,%rax)
leaq 0x110(%rsp), %rdi
leaq 0x13c(%rsp), %rsi
leaq 0x190(%rsp), %rdx
movb $0x0, %al
callq 0x126a0
movl %eax, 0x188(%rsp)
jmp 0xe83f9
movq 0x1a0(%rsp), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x28(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x30(%rsp)
leaq 0xef(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x12c30
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
leaq 0xf0(%rsp), %rdi
callq 0xf9320
jmp 0xe8389
leaq 0xef(%rsp), %rdi
callq 0x12760
leaq 0xf0(%rsp), %rdi
callq 0x12280
movq %rax, %rdi
leaq 0x13c(%rsp), %rsi
leaq 0x190(%rsp), %rdx
movb $0x0, %al
callq 0x126a0
movl %eax, 0x188(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x12430
jmp 0xe83f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0xef(%rsp), %rdi
callq 0x12760
jmp 0xe85f2
cmpl $0x1, 0x188(%rsp)
je 0xe8583
movq 0x1a0(%rsp), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x18(%rsp)
leaq 0x87(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x12c30
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
leaq 0x88(%rsp), %rdi
callq 0xf9320
jmp 0xe8451
leaq 0x82113(%rip), %rsi     # 0x16a56b
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0xf93a0
jmp 0xe846f
leaq 0x81f1f(%rip), %rdx     # 0x16a395
leaq 0xc8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x228f0
jmp 0xe848d
movq 0x50(%rsp), %rdi
movq 0x1a0(%rsp), %rdx
xorl %eax, %eax
movl %eax, %ecx
leaq 0xc8(%rsp), %rsi
callq 0xe5c50
movb %al, 0xf(%rsp)
jmp 0xe84b1
movb 0xf(%rsp), %al
andb $0x1, %al
movb %al, 0x1b7(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x12430
leaq 0xa8(%rsp), %rdi
callq 0x12430
leaq 0x88(%rsp), %rdi
callq 0x12430
leaq 0x87(%rsp), %rdi
callq 0x12760
jmp 0xe85e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xe8574
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xe8567
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0xe855a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x12430
leaq 0xa8(%rsp), %rdi
callq 0x12430
leaq 0x88(%rsp), %rdi
callq 0x12430
leaq 0x87(%rsp), %rdi
callq 0x12760
jmp 0xe85f2
movsd 0x190(%rsp), %xmm0
leaq 0x58(%rsp), %rdi
movq %rdi, (%rsp)
callq 0xece60
movq (%rsp), %rsi
movq 0x198(%rsp), %rdi
callq 0xe3700
jmp 0xe85ad
leaq 0x58(%rsp), %rdi
callq 0xed680
movb $0x1, 0x1b7(%rsp)
jmp 0xe85e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
leaq 0x58(%rsp), %rdi
callq 0xed680
jmp 0xe85f2
movb 0x1b7(%rsp), %al
andb $0x1, %al
addq $0x1b8, %rsp            # imm = 0x1B8
retq
movq 0x150(%rsp), %rdi
callq 0x12c20
nop