// File: tomfunkhouser[P]gaps/pkgs/RNBasics/json.cpp
// Function: Json::valueToQuotedStringN[abi:cxx11](char const*, unsigned int)
static std::string valueToQuotedStringN(const char* value, unsigned length) {
  if (value == NULL)
    return "";
  // Not sure how to handle unicode...
  if (strnpbrk(value, "\"\\\b\f\n\r\t", length) == NULL &&
      !containsControlCharacter0(value, length))
    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 =
      length * 2 + 3; // allescaped+quotes+NULL
  std::string result;
  result.reserve(maxsize); // to avoid lots of mallocs
  result += "\"";
  char const* end = value + length;
  for (const char* c = value; c != end; ++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)) || (*c == 0)) {
        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, 0x48(%rsp)
movq %rdi, %rax
movq %rax, 0x50(%rsp)
movq %rdi, 0x280(%rsp)
movq %rsi, 0x278(%rsp)
movl %edx, 0x274(%rsp)
cmpq $0x0, 0x278(%rsp)
jne 0xf3a98
leaq 0x273(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x12c30
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rdx
leaq 0x73ba6(%rip), %rsi     # 0x1675ff
callq 0x22830
jmp 0xf3a60
leaq 0x273(%rsp), %rdi
callq 0x12760
jmp 0xf3f74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x273(%rsp), %rdi
callq 0x12760
jmp 0xf3f81
movq 0x278(%rsp), %rdi
movl 0x274(%rsp), %eax
movl %eax, %edx
leaq 0x77135(%rip), %rsi     # 0x16abe5
callq 0xf9120
cmpq $0x0, %rax
jne 0xf3bda
movq 0x278(%rsp), %rdi
movl 0x274(%rsp), %esi
callq 0xf91d0
testb $0x1, %al
jne 0xf3bda
leaq 0x21f(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x12c30
movq 0x38(%rsp), %rdx
leaq 0x770f5(%rip), %rsi     # 0x16abee
leaq 0x220(%rsp), %rdi
callq 0x22830
jmp 0xf3b08
movq 0x278(%rsp), %rdx
leaq 0x240(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0x228f0
jmp 0xf3b27
movq 0x48(%rsp), %rdi
leaq 0x770bb(%rip), %rdx     # 0x16abee
leaq 0x240(%rsp), %rsi
callq 0x228f0
jmp 0xf3b42
leaq 0x240(%rsp), %rdi
callq 0x12430
leaq 0x220(%rsp), %rdi
callq 0x12430
leaq 0x21f(%rsp), %rdi
callq 0x12760
jmp 0xf3f74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xf3bc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xf3bbb
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 0xf3f81
movq 0x48(%rsp), %rdi
movl 0x274(%rsp), %ecx
movl %ecx, %eax
leal 0x3(%rax,%rax), %eax
movq %rax, 0x210(%rsp)
movb $0x0, 0x20f(%rsp)
callq 0x129f0
movq 0x48(%rsp), %rdi
movq 0x210(%rsp), %rsi
callq 0x12af0
jmp 0xf3c15
movq 0x48(%rsp), %rdi
leaq 0x76fcd(%rip), %rsi     # 0x16abee
callq 0x12670
jmp 0xf3c28
movq 0x278(%rsp), %rax
movl 0x274(%rsp), %ecx
addq %rcx, %rax
movq %rax, 0x200(%rsp)
movq 0x278(%rsp), %rax
movq %rax, 0x1f8(%rsp)
movq 0x1f8(%rsp), %rax
cmpq 0x200(%rsp), %rax
je 0xf3f37
movq 0x1f8(%rsp), %rax
movsbl (%rax), %eax
movl %eax, 0x34(%rsp)
subl $0x8, %eax
je 0xf3d20
jmp 0xf3c82
movl 0x34(%rsp), %eax
subl $0x9, %eax
je 0xf3d80
jmp 0xf3c91
movl 0x34(%rsp), %eax
subl $0xa, %eax
je 0xf3d50
jmp 0xf3ca0
movl 0x34(%rsp), %eax
subl $0xc, %eax
je 0xf3d38
jmp 0xf3caf
movl 0x34(%rsp), %eax
subl $0xd, %eax
je 0xf3d68
jmp 0xf3cbe
movl 0x34(%rsp), %eax
subl $0x22, %eax
je 0xf3cf0
jmp 0xf3cc9
movl 0x34(%rsp), %eax
subl $0x5c, %eax
je 0xf3d08
jmp 0xf3d98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xf3f68
movq 0x48(%rsp), %rdi
leaq 0x76ef1(%rip), %rsi     # 0x16abed
callq 0x12670
jmp 0xf3d03
jmp 0xf3f1c
movq 0x48(%rsp), %rdi
leaq 0x76edc(%rip), %rsi     # 0x16abf0
callq 0x12670
jmp 0xf3d1b
jmp 0xf3f1c
movq 0x48(%rsp), %rdi
leaq 0x76ec7(%rip), %rsi     # 0x16abf3
callq 0x12670
jmp 0xf3d33
jmp 0xf3f1c
movq 0x48(%rsp), %rdi
leaq 0x76eb2(%rip), %rsi     # 0x16abf6
callq 0x12670
jmp 0xf3d4b
jmp 0xf3f1c
movq 0x48(%rsp), %rdi
leaq 0x76e9d(%rip), %rsi     # 0x16abf9
callq 0x12670
jmp 0xf3d63
jmp 0xf3f1c
movq 0x48(%rsp), %rdi
leaq 0x76e88(%rip), %rsi     # 0x16abfc
callq 0x12670
jmp 0xf3d7b
jmp 0xf3f1c
movq 0x48(%rsp), %rdi
leaq 0x76e73(%rip), %rsi     # 0x16abff
callq 0x12670
jmp 0xf3d93
jmp 0xf3f1c
movq 0x1f8(%rsp), %rax
movsbl (%rax), %edi
callq 0xf3320
testb $0x1, %al
jne 0xf3dc0
movq 0x1f8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xf3f01
leaq 0x80(%rsp), %rdi
callq 0x12980
jmp 0xf3dcf
leaq 0x76e2c(%rip), %rsi     # 0x16ac02
leaq 0x80(%rsp), %rdi
callq 0x126b0
movq %rax, 0x28(%rsp)
jmp 0xf3dea
movq 0x28(%rsp), %rdi
leaq 0x6dda(%rip), %rsi      # 0xfabd0
callq 0x12220
movq %rax, 0x20(%rsp)
jmp 0xf3e02
movq 0x20(%rsp), %rdi
leaq 0x6de2(%rip), %rsi      # 0xfabf0
callq 0x12220
movq %rax, 0x18(%rsp)
jmp 0xf3e1a
movl $0x30, %edi
callq 0xfac10
movb %al, 0x17(%rsp)
jmp 0xf3e2a
movq 0x18(%rsp), %rdi
movb 0x17(%rsp), %al
movb %al, 0x7f(%rsp)
movzbl 0x7f(%rsp), %esi
callq 0x12b00
movq %rax, 0x8(%rsp)
jmp 0xf3e48
movl $0x4, %edi
callq 0xfac30
movq 0x8(%rsp), %rdi
movl %eax, 0x78(%rsp)
movl 0x78(%rsp), %esi
callq 0x12810
movq %rax, (%rsp)
jmp 0xf3e6a
movq (%rsp), %rdi
movq 0x1f8(%rsp), %rax
movsbl (%rax), %esi
callq 0x12bf0
jmp 0xf3e80
leaq 0x58(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x12700
jmp 0xf3e94
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x12910
jmp 0xf3ea5
leaq 0x58(%rsp), %rdi
callq 0x12430
leaq 0x80(%rsp), %rdi
callq 0x121a0
jmp 0xf3f1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xf3ef2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x12430
leaq 0x80(%rsp), %rdi
callq 0x121a0
jmp 0xf3f68
movq 0x48(%rsp), %rdi
movq 0x1f8(%rsp), %rax
movsbl (%rax), %esi
callq 0x12450
jmp 0xf3f18
jmp 0xf3f1a
jmp 0xf3f1c
jmp 0xf3f1e
movq 0x1f8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1f8(%rsp)
jmp 0xf3c52
movq 0x48(%rsp), %rdi
leaq 0x76cab(%rip), %rsi     # 0x16abee
callq 0x12670
jmp 0xf3f4a
movb $0x1, 0x20f(%rsp)
testb $0x1, 0x20f(%rsp)
jne 0xf3f66
movq 0x48(%rsp), %rdi
callq 0x12430
jmp 0xf3f74
movq 0x48(%rsp), %rdi
callq 0x12430
jmp 0xf3f81
movq 0x50(%rsp), %rax
addq $0x288, %rsp            # imm = 0x288
retq
movq 0x268(%rsp), %rdi
callq 0x12c20
nop