// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rsi, %r12
movq %rdi, -0x38(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
andq $0x0, -0x60(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x58ae
xorl %r13d, %r13d
leaq -0x160(%rbp), %r14
movslq %r13d, %rax
cmpq %rax, 0x8(%r12)
jbe 0x3e50
movq %r14, %rdi
movq %r12, %rsi
callq 0x5890
movq %r14, %rdi
movl %r13d, %esi
callq 0x3664
movl %eax, %ebx
movq %r14, %rdi
callq 0x585c
cmpl %ebx, %r13d
jne 0x3e25
xorl %r14d, %r14d
movq $0x0, -0x58(%rbp)
movl %r13d, %ebx
cmpq $0x30, %r14
je 0x3e2c
leaq 0x9f43(%rip), %rax      # 0xdc98
movq (%r14,%rax), %r15
leaq -0x140(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x5890
leaq -0xe0(%rbp), %rdi
movq %r13, %rsi
movl %ebx, %edx
callq *%r15
movq %r12, %r15
movq %r13, %rdi
callq 0x585c
movl -0xc0(%rbp), %r12d
cmpl %r12d, %ebx
je 0x3dc6
cmpq $0x0, -0xd8(%rbp)
je 0x3dee
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %r13
movq %r13, %rsi
leaq -0xe0(%rbp), %rdx
callq 0x6044
movq %r13, %rdi
callq 0x58ce
movl $0x0, -0x2c(%rbp)
movl %ebx, %r13d
leaq -0xe0(%rbp), %rdi
callq 0x5936
addq $0x8, %r14
cmpl %r12d, %ebx
movq %r15, %r12
je 0x3d41
jmp 0x3e31
leaq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x607e
leaq -0x70(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x58fa
movl -0xc0(%rbp), %r13d
decl %r13d
movb $0x1, %al
movq %rax, -0x58(%rbp)
movb $0x1, %al
movl %eax, -0x2c(%rbp)
jmp 0x3dd0
decl %ebx
movl %ebx, %r13d
jmp 0x3e48
movl %ebx, %r13d
jmp 0x3e3b
cmpb $0x0, -0x2c(%rbp)
je 0x3ef9
testb $0x1, -0x58(%rbp)
je 0x3e69
leaq -0x160(%rbp), %r14
incl %r13d
jmp 0x3cff
leaq 0x53b0(%rip), %rdx      # 0x9207
leaq -0x70(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x616a
jmp 0x3ef9
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
leaq 0x5252(%rip), %rsi      # 0x90ce
leaq -0x120(%rbp), %rdi
leaq -0x2d(%rbp), %rdx
callq 0x5820
leaq -0x100(%rbp), %rdi
movq %r12, %rsi
callq 0x5890
leaq -0xe0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x100(%rbp), %rdx
movl %r13d, %ecx
callq 0x3418
leaq -0x50(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
movq -0x38(%rbp), %rdi
callq 0x6044
leaq -0xe0(%rbp), %rdi
callq 0x585c
leaq -0x100(%rbp), %rdi
callq 0x585c
leaq -0x120(%rbp), %rdi
callq 0x585c
leaq -0x50(%rbp), %rdi
callq 0x58ce
leaq -0x78(%rbp), %rdi
callq 0x61bc
leaq -0x70(%rbp), %rdi
callq 0x58ce
movq -0x38(%rbp), %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x585c
jmp 0x3f35
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x585c
jmp 0x3f46
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x585c
jmp 0x3f57
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x58ce
jmp 0x3f9e
jmp 0x3f9b
movq %rax, %rbx
jmp 0x3fa7
jmp 0x3f9b
movq %rax, %rbx
jmp 0x3f7c
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x58ce
leaq -0xe0(%rbp), %rdi
callq 0x5936
jmp 0x3f9e
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x585c
jmp 0x3f9e
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x61bc
leaq -0x70(%rbp), %rdi
callq 0x58ce
movq %rbx, %rdi
callq 0x3260