// File: /workspace/github_cpp_makefile_star2_O3/AgathokakologicalBit[P]wit/src/parsing/lexing.cpp
// Function: akbit::system::parsing::get_next_token(akbit::system::parsing::LexerState&)
parsing::Token get_next_token(parsing::LexerState &state)
  {
    while (std::isspace(state.peek()))
      state.move();

    if (state.is_eof())
    {
      return parsing::Token{
        state.index, state.line, state.column,
        "##EOF##",
        TokenType::t_eof, TokenSubType::t_eof
      };
    }

    auto sub_type = get_character_type(state.peek());
    if (sub_type != TokenSubType::t_unknown)
    {
      state.move();

      // skipping comments
      if (sub_type == TokenSubType::t_slash && state.peek() == '/')
      {
        do state.move();
        while (state.peek() != '\n');

        // TODO: remove the recursion
        return get_next_token(state);
      }

      return parsing::Token{
        state.index - 1, state.line, state.column - 1,
        state.source.substr(state.index - 1, 1),
        TokenType::t_operator,
        sub_type
      };
    }

    if (state.peek() == '"')
    {
      std::uint32_t length = 1;
      do
      {
        state.move(), ++length;

        if (state.peek() == '\\')
          state.move(), ++length;
        
        if (state.peek() == '\0')
        {
          state.error.code = error_t::t_unexpected_eof;
          state.error.message = "String was not closed";
          break;
        }
      } while (state.peek() != '"');
      state.move();

      return parsing::Token{
        state.index - length, state.line, state.column - length,

        state.source.substr(state.index - length, length),

        TokenType::t_string,
        TokenSubType::t_string
      };
    }

    if (state.peek() == '\'')
    {
      state.move();
      std::uint32_t length = 1;

      if (std::isspace(state.peek()) || std::iscntrl(state.peek()))
      {
        state.error.code = error_t::t_misleading_character;
        state.error.message =
          "Character definition is misleading\n"
          "Whitespace symbols should be written using escape sequences:\n"
          "  \\s - space\n"
          "  \\t - tabulation\n"
          "  \\n - new line\n"
          "  \\r - carriage return";
      }

      if (state.peek() == '\\')
      {
        state.move(), ++length;
        switch(state.peek())
        {
          case 'r': case 'n': case 't': case 's': break;
          default:
          state.error.code = error_t::t_special_character_does_not_exist;
          state.error.message = std::string("Special character identifier '")
            + state.peek() + "' does not exists";
        }
      }

      state.move();

      return parsing::Token{
        state.index - length, state.line, state.column - length,

        state.source.substr(state.index - length, length),

        TokenType::t_character, TokenSubType::t_character,
      };
    }

    if ('0' <= state.peek() && state.peek() <= '9')
    {
      std::uint32_t length = 0;
      bool is_decimal = false;
      do state.move(), ++length;
      while (false
             || std::isdigit(state.peek())
             || (state.peek() == '.' && !is_decimal && (is_decimal = true)));

      return parsing::Token{
        state.index - length, state.line, state.column - length,

        state.source.substr(state.index - length, length),

        TokenType::t_number,
        (is_decimal
         ? TokenSubType::t_decimal
         : TokenSubType::t_integer)
      };
    }

    if (false
        || std::isalpha(state.peek())
        || state.peek() == '_' || state.peek() == '$')
    {
      std::uint32_t length = 0;
      do state.move(), ++length;
      while (false
             || std::isalnum(state.peek())
             || state.peek() == '_' || state.peek() == '$');

      return parsing::Token{
        state.index - length, state.line, state.column - length,
        state.source.substr(state.index - length, length),

        TokenType::t_identifier, TokenSubType::t_identifier
      };
    }

    auto ret = parsing::Token{
      state.index, state.line, state.column,
      state.source.substr(state.index, 1),

      TokenType::t_unknown, TokenSubType::t_unknown
    };

    state.move();
    return ret;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
movq 0x10(%rsi), %r15
movl (%rsi), %r12d
movq (%r15), %rax
movb (%rax,%r12), %r13b
movsbl %r13b, %ebp
movl %ebp, %edi
callq 0x3060
testl %eax, %eax
je 0x7d90
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %r15
movl (%r14), %r12d
movq (%r15), %rax
movb (%rax,%r12), %r13b
movsbl %r13b, %ebp
movl %ebp, %edi
callq 0x3060
movq %r12, %rbx
testl %eax, %eax
jne 0x7d66
jmp 0x7d93
movl %r12d, %ebx
cmpq %rbx, 0x8(%r15)
jbe 0x7e2a
movsbl %r13b, %edi
callq 0x7c4c
testl %eax, %eax
je 0x7e69
movq %r14, %rdi
movl %eax, %ebx
callq 0x7c24
movl (%r14), %edx
movq 0x10(%r14), %rsi
cmpl $0x15, %ebx
jne 0x7dee
movq (%rsi), %rax
cmpb $0x2f, (%rax,%rdx)
jne 0x7dee
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %r15
movl (%r14), %r12d
movq (%r15), %rax
cmpb $0xa, (%rax,%r12)
jne 0x7dcd
movb $0xa, %r13b
jmp 0x7d57
decl %edx
movq 0x8(%rsp), %r13
movl %edx, (%r13)
movl 0x4(%r14), %eax
movl %eax, 0x4(%r13)
movl 0x8(%r14), %eax
decl %eax
movl %eax, 0x8(%r13)
leaq 0x10(%r13), %rdi
movl $0x1, %ecx
callq 0x3220
movl $0x6, 0x30(%r13)
movl %ebx, 0x34(%r13)
jmp 0x826a
movq 0x8(%rsp), %r13
movl %r12d, (%r13)
movq 0x4(%r14), %rax
movq %rax, 0x4(%r13)
leaq 0x10(%r13), %rdi
leaq 0x20(%r13), %rax
movq %rax, 0x10(%r13)
leaq 0xd5b0(%rip), %rsi      # 0x153fe
leaq 0xd5b0(%rip), %rdx      # 0x15405
callq 0x6bd0
movabsq $0x2200000007, %rax     # imm = 0x2200000007
jmp 0x8266
cmpb $0x27, %r13b
je 0x7f2f
movzbl %r13b, %ecx
cmpl $0x22, %ecx
jne 0x805d
movl $0x1, %ebx
movq 0x8(%rsp), %r13
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movb (%rax,%rcx), %al
cmpb $0x5c, %al
jne 0x7ebd
movq %r14, %rdi
callq 0x7c24
addl $0x2, %ebx
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movb (%rax,%rcx), %al
jmp 0x7ebf
incl %ebx
cmpb $0x22, %al
je 0x7eee
movzbl %al, %eax
testl %eax, %eax
jne 0x7e8a
movl $0x3f2, 0x18(%r14)      # imm = 0x3F2
leaq 0x20(%r14), %rdi
movq 0x28(%r14), %rdx
leaq 0xd797(%rip), %rcx      # 0x15678
movl $0x15, %r8d
xorl %esi, %esi
callq 0x32d0
movq %r14, %rdi
callq 0x7c24
movl (%r14), %edx
subl %ebx, %edx
movl %edx, (%r13)
movl 0x4(%r14), %eax
movl %eax, 0x4(%r13)
movl 0x8(%r14), %eax
subl %ebx, %eax
movl %eax, 0x8(%r13)
leaq 0x10(%r13), %rdi
movq 0x10(%r14), %rsi
movl %ebx, %ecx
callq 0x3220
movabsq $0x600000004, %rax      # imm = 0x600000004
jmp 0x8266
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movb (%rax,%rcx), %r15b
movsbl %r15b, %ebp
movl %ebp, %edi
callq 0x3060
testl %eax, %eax
jne 0x7f5f
movl %ebp, %edi
callq 0x32a0
testl %eax, %eax
je 0x7f91
movl $0x407, 0x18(%r14)      # imm = 0x407
leaq 0x20(%r14), %rdi
movq 0x28(%r14), %rdx
leaq 0xd718(%rip), %rcx      # 0x1568e
movl $0xa5, %r8d
xorl %esi, %esi
callq 0x32d0
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movb (%rax,%rcx), %r15b
movl $0x1, %ebx
cmpb $0x5c, %r15b
movq 0x8(%rsp), %r13
jne 0x822a
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movb (%rax,%rcx), %al
addb $-0x6e, %al
cmpb $0x7, %al
jae 0x7fd6
movl $0x2, %ebx
movzbl %al, %eax
movl $0x71, %ecx
btl %eax, %ecx
jb 0x822a
movl $0x406, 0x18(%r14)      # imm = 0x406
leaq 0x28(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xd745(%rip), %rsi      # 0x15734
leaq 0xd75c(%rip), %rdx      # 0x15752
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x6bd0
movq 0x10(%r14), %rax
movl (%r14), %ecx
movq (%rax), %rax
movsbl (%rax,%rcx), %edx
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x83e2
leaq 0xd72e(%rip), %rsi      # 0x15753
leaq 0x38(%rsp), %rdi
callq 0x33a0
leaq 0x68(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x81b0
movq %rdx, 0x58(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x68(%rsp)
jmp 0x81b6
leal -0x30(%r13), %eax
cmpb $0x9, %al
ja 0x80df
xorl %ebp, %ebp
xorl %eax, %eax
movq 0x8(%rsp), %r13
movl %eax, %ebx
movq %r14, %rdi
callq 0x7c24
incl %ebp
movq 0x10(%r14), %rsi
movl (%r14), %edx
movq (%rsi), %rax
movsbl (%rax,%rdx), %eax
leal -0x30(%rax), %ecx
cmpl $0xa, %ecx
jb 0x8070
cmpb $0x2e, %al
sete %cl
movl %ebx, %edi
xorb $0x1, %dil
movb $0x1, %al
testb %dil, %cl
jne 0x806e
subl %ebp, %edx
movl %edx, (%r13)
movl 0x4(%r14), %eax
movl %eax, 0x4(%r13)
movl 0x8(%r14), %eax
subl %ebp, %eax
movl %eax, 0x8(%r13)
leaq 0x10(%r13), %rdi
movl %ebp, %ecx
callq 0x3220
movl $0x3, 0x30(%r13)
movzbl %bl, %eax
andl $0x1, %eax
orl $0x4, %eax
movl %eax, 0x34(%r13)
jmp 0x826a
movl %ecx, 0x14(%rsp)
movl %ebp, %edi
callq 0x32f0
testl %eax, %eax
je 0x8165
movl $0x1, %ebx
movq 0x8(%rsp), %r13
movq %r14, %rdi
callq 0x7c24
movq 0x10(%r14), %r15
movl (%r14), %r12d
movq (%r15), %rax
movsbl (%rax,%r12), %ebp
movl %ebp, %edi
callq 0x3200
testl %eax, %eax
jne 0x8128
movzbl %bpl, %eax
cmpl $0x24, %eax
je 0x8128
cmpl $0x5f, %eax
jne 0x812c
incl %ebx
jmp 0x80f8
subl %ebx, %r12d
movl %r12d, (%r13)
movl 0x4(%r14), %eax
movl %eax, 0x4(%r13)
movl 0x8(%r14), %eax
subl %ebx, %eax
movl %eax, 0x8(%r13)
leaq 0x10(%r13), %rdi
movl %ebx, %ecx
movq %r15, %rsi
movq %r12, %rdx
callq 0x3220
movabsq $0x300000002, %rax      # imm = 0x300000002
jmp 0x8266
cmpb $0x5f, %r13b
je 0x80ee
cmpl $0x24, 0x14(%rsp)
je 0x80ee
movq 0x8(%rsp), %r13
movl %r12d, (%r13)
movq 0x4(%r14), %rax
movq %rax, 0x4(%r13)
leaq 0x10(%r13), %rdi
movl $0x1, %ecx
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3220
movq $0x0, 0x30(%r13)
movq %r14, %rdi
callq 0x7c24
jmp 0x826a
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
leaq 0x58(%rsp), %r15
movq %rdx, 0x8(%r15)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x3270
movq (%r15), %rdi
cmpq %rbx, %rdi
je 0x81f3
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x31f0
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x820e
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x31f0
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x8225
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31f0
movl $0x2, %ebx
movq %r14, %rdi
callq 0x7c24
movl (%r14), %edx
subl %ebx, %edx
movl %edx, (%r13)
movl 0x4(%r14), %eax
movl %eax, 0x4(%r13)
movl 0x8(%r14), %eax
subl %ebx, %eax
movl %eax, 0x8(%r13)
leaq 0x10(%r13), %rdi
movq 0x10(%r14), %rsi
movl %ebx, %ecx
callq 0x3220
movabsq $0x700000005, %rax      # imm = 0x700000005
movq %rax, 0x30(%r13)
movq %r13, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x829f
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x31f0
jmp 0x829f
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x82b6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31f0
movq %rbx, %rdi
callq 0x3350