// File: tomfunkhouser[P]gaps/pkgs/RNBasics/json.cpp
// Function: Json::valueToString[abi:cxx11](double, bool, unsigned int)
std::string valueToString(double value, bool useSpecialFloats, unsigned int precision) {
  // Allocate a buffer that is more than large enough to store the 16 digits of
  // precision requested below.
  char buffer[32];
  int len = -1;

  char formatString[16];
  snprintf(formatString, sizeof(formatString), "%%.%dg", precision);

  // Print into the buffer. We need not request the alternative representation
  // that always has a decimal point because JSON doesn't distingish the
  // concepts of reals and integers.
  if (isfinite(value)) {
    len = snprintf(buffer, sizeof(buffer), formatString, value);
  } else {
    // IEEE standard states that NaN values will not compare to themselves
    if (value != value) {
      len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "NaN" : "null");
    } else if (value < 0) {
      len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "-Infinity" : "-1e+9999");
    } else {
      len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "Infinity" : "1e+9999");
    }
    // For those, we do not need to call fixNumLoc, but it is fast.
  }
  assert(len >= 0);
  fixNumericLocale(buffer, buffer + len);
  return buffer;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x18(%rsp)
movb %sil, %al
movq %rdi, %rcx
movq %rcx, 0x20(%rsp)
movq %rdi, 0x90(%rsp)
movsd %xmm0, 0x88(%rsp)
andb $0x1, %al
movb %al, 0x87(%rsp)
movl %edx, 0x80(%rsp)
movl $0xffffffff, 0x5c(%rsp) # imm = 0xFFFFFFFF
leaq 0x40(%rsp), %rdi
movl 0x80(%rsp), %ecx
movl $0x10, %esi
leaq 0x780da(%rip), %rdx     # 0x16abc2
movb $0x0, %al
callq 0x12b30
movsd 0x88(%rsp), %xmm0
callq 0xfab90
testb $0x1, %al
jne 0xf2b03
jmp 0xf2b2b
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rdx
movsd 0x88(%rsp), %xmm0
movl $0x20, %esi
movb $0x1, %al
callq 0x12b30
movl %eax, 0x5c(%rsp)
jmp 0xf2bec
movsd 0x88(%rsp), %xmm0
ucomisd 0x88(%rsp), %xmm0
jne 0xf2b43
jp 0xf2b43
jmp 0xf2b76
leaq 0x60(%rsp), %rdi
movb 0x87(%rsp), %cl
leaq 0x78077(%rip), %rdx     # 0x16abcd
leaq 0x7806c(%rip), %rax     # 0x16abc9
testb $0x1, %cl
cmovneq %rax, %rdx
movl $0x20, %esi
movb $0x0, %al
callq 0x12b30
movl %eax, 0x5c(%rsp)
jmp 0xf2bea
xorps %xmm0, %xmm0
ucomisd 0x88(%rsp), %xmm0
jbe 0xf2bb7
leaq 0x60(%rsp), %rdi
movb 0x87(%rsp), %cl
leaq 0x78045(%rip), %rdx     # 0x16abdc
leaq 0x78034(%rip), %rax     # 0x16abd2
testb $0x1, %cl
cmovneq %rax, %rdx
movl $0x20, %esi
movb $0x0, %al
callq 0x12b30
movl %eax, 0x5c(%rsp)
jmp 0xf2be8
leaq 0x60(%rsp), %rdi
movb 0x87(%rsp), %cl
leaq 0x78013(%rip), %rdx     # 0x16abdd
leaq 0x78002(%rip), %rax     # 0x16abd3
testb $0x1, %cl
cmovneq %rax, %rdx
movl $0x20, %esi
movb $0x0, %al
callq 0x12b30
movl %eax, 0x5c(%rsp)
jmp 0xf2bea
jmp 0xf2bec
movslq 0x5c(%rsp), %rax
leaq 0x60(%rsp,%rax), %rsi
leaq 0x60(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xf2c70
leaq 0x3f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x12c30
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x22830
jmp 0xf2c2a
leaq 0x3f(%rsp), %rdi
callq 0x12760
movq 0x20(%rsp), %rax
addq $0x98, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
leaq 0x3f(%rsp), %rdi
callq 0x12760
movq 0x30(%rsp), %rdi
callq 0x12c20
nopw %cs:(%rax,%rax)