// File: /workspace/github_cpp_makefile_star2_O2/ivan-tkatchev[P]yalz77/./lz77.h
// Function: lz77::decompress_t::feed(unsigned char const*, unsigned char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool feed(const unsigned char* i, const unsigned char* e, std::string& remaining) {

        // This function is complex because it is streamable and robust.
        // The routine checks if the input isn't complete and will properly
        // pick up from where we left off when the rest of the input arrives.
        
        if (state.state == state_t::INIT) {

            ret.clear();

            size_t size;
            if (!pop_vlq_uint(i, e, size))
                return true;

            ++i;

            state = state_t();

            if (max_size && size > max_size)
                throw std::length_error("Uncompressed data in message deemed too large");

            ret.resize(size);

            outb = (unsigned char*)ret.data();
            oute = outb + size;
            out = outb;

            state.state = state_t::START;
        }

        while (i != e) {

            if (out == oute) {
                remaining.assign(i, e);
                state.state = state_t::INIT;
                return true;
            }

            if (state.state == state_t::START) {

                if (!pop_vlq_uint(i, e, state.msg))
                    return false;

                ++i;

                state.state = ((state.msg & 1) ? state_t::READ_DATA : state_t::READ_RUN);

                state.msg = state.msg >> 1;
            }

            if (state.state == state_t::READ_DATA) {

                size_t len = state.msg;
                
                if (out + len > oute)
                    throw std::runtime_error("Malformed data while uncompressing");

                if (i == e)
                    return false;

                if (i + len > e) {

                    size_t l = e - i;
                    ::memcpy(out, &(*i), l);
                    out += l;
                    state.msg -= l;

                    return false;
                }

                ::memcpy(out, &(*i), len);
                out += len;
                i += len;

                state.state = state_t::START;

            } else if (state.state == state_t::READ_RUN) {

                size_t shortrun = state.msg & (SHORTRUN_MAX - 1);

                if (shortrun) {

                    state.run = shortrun;

                } else {

                    if (!pop_vlq_uint(i, e, state.run))
                        return false;

                    ++i;
                }

                size_t off = (state.msg >> SHORTRUN_BITS);
                size_t run = state.run + MIN_RUN - 1;

                unsigned char* outi = out - off;

                if (outi >= oute || outi < outb || out + run > oute || out + run < out)
                    throw std::runtime_error("Malformed data while uncompressing");

                if (outi + run < out) {
                    ::memcpy(out, outi, run);
                    out += run;

                } else {

                    while (run > 0) {
                        *out = *outi;
                        ++out;
                        ++outi;
                        --run;
                    }
                }

                state.state = state_t::START;
            }
        }

        if (out == oute) {
            remaining.assign(i, e);
            state.state = state_t::INIT;
            return true;
        }

        return false;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r15
movq %rdx, %r14
movq %rdi, %rbx
movq %rsi, (%rsp)
leaq 0x40(%rdi), %r12
movl 0x60(%rdi), %eax
testl %eax, %eax
jne 0x279c
andq $0x0, 0x10(%rbx)
movq 0x8(%rbx), %rax
movb $0x0, (%rax)
movq %rsp, %rsi
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rdx
callq 0x31ac
testb %al, %al
je 0x291f
incq (%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movups %xmm0, (%r12)
andl $0x0, 0x20(%r12)
movq (%rbx), %rax
testq %rax, %rax
setne %cl
movq 0x10(%rsp), %rsi
cmpq %rax, %rsi
seta %al
andb %cl, %al
cmpb $0x1, %al
je 0x2993
leaq 0x8(%rbx), %rdi
callq 0x2150
movq 0x8(%rbx), %rax
movq %rax, 0x30(%rbx)
movq 0x10(%rsp), %rcx
addq %rax, %rcx
movq %rcx, 0x38(%rbx)
movq %rax, 0x28(%rbx)
movl $0x1, 0x60(%rbx)
pushq $0x1
popq %rax
movq %r15, 0x8(%rsp)
pushq $0x1
popq %rbp
leaq 0x48(%rbx), %r13
movq (%rsp), %rsi
movq 0x28(%rbx), %rcx
movq 0x38(%rbx), %rdx
cmpq %r14, %rsi
je 0x2909
cmpq %rdx, %rcx
je 0x290e
cmpl $0x1, %eax
jne 0x2805
movq %rbx, %rdi
movq %rsp, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x31ac
testb %al, %al
je 0x2936
movq (%rsp), %rsi
incq %rsi
movq %rsi, (%rsp)
movq 0x40(%rbx), %rcx
movl %ecx, %eax
andl $0x1, %eax
xorl $0x3, %eax
movl %eax, 0x60(%rbx)
shrq %rcx
movq %rcx, 0x40(%rbx)
cmpl $0x3, %eax
je 0x2850
cmpl $0x2, %eax
jne 0x27a8
movq 0x28(%rbx), %rdi
movq 0x40(%rbx), %r15
leaq (%rdi,%r15), %rax
cmpq 0x38(%rbx), %rax
ja 0x2947
cmpq %r14, %rsi
je 0x2936
leaq (%rsi,%r15), %rax
cmpq %r14, %rax
ja 0x2923
movq %r15, %rdx
callq 0x20f0
addq %r15, 0x28(%rbx)
addq %r15, (%rsp)
jmp 0x28df
movq (%r12), %rcx
movq %rcx, %rax
andq $0x7, %rax
je 0x2863
movq %rax, (%r13)
jmp 0x2888
movq %rbx, %rdi
movq %rsp, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x31ac
testb %al, %al
je 0x2936
incq (%rsp)
movq (%r12), %rcx
movq (%r13), %rax
shrq $0x3, %rcx
movq 0x28(%rbx), %rdi
movq %rdi, %rsi
subq %rcx, %rsi
movq 0x38(%rbx), %rcx
cmpq %rcx, %rsi
jae 0x2963
cmpq 0x30(%rbx), %rsi
jb 0x2963
movq %rax, %r15
addq $0x4, %r15
js 0x2963
addq %rdi, %rax
addq $0x4, %rax
cmpq %rcx, %rax
ja 0x2963
leaq (%rsi,%r15), %rax
cmpq %rdi, %rax
jae 0x28ed
movq %r15, %rdx
callq 0x20f0
addq %r15, 0x28(%rbx)
movl $0x1, 0x60(%rbx)
movl %ebp, %eax
jmp 0x27a8
xorl %eax, %eax
cmpq %rax, %r15
je 0x28df
movb (%rsi,%rax), %cl
movb %cl, (%rdi)
movq 0x28(%rbx), %rdi
incq %rdi
movq %rdi, 0x28(%rbx)
incq %rax
jmp 0x28ef
cmpq %rdx, %rcx
jne 0x2936
movq 0x8(%rsp), %rdi
movq %r14, %rdx
callq 0x3202
andl $0x0, 0x60(%rbx)
movb $0x1, %al
jmp 0x2938
subq %rsi, %r14
movq %r14, %rdx
callq 0x20f0
addq %r14, 0x28(%rbx)
subq %r14, 0x40(%rbx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20a0
movq %rax, %r14
leaq 0x1832(%rip), %rsi      # 0x418b
movq %rax, %rdi
callq 0x2060
jmp 0x297d
pushq $0x10
popq %rdi
callq 0x20a0
movq %rax, %r14
leaq 0x1816(%rip), %rsi      # 0x418b
movq %rax, %rdi
callq 0x2060
movq 0x366c(%rip), %rsi      # 0x5ff0
movq 0x3635(%rip), %rdx      # 0x5fc0
movq %r14, %rdi
callq 0x21d0
pushq $0x10
popq %rdi
callq 0x20a0
movq %rax, %r14
leaq 0x17b8(%rip), %rsi      # 0x415d
movq %rax, %rdi
callq 0x2140
movq 0x361c(%rip), %rsi      # 0x5fd0
movq 0x35fd(%rip), %rdx      # 0x5fb8
jmp 0x298b
jmp 0x29c1
jmp 0x29c1
movq %rax, %rbx
movq %r14, %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x21e0