// File: eatonphil[P]cpp-json/json.cpp
// Function: json::lex(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::tuple<std::vector<JSONToken>, std::string> lex(std::string raw_json) {
  std::vector<JSONToken> tokens;
  auto original_copy = std::make_shared<std::string>(raw_json);
  auto generic_lexers = {lex_syntax, lex_string, lex_number,
                         lex_null,   lex_true,   lex_false};
  for (int i = 0; i < raw_json.length(); i++) {
    if (auto new_index = lex_whitespace(raw_json, i); i != new_index) {
      i = new_index - 1;
      continue;
    }

    auto found = false;
    for (auto lexer : generic_lexers) {
      if (auto [token, new_index, error] = lexer(raw_json, i); i != new_index) {
        if (error.length()) {
          return {{}, error};
        }

        token.full_source = original_copy;
        tokens.push_back(token);
        i = new_index - 1;
        found = true;
        break;
      }
    }

    if (found) {
      continue;
    }

    return {{}, format_error("Unable to lex", raw_json, i)};
  }

  return {tokens, ""};
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rsi, -0x220(%rbp)
movq %rdi, -0x230(%rbp)
movq %rdi, %rax
movq %rax, -0x228(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x8a30
movq -0x220(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8a50
jmp 0x56f6
leaq -0x88(%rbp), %rdi
leaq 0x1a554(%rip), %rsi     # 0x1fc58
movl $0x30, %edx
callq 0x4150
leaq -0x88(%rbp), %rax
movq %rax, -0x58(%rbp)
movq $0x6, -0x50(%rbp)
movl $0x0, -0x8c(%rbp)
movq -0x220(%rbp), %rdi
movslq -0x8c(%rbp), %rax
movq %rax, -0x238(%rbp)
callq 0x8830
movq %rax, %rcx
movq -0x238(%rbp), %rax
cmpq %rcx, %rax
jae 0x5be7
movq -0x220(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x88e0
jmp 0x576d
movl -0x8c(%rbp), %esi
leaq -0xb0(%rbp), %rdi
callq 0x4a80
movl %eax, -0x23c(%rbp)
jmp 0x5787
leaq -0xb0(%rbp), %rdi
callq 0x87f0
movl -0x23c(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x90(%rbp), %eax
je 0x5800
movl -0x90(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x5bd3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5c35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5c2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x87f0
jmp 0x5c2c
movb $0x0, -0xb1(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x8ac0
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x8ae0
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rax
cmpq -0xd0(%rbp), %rax
je 0x5a63
movq -0x220(%rbp), %rsi
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x248(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x88e0
jmp 0x5880
movq -0x248(%rbp), %rax
movl -0x8c(%rbp), %edx
leaq -0x138(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq *%rax
jmp 0x589f
leaq -0x158(%rbp), %rdi
callq 0x87f0
leaq -0x138(%rbp), %rdi
callq 0x8b20
movq %rax, -0x160(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x8b40
movq %rax, -0x168(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x8b60
movq %rax, -0x170(%rbp)
movl -0x8c(%rbp), %eax
movq -0x168(%rbp), %rcx
cmpl (%rcx), %eax
je 0x5a01
movq -0x170(%rbp), %rdi
callq 0x8830
cmpq $0x0, %rax
je 0x59a8
xorps %xmm0, %xmm0
movaps %xmm0, -0x190(%rbp)
movq $0x0, -0x180(%rbp)
leaq -0x190(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x8a30
movq -0x230(%rbp), %rdi
movq -0x250(%rbp), %rsi
movq -0x170(%rbp), %rdx
callq 0x8b80
jmp 0x5953
leaq -0x190(%rbp), %rdi
callq 0x8bb0
movl $0x1, -0x194(%rbp)
jmp 0x5a0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x87f0
jmp 0x5c2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x8bb0
jmp 0x5a52
movq -0x160(%rbp), %rdi
addq $0x28, %rdi
leaq -0x38(%rbp), %rsi
callq 0x8c10
movq -0x160(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x8c40
jmp 0x59ce
movq -0x168(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x8c(%rbp)
movb $0x1, -0xb1(%rbp)
movl $0x5, -0x194(%rbp)
jmp 0x5a0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5a52
movl $0x0, -0x194(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x8cb0
movl -0x194(%rbp), %eax
movl %eax, -0x254(%rbp)
testl %eax, %eax
je 0x5a39
jmp 0x5a29
movl -0x254(%rbp), %eax
subl $0x5, %eax
je 0x5a63
jmp 0x5c0a
jmp 0x5a3b
movq -0xc8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xc8(%rbp)
jmp 0x5838
leaq -0x138(%rbp), %rdi
callq 0x8cb0
jmp 0x5c2c
testb $0x1, -0xb1(%rbp)
je 0x5a71
jmp 0x5bd3
xorps %xmm0, %xmm0
movaps %xmm0, -0x1b0(%rbp)
movq $0x0, -0x1a0(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x8a30
leaq -0x1f1(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x42b0
movq -0x260(%rbp), %rdx
leaq 0xf5ff(%rip), %rsi      # 0x150b2
leaq -0x1f0(%rbp), %rdi
callq 0x8560
jmp 0x5ac1
movq -0x220(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x88e0
jmp 0x5ad6
movl -0x8c(%rbp), %ecx
leaq -0x1d0(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
leaq -0x218(%rbp), %rdx
callq 0x45d0
jmp 0x5af8
movq -0x230(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
leaq -0x1d0(%rbp), %rdx
callq 0x8b80
jmp 0x5b14
leaq -0x1d0(%rbp), %rdi
callq 0x87f0
leaq -0x218(%rbp), %rdi
callq 0x87f0
leaq -0x1f0(%rbp), %rdi
callq 0x87f0
leaq -0x1f1(%rbp), %rdi
callq 0x41d0
leaq -0x1b0(%rbp), %rdi
callq 0x8bb0
movl $0x1, -0x194(%rbp)
jmp 0x5c0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5bb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5bad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5ba1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x87f0
leaq -0x218(%rbp), %rdi
callq 0x87f0
leaq -0x1f0(%rbp), %rdi
callq 0x87f0
leaq -0x1f1(%rbp), %rdi
callq 0x41d0
leaq -0x1b0(%rbp), %rdi
callq 0x8bb0
jmp 0x5c2c
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x572b
movq -0x230(%rbp), %rdi
leaq 0xf5f6(%rip), %rdx      # 0x151eb
leaq -0x28(%rbp), %rsi
callq 0x8cd0
jmp 0x5c00
movl $0x1, -0x194(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x8d00
leaq -0x28(%rbp), %rdi
callq 0x8bb0
movq -0x228(%rbp), %rax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x8d00
leaq -0x28(%rbp), %rdi
callq 0x8bb0
movq -0x40(%rbp), %rdi
callq 0x42a0
nopw (%rax,%rax)