// File: /workspace/github_cpp_makefile_star2_O3/WayfireWM[P]wf-utils/wayfire/lexer/lexer.cpp
// Function: wf::lexer_t::_parse_encapsulated_literal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
variant_t lexer_t::_parse_encapsulated_literal(const std::string &s_bound, const std::string &e_bound)
{
    // Check if the boundary is at the end of the of the line.
    auto begin = _parse_position + s_bound.size();
    if (begin >= _size)
    {
        _parse_position = _size;
        throw std::runtime_error("Lexical parser error. Encapsulated literal is truncated.");
    }

    // Find the next occurrence of the boundary. Avoid escaped ones (\boundary).
    std::size_t found_at = 0;
    auto found = false;
    while (!found)
    {
        auto p = _text.find(e_bound, begin);
        if (p == std::string::npos)
        {
            // Not found before end of line, complain and bail out.
            _parse_position = _size;
            throw std::runtime_error("Lexical parser error. Encapsulated literal is truncated.");
        }

        // check the character before the boundary match to see if it is not an escape.
        if (_text.at(p - 1) != '\\')
        {
            found = true;
            found_at = p;
            break;
        }
    }

    // If we get here, and found == false, it must mean that all the matches were escaped -> trunctated.
    if (!found)
    {
        _parse_position = _size;
        throw std::runtime_error("Lexical parser error. Encapsulated literal is truncated.");
    }

    // Found a good match. The string we want is between _parse_position and (found_at + boundary_length)
    auto length = (found_at + e_bound.size()) - _parse_position;
    auto literal_text = _text.substr(_parse_position, length);
    _parse_position += length;
    return parse_literal(literal_text);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x8(%rdx), %r13
movq (%rsi), %rax
movq %rsi, %r14
addq 0x28(%rsi), %r13
cmpq %rax, %r13
jae 0x79a0
leaq 0x8(%r14), %r12
movq %rcx, %r15
movq %rdi, %rbx
movq (%r15), %rsi
movq 0x8(%r15), %rcx
movq %r12, %rdi
movq %r13, %rdx
callq 0x5380
cmpq $-0x1, %rax
je 0x7959
movq 0x10(%r14), %rdx
leaq -0x1(%rax), %rsi
movq %rax, %rbp
cmpq %rsi, %rdx
jbe 0x7992
movq (%r12), %rax
cmpb $0x5c, (%rax,%rsi)
je 0x78c9
addq 0x8(%r15), %rbp
movq 0x28(%r14), %rdx
leaq 0x8(%rsp), %r15
movq %r12, %rsi
movq %r15, %rdi
subq %rdx, %rbp
movq %rbp, %rcx
callq 0x5250
addq %rbp, 0x28(%r14)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x80c6
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7947
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5230
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rax
movl $0x10, %edi
movq %rax, 0x28(%r14)
callq 0x5110
movq %rax, %r14
leaq 0x4873(%rip), %rsi      # 0xc1e7
movq %rax, %rdi
callq 0x50d0
movq 0xb66d(%rip), %rsi      # 0x12ff0
movq 0xb62e(%rip), %rdx      # 0x12fb8
movq %r14, %rdi
callq 0x5370
leaq 0x48d1(%rip), %rdi      # 0xc26a
xorl %eax, %eax
callq 0x5300
movl $0x10, %edi
movq %rax, 0x28(%r14)
callq 0x5110
movq %rax, %r14
leaq 0x482f(%rip), %rsi      # 0xc1e7
movq %rax, %rdi
callq 0x50d0
jmp 0x797c
jmp 0x79e4
leaq 0x18(%rsp), %rcx
movq %rax, %rbx
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0x79ef
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0x79ef
movq %r14, %rdi
movq %rax, %rbx
callq 0x51a0
movq %rbx, %rdi
callq 0x5390