// File: /workspace/github_cpp_makefile_star2_O2/Falldog[P]dcinja/src/include/inja/inja.hpp
// Function: inja::Lexer::scan()
Token scan() {
    tok_start = pos;

  again:
    if (tok_start >= m_in.size()) {
      return make_token(Token::Kind::Eof);
    }

    switch (state) {
    default:
    case State::Text: {
      // fast-scan to first open character
      size_t open_start = m_in.substr(pos).find_first_of(config.open_chars);
      if (open_start == nonstd::string_view::npos) {
        // didn't find open, return remaining text as text token
        pos = m_in.size();
        return make_token(Token::Kind::Text);
      }
      pos += open_start;

      // try to match one of the opening sequences, and get the close
      nonstd::string_view open_str = m_in.substr(pos);
      bool must_lstrip = false;
      if (inja::string_view::starts_with(open_str, config.expression_open)) {
        if (inja::string_view::starts_with(open_str, config.expression_open_force_lstrip)) {
          state = State::ExpressionStartForceLstrip;
          must_lstrip = true;
        } else {
          state = State::ExpressionStart;
        }
      } else if (inja::string_view::starts_with(open_str, config.statement_open)) {
        if (inja::string_view::starts_with(open_str, config.statement_open_no_lstrip)) {
          state = State::StatementStartNoLstrip;
        } else if (inja::string_view::starts_with(open_str, config.statement_open_force_lstrip )) {
          state = State::StatementStartForceLstrip;
          must_lstrip = true;
        } else {
          state = State::StatementStart;
          must_lstrip = config.lstrip_blocks;
        }
      } else if (inja::string_view::starts_with(open_str, config.comment_open)) {
        state = State::CommentStart;
        must_lstrip = config.lstrip_blocks;
      } else if ((pos == 0 || m_in[pos - 1] == '\n') && inja::string_view::starts_with(open_str, config.line_statement)) {
        state = State::LineStart;
      } else {
        pos += 1; // wasn't actually an opening sequence
        goto again;
      }

      nonstd::string_view text = string_view::slice(m_in, tok_start, pos);
      if (must_lstrip) {
        text = clear_final_line_if_whitespace(text);
      }

      if (text.empty()) {
        goto again; // don't generate empty token
      }
      return Token(Token::Kind::Text, text);
    }
    case State::ExpressionStart: {
      state = State::ExpressionBody;
      pos += config.expression_open.size();
      return make_token(Token::Kind::ExpressionOpen);
    }
    case State::ExpressionStartForceLstrip: {
      state = State::ExpressionBody;
      pos += config.expression_open_force_lstrip.size();
      return make_token(Token::Kind::ExpressionOpen);
    }
    case State::LineStart: {
      state = State::LineBody;
      pos += config.line_statement.size();
      return make_token(Token::Kind::LineStatementOpen);
    }
    case State::StatementStart: {
      state = State::StatementBody;
      pos += config.statement_open.size();
      return make_token(Token::Kind::StatementOpen);
    }
    case State::StatementStartNoLstrip: {
      state = State::StatementBody;
      pos += config.statement_open_no_lstrip.size();
      return make_token(Token::Kind::StatementOpen);
    }
    case State::StatementStartForceLstrip: {
      state = State::StatementBody;
      pos += config.statement_open_force_lstrip.size();
      return make_token(Token::Kind::StatementOpen);
    }
    case State::CommentStart: {
      state = State::CommentBody;
      pos += config.comment_open.size();
      return make_token(Token::Kind::CommentOpen);
    }
    case State::ExpressionBody:
      return scan_body(config.expression_close, Token::Kind::ExpressionClose, config.expression_close_force_rstrip);
    case State::LineBody:
      return scan_body("\n", Token::Kind::LineStatementClose);
    case State::StatementBody:
      return scan_body(config.statement_close, Token::Kind::StatementClose, config.statement_close_force_rstrip, config.trim_blocks);
    case State::CommentBody: {
      // fast-scan to comment close
      size_t end = m_in.substr(pos).find(config.comment_close);
      if (end == nonstd::string_view::npos) {
        pos = m_in.size();
        return make_token(Token::Kind::Eof);
      }
      // return the entire comment in the close token
      state = State::Text;
      pos += end + config.comment_close.size();
      Token tok = make_token(Token::Kind::CommentClose);
      if (config.trim_blocks) {
        skip_whitespaces_and_first_newline();
      }
      return tok;
    }
    }
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x28(%rsi), %rax
movq %rax, 0x20(%rsi)
leaq 0x10(%rsi), %r15
pushq $-0x1
popq %r12
cmpq (%r15), %rax
jae 0x18ea0
movl 0x8(%r14), %eax
decl %eax
cmpl $0xa, %eax
jbe 0x18ca4
movq 0x28(%r14), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x189aa
movq %rax, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq (%r14), %rax
movq 0x180(%rax), %rsi
movq 0x188(%rax), %rcx
leaq 0x10(%rsp), %rdi
xorl %edx, %edx
callq 0x192dc
cmpq $-0x1, %rax
je 0x18e79
addq 0x28(%r14), %rax
movq %rax, 0x28(%r14)
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x189aa
movq %rax, %r13
movq %rdx, %rbp
movq (%r14), %rax
movq 0xc0(%rax), %rcx
movq 0xc8(%rax), %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18977
movq (%r14), %rdx
testb %al, %al
je 0x18b76
movq 0xe0(%rdx), %rcx
movq 0xe8(%rdx), %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18977
testb %al, %al
je 0x18bb0
movl $0x2, 0x8(%r14)
movb $0x1, %bpl
jmp 0x18c60
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18977
movq (%r14), %rdx
testb %al, %al
je 0x18bbf
movq 0x20(%rdx), %rcx
movq 0x28(%rdx), %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18977
testb %al, %al
je 0x18be6
movl $0x7, 0x8(%r14)
jmp 0x18bb8
movl $0x1, 0x8(%r14)
xorl %ebp, %ebp
jmp 0x18c60
movq 0x140(%rdx), %rcx
movq 0x148(%rdx), %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18977
testb %al, %al
je 0x18c0d
movl $0xa, 0x8(%r14)
jmp 0x18c56
movq (%r14), %rax
movq 0x40(%rax), %rcx
movq 0x48(%rax), %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18977
testb %al, %al
je 0x18c4e
movl $0x8, 0x8(%r14)
jmp 0x18b6e
movq 0x28(%r14), %rax
testq %rax, %rax
je 0x18c21
movq 0x18(%r14), %rcx
cmpb $0xa, -0x1(%rcx,%rax)
jne 0x18c9b
movq (%r14), %rax
movq 0xa0(%rax), %rcx
movq 0xa8(%rax), %rdx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18977
testb %al, %al
je 0x18c97
movl $0x4, 0x8(%r14)
jmp 0x18bb8
movl $0x6, 0x8(%r14)
movq (%r14), %rax
movb 0x1a1(%rax), %bpl
movq 0x10(%r14), %rdi
movq 0x18(%r14), %rsi
movq 0x20(%r14), %rdx
movq 0x28(%r14), %rcx
callq 0x18ef7
testb %bpl, %bpl
je 0x18c85
movq %rax, %rdi
movq %rdx, %rsi
callq 0x18f32
testq %rax, %rax
jne 0x18e8b
movq 0x20(%r14), %rax
jmp 0x18ab2
movq 0x28(%r14), %rax
incq %rax
movq %rax, 0x28(%r14)
jmp 0x18c8e
leaq 0x2c545(%rip), %rcx     # 0x451f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x3, 0x8(%r14)
movq (%r14), %rax
movq 0xc8(%rax), %rax
jmp 0x18d86
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movups %xmm0, (%rsp)
leaq 0x2dc3c(%rip), %rcx     # 0x4691a
pushq $0x1
popq %rdx
pushq $0x4
jmp 0x18d36
movl $0xb, 0x8(%r14)
movq (%r14), %rax
movq 0x148(%rax), %rax
addq %rax, 0x28(%r14)
pushq $0x7
jmp 0x18ea2
movq (%r14), %rax
movq 0x100(%rax), %rcx
movq 0x108(%rax), %rdx
movq 0x120(%rax), %rsi
movq 0x128(%rax), %rax
movq %rax, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
pushq $0x2
popq %r8
movq %rbx, %rdi
movq %r14, %rsi
xorl %r9d, %r9d
jmp 0x18e72
movl $0x5, 0x8(%r14)
movq (%r14), %rax
movq 0xa8(%rax), %rax
addq %rax, 0x28(%r14)
pushq $0x3
jmp 0x18ea2
movl $0x9, 0x8(%r14)
movq (%r14), %rax
movq 0x48(%rax), %rax
jmp 0x18db1
movl $0x3, 0x8(%r14)
movq (%r14), %rax
movq 0xe8(%rax), %rax
addq %rax, 0x28(%r14)
pushq $0x1
jmp 0x18ea2
movl $0x9, 0x8(%r14)
movq (%r14), %rax
movq 0x8(%rax), %rax
jmp 0x18db1
movl $0x9, 0x8(%r14)
movq (%r14), %rax
movq 0x28(%rax), %rax
addq %rax, 0x28(%r14)
pushq $0x5
jmp 0x18ea2
movq 0x28(%r14), %rsi
pushq $-0x1
popq %rdx
movq %r15, %rdi
callq 0x189aa
leaq 0x10(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
movq (%r14), %rax
movq 0x160(%rax), %rsi
movq 0x168(%rax), %rcx
xorl %edx, %edx
callq 0x194b6
cmpq $-0x1, %rax
je 0x18e98
andl $0x0, 0x8(%r14)
movq (%r14), %rcx
addq 0x168(%rcx), %rax
addq %rax, 0x28(%r14)
pushq $0x8
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x18ec0
movq (%r14), %rax
cmpb $0x1, 0x1a0(%rax)
jne 0x18eae
movq %r14, %rdi
callq 0x19276
jmp 0x18eae
movq (%r14), %rax
movq 0x60(%rax), %rcx
movq 0x68(%rax), %rdx
movq 0x80(%rax), %rsi
movq 0x88(%rax), %rdi
movq %rdi, 0x20(%rsp)
movq %rsi, 0x28(%rsp)
movzbl 0x1a0(%rax), %r9d
movups 0x20(%rsp), %xmm0
movups %xmm0, (%rsp)
pushq $0x6
popq %r8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x18f64
jmp 0x18eae
movq 0x10(%r14), %rax
movq %rax, 0x28(%r14)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
jmp 0x18ea9
andl $0x0, (%rbx)
movq %rax, 0x8(%rbx)
movq %rdx, 0x10(%rbx)
jmp 0x18eae
movq 0x10(%r14), %rax
movq %rax, 0x28(%r14)
pushq $0x22
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x18ec0
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq