// File: tomfunkhouser[P]gaps/pkgs/RNBasics/json.cpp
// Function: Json::Reader::decodeUnicodeCodePoint(Json::Reader::Token&, char const*&, char const*, unsigned int&)
bool Reader::decodeUnicodeCodePoint(Token& token,
                                    Location& current,
                                    Location end,
                                    unsigned int& unicode) {

  if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
    return false;
  if (unicode >= 0xD800 && unicode <= 0xDBFF) {
    // surrogate pairs
    if (end - current < 6)
      return addError(
          "additional six characters expected to parse unicode surrogate pair.",
          token,
          current);
    unsigned int surrogatePair;
    if (*(current++) == '\\' && *(current++) == 'u') {
      if (decodeUnicodeEscapeSequence(token, current, end, surrogatePair)) {
        unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF);
      } else
        return false;
    } else
      return addError("expecting another \\u token to begin the second half of "
                      "a unicode surrogate pair",
                      token,
                      current);
  }
  return true;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq %rdx, 0x98(%rsp)
movq %rcx, 0x90(%rsp)
movq %r8, 0x88(%rsp)
movq 0xa8(%rsp), %rdi
movq %rdi, 0x20(%rsp)
movq 0xa0(%rsp), %rsi
movq 0x98(%rsp), %rdx
movq 0x90(%rsp), %rcx
movq 0x88(%rsp), %r8
callq 0xe3ec0
testb $0x1, %al
jne 0xe38f2
movb $0x0, 0xb7(%rsp)
jmp 0xe3b43
movq 0x88(%rsp), %rax
cmpl $0xd800, (%rax)         # imm = 0xD800
jb 0xe3b3b
movq 0x88(%rsp), %rax
cmpl $0xdbff, (%rax)         # imm = 0xDBFF
ja 0xe3b3b
movq 0x90(%rsp), %rax
movq 0x98(%rsp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
cmpq $0x6, %rax
jge 0xe39e6
leaq 0x67(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x12c30
movq 0x18(%rsp), %rdx
leaq 0x86a91(%rip), %rsi     # 0x16a3e6
leaq 0x68(%rsp), %rdi
callq 0x22830
jmp 0xe3961
movq 0x20(%rsp), %rdi
movq 0xa0(%rsp), %rdx
movq 0x98(%rsp), %rax
movq (%rax), %rcx
leaq 0x68(%rsp), %rsi
callq 0xe0aa0
movb %al, 0x17(%rsp)
jmp 0xe3989
movb 0x17(%rsp), %al
andb $0x1, %al
movb %al, 0xb7(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x12430
leaq 0x67(%rsp), %rdi
callq 0x12760
jmp 0xe3b43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0xe39d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x12430
leaq 0x67(%rsp), %rdi
callq 0x12760
jmp 0xe3b54
movq 0x98(%rsp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0xe3a93
movq 0x98(%rsp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
movsbl (%rax), %eax
cmpl $0x75, %eax
jne 0xe3a93
movq 0x20(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movq 0x98(%rsp), %rdx
movq 0x90(%rsp), %rcx
leaq 0x50(%rsp), %r8
callq 0xe3ec0
testb $0x1, %al
jne 0xe3a51
jmp 0xe3a81
movq 0x88(%rsp), %rax
movl (%rax), %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
shll $0xa, %ecx
addl $0x10000, %ecx          # imm = 0x10000
movl 0x50(%rsp), %eax
andl $0x3ff, %eax            # imm = 0x3FF
addl %eax, %ecx
movq 0x88(%rsp), %rax
movl %ecx, (%rax)
jmp 0xe3a8e
movb $0x0, 0xb7(%rsp)
jmp 0xe3b43
jmp 0xe3b39
leaq 0x2f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x12c30
movq 0x8(%rsp), %rdx
leaq 0x8697c(%rip), %rsi     # 0x16a42a
leaq 0x30(%rsp), %rdi
callq 0x22830
jmp 0xe3aba
movq 0x20(%rsp), %rdi
movq 0xa0(%rsp), %rdx
movq 0x98(%rsp), %rax
movq (%rax), %rcx
leaq 0x30(%rsp), %rsi
callq 0xe0aa0
movb %al, 0x7(%rsp)
jmp 0xe3ae2
movb 0x7(%rsp), %al
andb $0x1, %al
movb %al, 0xb7(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x12430
leaq 0x2f(%rsp), %rdi
callq 0x12760
jmp 0xe3b43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0xe3b2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x12430
leaq 0x2f(%rsp), %rdi
callq 0x12760
jmp 0xe3b54
jmp 0xe3b3b
movb $0x1, 0xb7(%rsp)
movb 0xb7(%rsp), %al
andb $0x1, %al
addq $0xb8, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0x12c20
nop