// File: eatonphil[P]cpp-json/json.cpp
// Function: json::lex_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
std::tuple<JSONToken, int, std::string> lex_string(std::string raw_json,
                                                   int original_index) {
  int index = original_index;
  JSONToken token{"", JSONTokenType::String, index};
  std::string value = "";
  auto c = raw_json[index];
  if (c != '"') {
    return {token, original_index, ""};
  }
  index++;

  // TODO: handle nested quotes
  while (c = raw_json[index], c != '"') {
    if (index == raw_json.length()) {
      return {
          token, index,
          format_error("Unexpected EOF while lexing string", raw_json, index)};
    }

    token.value += c;
    index++;
  }
  index++;

  return {token, index, ""};
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rsi, -0x118(%rbp)
movq %rdi, -0x110(%rbp)
movq %rdi, %rax
movq %rax, -0x108(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x42b0
movq -0x100(%rbp), %rdx
leaq 0x104d9(%rip), %rsi     # 0x151eb
leaq -0x50(%rbp), %rdi
callq 0x8560
jmp 0x4d1d
movl $0x0, -0x30(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x2c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x8850
leaq -0x51(%rbp), %rdi
callq 0x41d0
leaq -0x89(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x42b0
movq -0x120(%rbp), %rdx
leaq 0x1048e(%rip), %rsi     # 0x151eb
leaq -0x88(%rbp), %rdi
callq 0x8560
jmp 0x4d6b
leaq -0x89(%rbp), %rdi
callq 0x41d0
movq -0x118(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x87c0
movq %rax, -0x128(%rbp)
jmp 0x4d90
movq -0x128(%rbp), %rax
movb (%rax), %al
movb %al, -0x8a(%rbp)
movsbl -0x8a(%rbp), %eax
cmpl $0x22, %eax
je 0x4e1f
movq -0x110(%rbp), %rdi
leaq 0x10432(%rip), %rcx     # 0x151eb
leaq -0x50(%rbp), %rsi
leaq -0x14(%rbp), %rdx
callq 0x8870
jmp 0x4dc8
movl $0x1, -0x90(%rbp)
jmp 0x5000
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x41d0
jmp 0x503a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x89(%rbp), %rdi
callq 0x41d0
jmp 0x5031
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x5025
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x118(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x87c0
movq %rax, -0x130(%rbp)
jmp 0x4e41
movq -0x130(%rbp), %rax
movb (%rax), %al
movb %al, -0x8a(%rbp)
movsbl -0x8a(%rbp), %eax
cmpl $0x22, %eax
je 0x4fd1
movq -0x118(%rbp), %rdi
movslq -0x18(%rbp), %rax
movq %rax, -0x138(%rbp)
callq 0x8830
movq %rax, %rcx
movq -0x138(%rbp), %rax
cmpq %rcx, %rax
jne 0x4fb1
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x42b0
movq -0x140(%rbp), %rdx
leaq 0x101d4(%rip), %rsi     # 0x1507f
leaq -0xd0(%rbp), %rdi
callq 0x8560
jmp 0x4eb9
movq -0x118(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x88e0
jmp 0x4ece
movl -0x18(%rbp), %ecx
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x45d0
jmp 0x4eed
movq -0x110(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x18(%rbp), %rdx
leaq -0xb0(%rbp), %rcx
callq 0x89c0
jmp 0x4f0a
leaq -0xb0(%rbp), %rdi
callq 0x87f0
leaq -0xf8(%rbp), %rdi
callq 0x87f0
leaq -0xd0(%rbp), %rdi
callq 0x87f0
leaq -0xd1(%rbp), %rdi
callq 0x41d0
movl $0x1, -0x90(%rbp)
jmp 0x5000
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x4fa3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x4f97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x4f8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x87f0
leaq -0xf8(%rbp), %rdi
callq 0x87f0
leaq -0xd0(%rbp), %rdi
callq 0x87f0
leaq -0xd1(%rbp), %rdi
callq 0x41d0
jmp 0x5025
movsbl -0x8a(%rbp), %esi
leaq -0x50(%rbp), %rdi
callq 0x8750
jmp 0x4fc3
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x4e28
movq -0x110(%rbp), %rdi
movl -0x18(%rbp), %eax
incl %eax
movl %eax, -0x18(%rbp)
leaq 0x10204(%rip), %rcx     # 0x151eb
leaq -0x50(%rbp), %rsi
leaq -0x18(%rbp), %rdx
callq 0x8870
jmp 0x4ff6
movl $0x1, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x87f0
leaq -0x50(%rbp), %rdi
callq 0x88b0
movq -0x108(%rbp), %rax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
leaq -0x88(%rbp), %rdi
callq 0x87f0
leaq -0x50(%rbp), %rdi
callq 0x88b0
movq -0x60(%rbp), %rdi
callq 0x42a0
nopw %cs:(%rax,%rax)