// File: /workspace/github_cpp_makefile_star2_O1/ivan-tkatchev[P]yalz77/./lz77.h
// Function: lz77::offsets_dict_t::operator()(unsigned short, unsigned char const*, unsigned char const*, unsigned char const*, unsigned long&, unsigned long&, unsigned long&)
void operator()(uint16_t packed, const unsigned char* i0, const unsigned char* i, const unsigned char* e,
                    size_t& maxrun, size_t& maxoffset, size_t& maxgain) {

        // Select a range of values representing a circular buffer.
        // The first value is the index of the buffer head, the rest are
        // the values of the buffer itself. 

        size_t* cb_start = &offsets[packed * (searchlen + 1)];

        size_t* cb_beg = (cb_start + 1);
        size_t* cb_end = (cb_start + 1 + searchlen);
        size_t* cb_head = cb_beg + *cb_start;

        size_t* cb_i = cb_head;

        while (1) {

            cb_i = prev(cb_beg, cb_end, cb_i);

            if (*cb_i == 0)
                break;

            // The stored value is position + 1 to allow 0 to mean 'uninitialized offset'.
            size_t pos = *cb_i - 1;

            size_t offset = i - i0 - pos;
            size_t run = substr_run(i, e, i0 + pos, e);
            size_t gain = gains(run, offset);

            if (gain > maxgain) {
                maxrun = run;
                maxoffset = offset;
                maxgain = gain;
            }

            if (cb_i == cb_head)
                break;
        }

        *cb_start = push_back(cb_beg, cb_end, cb_head, i - i0 + 1);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x40(%rsp), %r10
movl %esi, %eax
movq (%rdi), %rsi
movq 0x18(%rdi), %rdi
leaq 0x1(%rdi), %rbx
imulq %rax, %rbx
leaq (%rsi,%rbx,8), %r11
leaq (%rsi,%rbx,8), %rsi
addq $0x8, %rsi
leaq 0x8(%r11,%rdi,8), %rbx
movq -0x8(%rsi), %rax
movq %r11, -0x8(%rsp)
leaq (%r11,%rax,8), %rdi
addq $0x8, %rdi
leaq 0x1(%rcx), %rax
movq %rdi, %r15
cmpq %rsi, %r15
cmoveq %rbx, %r15
movq -0x8(%r15), %rbp
testq %rbp, %rbp
je 0x31c7
addq $-0x8, %r15
addq %rdx, %rbp
movq %rcx, %r12
subq %rbp, %r12
incq %r12
movq %rax, %r14
xorl %r13d, %r13d
movb -0x1(%r14), %r11b
cmpb -0x1(%rbp), %r11b
jne 0x3140
incq %r13
cmpq %r8, %r14
je 0x3140
leaq 0x1(%rbp), %r11
incq %r14
cmpq %r8, %rbp
movq %r11, %rbp
jne 0x311f
movq %r12, %r11
shlq $0x4, %r11
xorl %ebp, %ebp
cmpq $0x7f, %r11
seta %bpl
cmpq $0x4000, %r11           # imm = 0x4000
sbbq $-0x1, %rbp
cmpq $0x200000, %r11         # imm = 0x200000
sbbq $-0x1, %rbp
incq %rbp
cmpq $0x8, %r13
jb 0x319b
leaq -0x4(%r13), %r11
xorl %r14d, %r14d
cmpq $0x7f, %r11
seta %r14b
cmpq $0x4000, %r11           # imm = 0x4000
sbbq $-0x1, %rbp
addq %r14, %rbp
cmpq $0x200000, %r11         # imm = 0x200000
sbbq $-0x1, %rbp
incq %rbp
movq %r13, %r11
subq %rbp, %r11
movl $0x0, %r14d
cmovaeq %r11, %r14
cmpq (%r10), %r14
jbe 0x31be
movq %r13, (%r9)
movq 0x38(%rsp), %r11
movq %r12, (%r11)
movq %r14, (%r10)
cmpq %rdi, %r15
jne 0x30f5
subq %rdx, %rcx
incq %rcx
movq %rcx, (%rdi)
addq $0x8, %rdi
cmpq %rbx, %rdi
cmoveq %rsi, %rdi
subq %rsi, %rdi
sarq $0x3, %rdi
movq -0x8(%rsp), %rax
movq %rdi, (%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop