// File: /workspace/github_cpp_makefile_star2_O2/Falldog[P]dcinja/src/include/inja/inja.hpp
// Function: inja::Lexer::scan_body(std::basic_string_view<char, std::char_traits<char>>, inja::Token::Kind, std::basic_string_view<char, std::char_traits<char>>, bool)
Token scan_body(nonstd::string_view close, Token::Kind closeKind, nonstd::string_view close_trim = nonstd::string_view(), bool trim = false) {
  again:
    // skip whitespace (except for \n as it might be a close)
    if (tok_start >= m_in.size()) {
      return make_token(Token::Kind::Eof);
    }
    char ch = m_in[tok_start];
    if (ch == ' ' || ch == '\t' || ch == '\r') {
      tok_start += 1;
      goto again;
    }

    // check for close
    if (!close_trim.empty() && inja::string_view::starts_with(m_in.substr(tok_start), close_trim)) {
      state = State::Text;
      pos = tok_start + close_trim.size();
      Token tok = make_token(closeKind);
      skip_whitespaces_and_newlines();
      return tok;
    }

    if (inja::string_view::starts_with(m_in.substr(tok_start), close)) {
      state = State::Text;
      pos = tok_start + close.size();
      Token tok = make_token(closeKind);
      if (trim) {
        skip_whitespaces_and_first_newline();
      }
      return tok;
    }

    // skip \n
    if (ch == '\n') {
      tok_start += 1;
      goto again;
    }

    pos = tok_start + 1;
    if (std::isalpha(ch)) {
      minus_state = MinusState::Operator;
      return scan_id();
    }

    MinusState current_minus_state = minus_state;
    if (minus_state == MinusState::Operator) {
      minus_state = MinusState::Number;
    }

    switch (ch) {
    case '+':
      return make_token(Token::Kind::Plus);
    case '-':
      if (current_minus_state == MinusState::Operator) {
        return make_token(Token::Kind::Minus);
      }
      return scan_number();
    case '*':
      return make_token(Token::Kind::Times);
    case '/':
      return make_token(Token::Kind::Slash);
    case '^':
      return make_token(Token::Kind::Power);
    case '%':
      return make_token(Token::Kind::Percent);
    case '.':
      return make_token(Token::Kind::Dot);
    case ',':
      return make_token(Token::Kind::Comma);
    case ':':
      return make_token(Token::Kind::Colon);
    case '(':
      return make_token(Token::Kind::LeftParen);
    case ')':
      minus_state = MinusState::Operator;
      return make_token(Token::Kind::RightParen);
    case '[':
      return make_token(Token::Kind::LeftBracket);
    case ']':
      minus_state = MinusState::Operator;
      return make_token(Token::Kind::RightBracket);
    case '{':
      return make_token(Token::Kind::LeftBrace);
    case '}':
      minus_state = MinusState::Operator;
      return make_token(Token::Kind::RightBrace);
    case '>':
      if (pos < m_in.size() && m_in[pos] == '=') {
        pos += 1;
        return make_token(Token::Kind::GreaterEqual);
      }
      return make_token(Token::Kind::GreaterThan);
    case '<':
      if (pos < m_in.size() && m_in[pos] == '=') {
        pos += 1;
        return make_token(Token::Kind::LessEqual);
      }
      return make_token(Token::Kind::LessThan);
    case '=':
      if (pos < m_in.size() && m_in[pos] == '=') {
        pos += 1;
        return make_token(Token::Kind::Equal);
      }
      return make_token(Token::Kind::Unknown);
    case '!':
      if (pos < m_in.size() && m_in[pos] == '=') {
        pos += 1;
        return make_token(Token::Kind::NotEqual);
      }
      return make_token(Token::Kind::Unknown);
    case '\"':
      return scan_string();
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      minus_state = MinusState::Operator;
      return scan_number();
    case '_':
      minus_state = MinusState::Operator;
      return scan_id();
    default:
      return make_token(Token::Kind::Unknown);
    }
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0x14(%rsp)
movl %r8d, 0x10(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
leaq 0x60(%rsp), %r13
leaq 0x10(%rsi), %r15
movq 0x20(%rsi), %rsi
movabsq $0x100002200, %r12      # imm = 0x100002200
cmpq (%r15), %rsi
jae 0x19032
movq 0x18(%r14), %rax
movzbl (%rax,%rsi), %ebx
cmpq $0x20, %rbx
ja 0x18fc2
btq %rbx, %r12
jb 0x19026
movq (%r13), %rbp
testq %rbp, %rbp
je 0x18ff4
movq %r15, %rdi
pushq $-0x1
popq %rdx
callq 0x189aa
movq 0x8(%r13), %rcx
movq %rax, %rdi
movq %rdx, %rsi
movq %rbp, %rdx
callq 0x18977
movq 0x20(%r14), %rsi
testb %al, %al
jne 0x190be
movq %r15, %rdi
pushq $-0x1
popq %rdx
callq 0x189aa
movq %rax, %rdi
movq %rdx, %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
callq 0x18977
testb %al, %al
jne 0x19057
cmpb $0xa, %bl
jne 0x1908e
movq 0x20(%r14), %rsi
leaq 0x60(%rsp), %r13
incq %rsi
movq %rsi, 0x20(%r14)
jmp 0x18fa5
pushq $0x22
popq %rdx
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x18ec0
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andl $0x0, 0x8(%r14)
movq 0x18(%rsp), %rax
addq 0x20(%r14), %rax
movq %rax, 0x28(%r14)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl 0x10(%rsp), %edx
callq 0x18ec0
cmpb $0x0, 0x14(%rsp)
je 0x19045
movq %r14, %rdi
callq 0x19276
jmp 0x19045
movsbl %bl, %edi
movq 0x20(%r14), %r12
leaq 0x1(%r12), %r13
movq %r13, 0x28(%r14)
callq 0x9700
testl %eax, %eax
je 0x190f0
andl $0x0, 0xc(%r14)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19386
jmp 0x19045
andl $0x0, 0x8(%r14)
leaq 0x60(%rsp), %rax
addq (%rax), %rsi
movq %rsi, 0x28(%r14)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl 0x10(%rsp), %edx
callq 0x18ec0
movq %r14, %rdi
callq 0x1934a
jmp 0x19045
movl 0xc(%r14), %eax
testl %eax, %eax
jne 0x19100
movl $0x1, 0xc(%r14)
movzbl %bl, %ecx
leal -0x21(%rcx), %edx
cmpl $0x3e, %edx
ja 0x19135
leaq 0x2c10a(%rip), %rcx     # 0x4521c
movslq (%rcx,%rdx,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
andl $0x0, 0xc(%r14)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19402
jmp 0x19045
cmpl $0x7b, %ecx
je 0x19260
cmpl $0x7d, %ecx
jne 0x191ff
andl $0x0, 0xc(%r14)
pushq $0x1a
jmp 0x19034
cmpq (%r15), %r13
jae 0x19267
movq 0x18(%r14), %rax
cmpb $0x3d, (%rax,%r13)
jne 0x19267
addq $0x2, %r12
movq %r12, 0x28(%r14)
pushq $0x20
jmp 0x19034
pushq $0x14
jmp 0x19034
pushq $0xf
jmp 0x19034
pushq $0x10
jmp 0x19034
cmpq (%r15), %r13
jae 0x191ff
movq 0x18(%r14), %rax
cmpb $0x3d, (%rax,%r13)
jne 0x191ff
addq $0x2, %r12
movq %r12, 0x28(%r14)
pushq $0x1b
jmp 0x19034
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19460
jmp 0x19045
testl %eax, %eax
jne 0x19120
pushq $0xd
jmp 0x19034
pushq $0x12
jmp 0x19034
pushq $0x11
jmp 0x19034
cmpq (%r15), %r13
jae 0x191ff
movq 0x18(%r14), %rax
cmpb $0x3d, (%rax,%r13)
jne 0x191ff
addq $0x2, %r12
movq %r12, 0x28(%r14)
pushq $0x1c
jmp 0x19034
pushq $0x21
jmp 0x19034
andl $0x0, 0xc(%r14)
pushq $0x16
jmp 0x19034
pushq $0x15
jmp 0x19034
pushq $0xe
jmp 0x19034
pushq $0xc
jmp 0x19034
pushq $0x17
jmp 0x19034
pushq $0x13
jmp 0x19034
cmpq (%r15), %r13
jae 0x1926e
movq 0x18(%r14), %rax
cmpb $0x3d, (%rax,%r13)
jne 0x1926e
addq $0x2, %r12
movq %r12, 0x28(%r14)
pushq $0x1e
jmp 0x19034
andl $0x0, 0xc(%r14)
pushq $0x18
jmp 0x19034
pushq $0x19
jmp 0x19034
pushq $0x1f
jmp 0x19034
pushq $0x1d
jmp 0x19034
nop