// File: tomfunkhouser[P]gaps/pkgs/RNBasics/json.cpp
// Function: Json::valueToQuotedString[abi:cxx11](char const*)
std::string valueToQuotedString(const char* value) {
  if (value == NULL)
    return "";
  // Not sure how to handle unicode...
  if (strpbrk(value, "\"\\\b\f\n\r\t") == NULL &&
      !containsControlCharacter(value))
    return std::string("\"") + value + "\"";
  // We have to walk value and escape any special characters.
  // Appending to std::string is not efficient, but this should be rare.
  // (Note: forward slashes are *not* rare, but I am not escaping them.)
  std::string::size_type maxsize =
      strlen(value) * 2 + 3; // allescaped+quotes+NULL
  std::string result;
  result.reserve(maxsize); // to avoid lots of mallocs
  result += "\"";
  for (const char* c = value; *c != 0; ++c) {
    switch (*c) {
    case '\"':
      result += "\\\"";
      break;
    case '\\':
      result += "\\\\";
      break;
    case '\b':
      result += "\\b";
      break;
    case '\f':
      result += "\\f";
      break;
    case '\n':
      result += "\\n";
      break;
    case '\r':
      result += "\\r";
      break;
    case '\t':
      result += "\\t";
      break;
    // case '/':
    // Even though \/ is considered a legal escape in JSON, a bare
    // slash is also legal, so I see no reason to escape it.
    // (I hope I am not misunderstanding something.
    // blep notes: actually escaping \/ may be useful in javascript to avoid </
    // sequence.
    // Should add a flag to allow this compatibility mode and prevent this
    // sequence from occurring.
    default:
      if (isControlCharacter(*c)) {
        std::ostringstream oss;
        oss << "\\u" << std::hex << std::uppercase << std::setfill('0')
            << std::setw(4) << static_cast<int>(*c);
        result += oss.str();
      } else {
        result += *c;
      }
      break;
    }
  }
  result += "\"";
  return result;
}

// Assembly:
subq $0x288, %rsp            # imm = 0x288
movq %rdi, 0x50(%rsp)
movq %rdi, %rax
movq %rax, 0x58(%rsp)
movq %rdi, 0x280(%rsp)
movq %rsi, 0x278(%rsp)
cmpq $0x0, 0x278(%rsp)
jne 0xf2de1
leaq 0x277(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x12c30
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rdx
leaq 0x7485d(%rip), %rsi     # 0x1675ff
callq 0x22830
jmp 0xf2da9
leaq 0x277(%rsp), %rdi
callq 0x12760
jmp 0xf32a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x277(%rsp), %rdi
callq 0x12760
jmp 0xf32b4
movq 0x278(%rsp), %rdi
leaq 0x77df5(%rip), %rsi     # 0x16abe5
callq 0x12c10
cmpq $0x0, %rax
jne 0xf2f13
movq 0x278(%rsp), %rdi
callq 0xf32d0
testb $0x1, %al
jne 0xf2f13
leaq 0x21f(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x12c30
movq 0x40(%rsp), %rdx
leaq 0x77dbc(%rip), %rsi     # 0x16abee
leaq 0x220(%rsp), %rdi
callq 0x22830
jmp 0xf2e41
movq 0x278(%rsp), %rdx
leaq 0x240(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0x228f0
jmp 0xf2e60
movq 0x50(%rsp), %rdi
leaq 0x77d82(%rip), %rdx     # 0x16abee
leaq 0x240(%rsp), %rsi
callq 0x228f0
jmp 0xf2e7b
leaq 0x240(%rsp), %rdi
callq 0x12430
leaq 0x220(%rsp), %rdi
callq 0x12430
leaq 0x21f(%rsp), %rdi
callq 0x12760
jmp 0xf32a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xf2f01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xf2ef4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x12430
leaq 0x220(%rsp), %rdi
callq 0x12430
leaq 0x21f(%rsp), %rdi
callq 0x12760
jmp 0xf32b4
movq 0x278(%rsp), %rdi
callq 0x122b0
movq 0x50(%rsp), %rdi
leaq 0x3(%rax,%rax), %rax
movq %rax, 0x210(%rsp)
movb $0x0, 0x20f(%rsp)
callq 0x129f0
movq 0x50(%rsp), %rdi
movq 0x210(%rsp), %rsi
callq 0x12af0
jmp 0xf2f53
movq 0x50(%rsp), %rdi
leaq 0x77c8f(%rip), %rsi     # 0x16abee
callq 0x12670
jmp 0xf2f66
movq 0x278(%rsp), %rax
movq %rax, 0x200(%rsp)
movq 0x200(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xf326a
movq 0x200(%rsp), %rax
movsbl (%rax), %eax
movl %eax, 0x3c(%rsp)
subl $0x8, %eax
je 0xf3042
jmp 0xf2fa4
movl 0x3c(%rsp), %eax
subl $0x9, %eax
je 0xf30a2
jmp 0xf2fb3
movl 0x3c(%rsp), %eax
subl $0xa, %eax
je 0xf3072
jmp 0xf2fc2
movl 0x3c(%rsp), %eax
subl $0xc, %eax
je 0xf305a
jmp 0xf2fd1
movl 0x3c(%rsp), %eax
subl $0xd, %eax
je 0xf308a
jmp 0xf2fe0
movl 0x3c(%rsp), %eax
subl $0x22, %eax
je 0xf3012
jmp 0xf2feb
movl 0x3c(%rsp), %eax
subl $0x5c, %eax
je 0xf302a
jmp 0xf30ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xf329b
movq 0x50(%rsp), %rdi
leaq 0x77bcf(%rip), %rsi     # 0x16abed
callq 0x12670
jmp 0xf3025
jmp 0xf324f
movq 0x50(%rsp), %rdi
leaq 0x77bba(%rip), %rsi     # 0x16abf0
callq 0x12670
jmp 0xf303d
jmp 0xf324f
movq 0x50(%rsp), %rdi
leaq 0x77ba5(%rip), %rsi     # 0x16abf3
callq 0x12670
jmp 0xf3055
jmp 0xf324f
movq 0x50(%rsp), %rdi
leaq 0x77b90(%rip), %rsi     # 0x16abf6
callq 0x12670
jmp 0xf306d
jmp 0xf324f
movq 0x50(%rsp), %rdi
leaq 0x77b7b(%rip), %rsi     # 0x16abf9
callq 0x12670
jmp 0xf3085
jmp 0xf324f
movq 0x50(%rsp), %rdi
leaq 0x77b66(%rip), %rsi     # 0x16abfc
callq 0x12670
jmp 0xf309d
jmp 0xf324f
movq 0x50(%rsp), %rdi
leaq 0x77b51(%rip), %rsi     # 0x16abff
callq 0x12670
jmp 0xf30b5
jmp 0xf324f
movq 0x200(%rsp), %rax
movsbl (%rax), %edi
callq 0xf3320
movb %al, 0x3b(%rsp)
jmp 0xf30d0
movb 0x3b(%rsp), %al
testb $0x1, %al
jne 0xf30dd
jmp 0xf3234
leaq 0x88(%rsp), %rdi
callq 0x12980
jmp 0xf30ec
leaq 0x77b0f(%rip), %rsi     # 0x16ac02
leaq 0x88(%rsp), %rdi
callq 0x126b0
movq %rax, 0x30(%rsp)
jmp 0xf3107
movq 0x30(%rsp), %rdi
leaq 0x7abd(%rip), %rsi      # 0xfabd0
callq 0x12220
movq %rax, 0x28(%rsp)
jmp 0xf311f
movq 0x28(%rsp), %rdi
leaq 0x7ac5(%rip), %rsi      # 0xfabf0
callq 0x12220
movq %rax, 0x20(%rsp)
jmp 0xf3137
movl $0x30, %edi
callq 0xfac10
movb %al, 0x1f(%rsp)
jmp 0xf3147
movq 0x20(%rsp), %rdi
movb 0x1f(%rsp), %al
movb %al, 0x87(%rsp)
movzbl 0x87(%rsp), %esi
callq 0x12b00
movq %rax, 0x10(%rsp)
jmp 0xf316b
movl $0x4, %edi
callq 0xfac30
movl %eax, 0xc(%rsp)
jmp 0xf317b
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %eax
movl %eax, 0x80(%rsp)
movl 0x80(%rsp), %esi
callq 0x12810
movq %rax, (%rsp)
jmp 0xf319d
movq (%rsp), %rdi
movq 0x200(%rsp), %rax
movsbl (%rax), %esi
callq 0x12bf0
jmp 0xf31b3
leaq 0x60(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x12700
jmp 0xf31c7
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x12910
jmp 0xf31d8
leaq 0x60(%rsp), %rdi
callq 0x12430
leaq 0x88(%rsp), %rdi
callq 0x121a0
jmp 0xf324d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xf3225
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x12430
leaq 0x88(%rsp), %rdi
callq 0x121a0
jmp 0xf329b
movq 0x50(%rsp), %rdi
movq 0x200(%rsp), %rax
movsbl (%rax), %esi
callq 0x12450
jmp 0xf324b
jmp 0xf324d
jmp 0xf324f
jmp 0xf3251
movq 0x200(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x200(%rsp)
jmp 0xf2f76
movq 0x50(%rsp), %rdi
leaq 0x77978(%rip), %rsi     # 0x16abee
callq 0x12670
jmp 0xf327d
movb $0x1, 0x20f(%rsp)
testb $0x1, 0x20f(%rsp)
jne 0xf3299
movq 0x50(%rsp), %rdi
callq 0x12430
jmp 0xf32a7
movq 0x50(%rsp), %rdi
callq 0x12430
jmp 0xf32b4
movq 0x58(%rsp), %rax
addq $0x288, %rsp            # imm = 0x288
retq
movq 0x268(%rsp), %rdi
callq 0x12c20
nopw %cs:(%rax,%rax)