// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x88(%rbp)
movb %r9b, %al
movq %rdi, -0x80(%rbp)
leaq 0x10(%rbp), %rdi
movq %rdi, -0x78(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x8(%rbp)
movq %rsi, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
andb $0x1, %al
movb %al, -0x1d(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movq 0x20(%rdi), %rax
movq %rax, -0x90(%rbp)
addq $0x10, %rdi
callq 0x332e0
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jb 0x3772f
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x22, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rax
movq %rax, %rdi
addq $0x10, %rdi
movq 0x20(%rax), %rsi
callq 0x374e0
movb (%rax), %al
movb %al, -0x1e(%rbp)
movsbl -0x1e(%rbp), %eax
cmpl $0x20, %eax
je 0x37763
movsbl -0x1e(%rbp), %eax
cmpl $0x9, %eax
je 0x37763
movsbl -0x1e(%rbp), %eax
cmpl $0xd, %eax
jne 0x37778
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
jmp 0x376ee
movq -0x78(%rbp), %rdi
callq 0x37660
testb $0x1, %al
jne 0x3782e
movq -0x70(%rbp), %rax
movq %rax, %rdi
addq $0x10, %rdi
movq 0x20(%rax), %rsi
movq $-0x1, %rdx
callq 0x36790
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x30(%rbp)
movq %rdx, -0x28(%rbp)
movq (%rax), %rcx
movq %rcx, -0x40(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x36700
testb $0x1, %al
jne 0x377dd
jmp 0x3782e
movq -0x70(%rbp), %rax
movq -0x78(%rbp), %rdi
movl $0x0, 0x8(%rax)
movq 0x20(%rax), %rax
movq %rax, -0x98(%rbp)
callq 0x332e0
movq -0x88(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq %rax, %rcx
movq -0x98(%rbp), %rax
addq %rcx, %rax
movq %rax, 0x28(%rsi)
movl -0x1c(%rbp), %edx
callq 0x37430
movq -0x70(%rbp), %rdi
callq 0x38130
jmp 0x37d8b
movq -0x70(%rbp), %rax
movq %rax, %rdi
addq $0x10, %rdi
movq 0x20(%rax), %rsi
movq $-0x1, %rdx
callq 0x36790
movq %rax, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x36700
testb $0x1, %al
jne 0x3787c
jmp 0x378d3
movq -0x70(%rbp), %rax
movl $0x0, 0x8(%rax)
movq 0x20(%rax), %rax
movq %rax, -0xa0(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x332e0
movq -0x88(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq %rax, %rcx
movq -0xa0(%rbp), %rax
addq %rcx, %rax
movq %rax, 0x28(%rsi)
movl -0x1c(%rbp), %edx
callq 0x37430
testb $0x1, -0x1d(%rbp)
je 0x378ce
movq -0x70(%rbp), %rdi
callq 0x37de0
jmp 0x37d8b
movsbl -0x1e(%rbp), %eax
cmpl $0xa, %eax
jne 0x378f1
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
jmp 0x376ee
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
movsbl -0x1e(%rbp), %edi
callq 0xb950
cmpl $0x0, %eax
je 0x3792b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x0, 0xc(%rsi)
callq 0x38240
jmp 0x37d8b
movq -0x70(%rbp), %rax
movl 0xc(%rax), %ecx
movl %ecx, -0x64(%rbp)
cmpl $0x0, 0xc(%rax)
jne 0x37946
movq -0x70(%rbp), %rax
movl $0x1, 0xc(%rax)
movsbl -0x1e(%rbp), %eax
addl $-0x21, %eax
movl %eax, %ecx
movq %rcx, -0xa8(%rbp)
subl $0x5c, %eax
ja 0x37d76
movq -0xa8(%rbp), %rax
leaq 0x8887f(%rip), %rcx     # 0xc01ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0xc, %edx
callq 0x37430
jmp 0x37d8b
cmpl $0x0, -0x64(%rbp)
jne 0x379b0
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0xd, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
callq 0x38300
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0xe, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0xf, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x11, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x10, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x13, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x12, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x14, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x15, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x0, 0xc(%rsi)
movl $0x16, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x17, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x0, 0xc(%rsi)
movl $0x18, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x19, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x0, 0xc(%rsi)
movl $0x1a, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rdi
movq 0x28(%rdi), %rax
movq %rax, -0xb0(%rbp)
addq $0x10, %rdi
callq 0x332e0
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jae 0x37b95
movq -0x70(%rbp), %rax
movq %rax, %rdi
addq $0x10, %rdi
movq 0x28(%rax), %rsi
callq 0x374e0
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x37b95
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movq 0x28(%rsi), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsi)
movl $0x1e, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x1d, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rdi
movq 0x28(%rdi), %rax
movq %rax, -0xb8(%rbp)
addq $0x10, %rdi
callq 0x332e0
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq %rcx, %rax
jae 0x37c18
movq -0x70(%rbp), %rax
movq %rax, %rdi
addq $0x10, %rdi
movq 0x28(%rax), %rsi
callq 0x374e0
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x37c18
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movq 0x28(%rsi), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsi)
movl $0x20, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x1f, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rdi
movq 0x28(%rdi), %rax
movq %rax, -0xc0(%rbp)
addq $0x10, %rdi
callq 0x332e0
movq %rax, %rcx
movq -0xc0(%rbp), %rax
cmpq %rcx, %rax
jae 0x37c9b
movq -0x70(%rbp), %rax
movq %rax, %rdi
addq $0x10, %rdi
movq 0x28(%rax), %rsi
callq 0x374e0
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x37c9b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movq 0x28(%rsi), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsi)
movl $0x1b, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x21, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rdi
movq 0x28(%rdi), %rax
movq %rax, -0xc8(%rbp)
addq $0x10, %rdi
callq 0x332e0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
cmpq %rcx, %rax
jae 0x37d1b
movq -0x70(%rbp), %rax
movq %rax, %rdi
addq $0x10, %rdi
movq 0x28(%rax), %rsi
callq 0x374e0
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x37d1b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movq 0x28(%rsi), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsi)
movl $0x1c, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x21, %edx
callq 0x37430
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
callq 0x383d0
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x0, 0xc(%rsi)
callq 0x38300
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x0, 0xc(%rsi)
callq 0x38240
jmp 0x37d8b
movq -0x70(%rbp), %rsi
movq -0x88(%rbp), %rdi
movl $0x21, %edx
callq 0x37430
movq -0x80(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)