// File: DoubleString[P]RtConverter/src/Json/json_writer.cpp
// Function: Json::valueToQuotedStringN[abi:cxx11](char const*, unsigned int)
static JSONCPP_STRING valueToQuotedStringN(const char* value, unsigned length) {
  if (value == NULL)
    return "";

  if (!isAnyCharRequiredQuoting(value, length))
    return JSONCPP_STRING("\"") + value + "\"";
  // We have to walk value and escape any special characters.
  // Appending to JSONCPP_STRING is not efficient, but this should be rare.
  // (Note: forward slashes are *not* rare, but I am not escaping them.)
  JSONCPP_STRING::size_type maxsize = length * 2 + 3; // allescaped+quotes+NULL
  JSONCPP_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: {
      unsigned int cp = utf8ToCodepoint(c, end);
      // don't escape non-control characters
      // (short escape sequence are applied above)
      if (cp < 0x80 && cp >= 0x20)
        result += static_cast<char>(cp);
      else if (cp < 0x10000) { // codepoint is in Basic Multilingual Plane
        result += "\\u";
        result += toHex16Bit(cp);
      } else { // codepoint is not in Basic Multilingual Plane
               // convert to surrogate pair first
        cp -= 0x10000;
        result += "\\u";
        result += toHex16Bit((cp >> 10) + 0xD800);
        result += "\\u";
        result += toHex16Bit((cp & 0x3FF) + 0xDC00);
      }
    } break;
    }
  }
  result += "\"";
  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x108(%rbp)
movq %rdi, %rax
movq %rax, -0x100(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x2b502
leaq -0x15(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x9d30
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rdx
leaq 0x91834(%rip), %rsi     # 0xbcd07
callq 0x9a30
jmp 0x2b4da
leaq -0x15(%rbp), %rdi
callq 0x97e0
jmp 0x2b9a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x15(%rbp), %rdi
callq 0x97e0
jmp 0x2b9b2
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, %esi
callq 0x31020
testb $0x1, %al
jne 0x2b5d5
leaq -0x69(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x9d30
movq -0x118(%rbp), %rdx
leaq 0x9185f(%rip), %rsi     # 0xbcd95
leaq -0x68(%rbp), %rdi
callq 0x9a30
jmp 0x2b541
movq -0x10(%rbp), %rdx
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x145e0
jmp 0x2b554
movq -0x108(%rbp), %rdi
leaq 0x91833(%rip), %rdx     # 0xbcd95
leaq -0x48(%rbp), %rsi
callq 0x145e0
jmp 0x2b56d
leaq -0x48(%rbp), %rdi
callq 0x9480
leaq -0x68(%rbp), %rdi
callq 0x9480
leaq -0x69(%rbp), %rdi
callq 0x97e0
jmp 0x2b9a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x2b5c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x2b5be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x9480
leaq -0x68(%rbp), %rdi
callq 0x9480
leaq -0x69(%rbp), %rdi
callq 0x97e0
jmp 0x2b9b2
movq -0x108(%rbp), %rdi
movl -0x14(%rbp), %ecx
movl %ecx, %eax
leal 0x3(%rax,%rax), %eax
movq %rax, -0x78(%rbp)
movb $0x0, -0x79(%rbp)
callq 0x9a50
movq -0x108(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x9b90
jmp 0x2b604
movq -0x108(%rbp), %rdi
leaq 0x91783(%rip), %rsi     # 0xbcd95
callq 0x9740
jmp 0x2b619
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x88(%rbp), %rax
je 0x2b967
movq -0x90(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x11c(%rbp)
subl $0x8, %eax
je 0x2b70a
jmp 0x2b664
movl -0x11c(%rbp), %eax
subl $0x9, %eax
je 0x2b772
jmp 0x2b675
movl -0x11c(%rbp), %eax
subl $0xa, %eax
je 0x2b73e
jmp 0x2b686
movl -0x11c(%rbp), %eax
subl $0xc, %eax
je 0x2b724
jmp 0x2b697
movl -0x11c(%rbp), %eax
subl $0xd, %eax
je 0x2b758
jmp 0x2b6a8
movl -0x11c(%rbp), %eax
subl $0x22, %eax
je 0x2b6d6
jmp 0x2b6b5
movl -0x11c(%rbp), %eax
subl $0x5c, %eax
je 0x2b6f0
jmp 0x2b78c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x2b994
movq -0x108(%rbp), %rdi
leaq 0x916b0(%rip), %rsi     # 0xbcd94
callq 0x9740
jmp 0x2b6eb
jmp 0x2b94e
movq -0x108(%rbp), %rdi
leaq 0x91699(%rip), %rsi     # 0xbcd97
callq 0x9740
jmp 0x2b705
jmp 0x2b94e
movq -0x108(%rbp), %rdi
leaq 0x91682(%rip), %rsi     # 0xbcd9a
callq 0x9740
jmp 0x2b71f
jmp 0x2b94e
movq -0x108(%rbp), %rdi
leaq 0x9166b(%rip), %rsi     # 0xbcd9d
callq 0x9740
jmp 0x2b739
jmp 0x2b94e
movq -0x108(%rbp), %rdi
leaq 0x91654(%rip), %rsi     # 0xbcda0
callq 0x9740
jmp 0x2b753
jmp 0x2b94e
movq -0x108(%rbp), %rdi
leaq 0x9163d(%rip), %rsi     # 0xbcda3
callq 0x9740
jmp 0x2b76d
jmp 0x2b94e
movq -0x108(%rbp), %rdi
leaq 0x91626(%rip), %rsi     # 0xbcda6
callq 0x9740
jmp 0x2b787
jmp 0x2b94e
movq -0x88(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x310f0
movl %eax, -0x120(%rbp)
jmp 0x2b7a7
movl -0x120(%rbp), %eax
movl %eax, -0x94(%rbp)
cmpl $0x80, -0x94(%rbp)
jae 0x2b7e2
cmpl $0x20, -0x94(%rbp)
jb 0x2b7e2
movq -0x108(%rbp), %rdi
movsbl -0x94(%rbp), %esi
callq 0x9490
jmp 0x2b7dd
jmp 0x2b94c
cmpl $0x10000, -0x94(%rbp)   # imm = 0x10000
jae 0x2b85a
movq -0x108(%rbp), %rdi
leaq 0x915ad(%rip), %rsi     # 0xbcda9
callq 0x9740
jmp 0x2b803
movl -0x94(%rbp), %esi
leaq -0xb8(%rbp), %rdi
callq 0x312f0
jmp 0x2b817
movq -0x108(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x9980
jmp 0x2b82c
leaq -0xb8(%rbp), %rdi
callq 0x9480
jmp 0x2b94a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x9480
jmp 0x2b994
movq -0x108(%rbp), %rdi
movl -0x94(%rbp), %eax
addl $0xffff0000, %eax       # imm = 0xFFFF0000
movl %eax, -0x94(%rbp)
leaq 0x91530(%rip), %rsi     # 0xbcda9
callq 0x9740
jmp 0x2b880
movl -0x94(%rbp), %esi
shrl $0xa, %esi
addl $0xd800, %esi           # imm = 0xD800
leaq -0xd8(%rbp), %rdi
callq 0x312f0
jmp 0x2b89d
movq -0x108(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x9980
jmp 0x2b8b2
leaq -0xd8(%rbp), %rdi
callq 0x9480
movq -0x108(%rbp), %rdi
leaq 0x914dd(%rip), %rsi     # 0xbcda9
callq 0x9740
jmp 0x2b8d3
movl -0x94(%rbp), %esi
andl $0x3ff, %esi            # imm = 0x3FF
orl $0xdc00, %esi           # imm = 0xDC00
leaq -0xf8(%rbp), %rdi
callq 0x312f0
jmp 0x2b8f3
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x9980
jmp 0x2b908
leaq -0xf8(%rbp), %rdi
callq 0x9480
jmp 0x2b94a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x9480
jmp 0x2b994
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x9480
jmp 0x2b994
jmp 0x2b94c
jmp 0x2b94e
jmp 0x2b950
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x2b635
movq -0x108(%rbp), %rdi
leaq 0x91420(%rip), %rsi     # 0xbcd95
callq 0x9740
jmp 0x2b97c
movb $0x1, -0x79(%rbp)
testb $0x1, -0x79(%rbp)
jne 0x2b992
movq -0x108(%rbp), %rdi
callq 0x9480
jmp 0x2b9a2
movq -0x108(%rbp), %rdi
callq 0x9480
jmp 0x2b9b2
movq -0x100(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x9d20
nopl (%rax,%rax)