// File: /workspace/github_cpp_makefile_star2_O2/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 0x13c57
testb %sil, %sil
je 0x13c57
movq %rcx, %r15
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x13c57
movq 0x10(%rcx), %r12
xorb $0x1, %r9b
movzbl %r9b, %eax
movq %rax, 0x20(%rsp)
movzbl %r8b, %eax
movq %rax, 0x18(%rsp)
pushq $-0x1
popq %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 0x13a88
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 0x13c1b
cmpq %r15, %rsi
jbe 0x13bc2
cmpq 0x10(%rsp), %rsi
jae 0x13c26
xorl %eax, %eax
jmp 0x13c57
cmpq %rcx, %rdx
ja 0x13c66
cmpq %r12, %rdx
cmovbq %rdx, %r12
movq 0x60(%rsp), %rax
movq %r12, (%rax)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
cmpq %rax, %rcx
cmovbq %rcx, %rax
movq 0x68(%rsp), %rcx
movq %rax, (%rcx)
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x739f(%rip), %rdi      # 0x1b00c
leaq 0x73af(%rip), %rsi      # 0x1b023
leaq 0x73b8(%rip), %rcx      # 0x1b033
movl $0x11f, %edx            # imm = 0x11F
callq 0x3240
nop