// File: /workspace/github_cpp_makefile_star2_O1/rofl0r[P]ascc/util_string.cpp
// Function: AGS::Common::String::FindSection(char, unsigned long, unsigned long, bool, bool, unsigned long&, unsigned long&) const
bool String::FindSection(char separator, size_t first, size_t last, bool exclude_first_sep, bool exclude_last_sep,
                        size_t &from, size_t &to) const
{
    if (!_meta || !separator)
    {
        return false;
    }
    if (first > last)
    {
        return false;
    }

    size_t this_field = 0;
    size_t slice_from = 0;
    size_t slice_to = _meta->Length;
    size_t slice_at = -1;
    do
    {
        slice_at = FindChar(separator, slice_at + 1);
        if (slice_at == -1)
            slice_at = _meta->Length;
        // found where previous field ends
        if (this_field == last)
        {
            // if previous field is the last one to be included,
            // then set the section tail
            slice_to = exclude_last_sep ? slice_at : slice_at + 1;
        }
        if (slice_at != _meta->Length)
        {
            this_field++;
            if (this_field == first)
            {
                // if the new field is the first one to be included,
                // then set the section head
                slice_from = exclude_first_sep ? slice_at + 1 : slice_at;
            }
        }
    }
    while (slice_at < _meta->Length && this_field <= last);

    // the search is a success if at least the first field was found
    if (this_field >= first)
    {
        // correct the indices to stay in the [0; length] range
        assert(slice_from <= slice_to);
        from = Math::Clamp(slice_from, (size_t)0, _meta->Length);
        to   = Math::Clamp(slice_to, (size_t)0, _meta->Length);
        return true;
    }
    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, 0x8(%rsp)
xorl %eax, %eax
movq %rdx, 0x10(%rsp)
cmpq %rcx, %rdx
ja 0x1572a
testb %sil, %sil
je 0x1572a
movq %rcx, %r15
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x1572a
movq 0x10(%rcx), %r12
xorb $0x1, %r9b
movzbl %r9b, %eax
movq %rax, 0x20(%rsp)
movzbl %r8b, %eax
movq %rax, 0x18(%rsp)
movq $-0x1, %rax
xorl %edx, %edx
movsbl %sil, %ebp
movq %r12, %rcx
xorl %esi, %esi
movq %rsi, %r14
movq %rdx, %r13
movq %rcx, %rbx
incq %rax
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0x15546
cmpq $-0x1, %rax
cmoveq %r12, %rax
movq 0x20(%rsp), %rcx
addq %rax, %rcx
cmpq %r15, %r14
cmovneq %rbx, %rcx
leaq 0x1(%r14), %rsi
movq 0x18(%rsp), %rdx
addq %rax, %rdx
cmpq 0x10(%rsp), %rsi
cmovneq %r13, %rdx
cmpq %r12, %rax
cmoveq %r13, %rdx
cmoveq %r14, %rsi
jae 0x156f1
cmpq %r15, %rsi
jbe 0x15698
cmpq 0x10(%rsp), %rsi
setae %al
jb 0x1572a
cmpq %rcx, %rdx
ja 0x15739
cmpq %r12, %rdx
cmovbq %rdx, %r12
movq 0x60(%rsp), %rdx
movq %r12, (%rdx)
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
movq 0x10(%rdx), %rdx
cmpq %rdx, %rcx
cmovbq %rcx, %rdx
movq 0x68(%rsp), %rcx
movq %rdx, (%rcx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x78bb(%rip), %rdi      # 0x1cffb
leaq 0x78cb(%rip), %rsi      # 0x1d012
leaq 0x78d4(%rip), %rcx      # 0x1d022
movl $0x11f, %edx            # imm = 0x11F
callq 0x3240