// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
leaq 0x40(%rdi), %r12
cmpl $0x0, 0x60(%rdi)
je 0x298b
movq 0x8(%rsp), %rcx
cmpq %r14, %rcx
je 0x2956
movq 0x28(%rbx), %rax
cmpq 0x38(%rbx), %rax
je 0x2967
leaq 0x48(%rbx), %rax
movq %rax, 0x10(%rsp)
movb $0x1, %bpl
cmpl $0x1, 0x60(%rbx)
jne 0x280a
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x35c2
testb %al, %al
je 0x2960
incq 0x8(%rsp)
movq 0x40(%rbx), %rax
movl %eax, %ecx
andl $0x1, %ecx
xorl $0x3, %ecx
movl %ecx, 0x60(%rbx)
shrq %rax
movq %rax, 0x40(%rbx)
movl 0x60(%rbx), %eax
cmpl $0x3, %eax
je 0x2867
cmpl $0x2, %eax
jne 0x293c
movq 0x28(%rbx), %rdi
movq 0x40(%rbx), %r13
leaq (%rdi,%r13), %rax
cmpq 0x38(%rbx), %rax
ja 0x2a8a
movq 0x8(%rsp), %rsi
cmpq %r14, %rsi
je 0x28f6
leaq (%rsi,%r13), %rax
cmpq %r14, %rax
jbe 0x291a
movq %r14, %r13
subq %rsi, %r13
movq %r13, %rdx
callq 0x20f0
addq %r13, 0x28(%rbx)
subq %r13, 0x40(%rbx)
jmp 0x28f6
movq (%r12), %rax
andq $0x7, %rax
je 0x2877
movq %rax, 0x48(%rbx)
jmp 0x2895
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
movq %r14, %rdx
movq 0x10(%rsp), %rcx
callq 0x35c2
testb %al, %al
je 0x28f6
incq 0x8(%rsp)
movq 0x40(%rbx), %rax
shrq $0x3, %rax
movq 0x28(%rbx), %rdi
movq %rdi, %rsi
subq %rax, %rsi
movq 0x38(%rbx), %rax
cmpq %rax, %rsi
jae 0x2aa8
cmpq 0x30(%rbx), %rsi
jb 0x2aa8
movq 0x48(%rbx), %rcx
movq %rcx, %r13
addq $0x4, %r13
js 0x2aa8
addq %rdi, %rcx
addq $0x4, %rcx
cmpq %rax, %rcx
ja 0x2aa8
leaq (%rsi,%r13), %rax
cmpq %rdi, %rax
jae 0x28fc
movq %r13, %rdx
callq 0x20f0
addq %r13, 0x28(%rbx)
jmp 0x292b
xorl %eax, %eax
xorl %ebp, %ebp
jmp 0x2934
testq %r13, %r13
je 0x292b
xorl %eax, %eax
movb (%rsi,%rax), %cl
movq 0x28(%rbx), %rdx
movb %cl, (%rdx)
incq 0x28(%rbx)
incq %rax
cmpq %rax, %r13
jne 0x2903
jmp 0x292b
movq %r13, %rdx
callq 0x20f0
addq %r13, 0x28(%rbx)
addq %r13, 0x8(%rsp)
movl $0x1, 0x60(%rbx)
movb $0x1, %al
testb %al, %al
je 0x2a75
movq 0x8(%rsp), %rcx
cmpq %r14, %rcx
je 0x2956
movq 0x28(%rbx), %rax
cmpq 0x38(%rbx), %rax
jne 0x27ce
jmp 0x2967
movq 0x28(%rbx), %rax
cmpq 0x38(%rbx), %rax
je 0x2967
xorl %ebp, %ebp
jmp 0x2a75
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %r15, %rdi
movq %r14, %r8
callq 0x362e
movl $0x0, 0x60(%rbx)
movb $0x1, %bpl
jmp 0x2a75
movq %r15, 0x10(%rsp)
leaq 0x8(%rbx), %rdi
movq $0x0, 0x10(%rbx)
movq 0x8(%rbx), %rax
movb $0x0, (%rax)
movq 0x8(%rsp), %r8
leaq 0x50(%rbx), %rax
movq 0x50(%rbx), %rdx
movq 0x58(%rbx), %rcx
movq %r8, %r15
cmpq %r14, %r8
je 0x2a06
movzbl (%r15), %esi
testb %sil, %sil
js 0x29d6
movq %rsi, %r8
shlq %cl, %r8
orq %r8, %rdx
movq %rdx, (%rax)
movq %r15, %r8
jmp 0x29f8
movl %esi, %r8d
andl $0x7f, %r8d
shlq %cl, %r8
orq %r8, %rdx
movq %rdx, 0x50(%rbx)
addq $0x7, %rcx
movq %rcx, 0x58(%rbx)
leaq 0x1(%r15), %r8
movq %r8, 0x8(%rsp)
testb %sil, %sil
js 0x29b4
movq (%rax), %r13
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movb $0x1, %bpl
cmpq %r14, %r15
je 0x2a75
incq 0x8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movups %xmm0, (%r12)
movl $0x0, 0x20(%r12)
movq (%rbx), %rax
testq %rax, %rax
setne %cl
cmpq %rax, %r13
seta %al
andb %cl, %al
cmpb $0x1, %al
je 0x2ada
movq %r13, %rsi
xorl %edx, %edx
callq 0x2040
movq 0x8(%rbx), %rax
addq %rax, %r13
movq %rax, 0x30(%rbx)
movq %r13, 0x38(%rbx)
movq %rax, 0x28(%rbx)
movl $0x1, 0x60(%rbx)
cmpq %r14, %r15
movq 0x10(%rsp), %r15
jne 0x27a6
andb $0x1, %bpl
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x2090
movq %rax, %rbx
leaq 0x1719(%rip), %rsi      # 0x41b7
movq %rax, %rdi
callq 0x2070
jmp 0x2ac4
movl $0x10, %edi
callq 0x2090
movq %rax, %rbx
leaq 0x16fb(%rip), %rsi      # 0x41b7
movq %rax, %rdi
callq 0x2070
movq 0x3525(%rip), %rsi      # 0x5ff0
movq 0x34ee(%rip), %rdx      # 0x5fc0
movq %rbx, %rdi
callq 0x21a0
movl $0x10, %edi
callq 0x2090
movq %rax, %rbx
leaq 0x169b(%rip), %rsi      # 0x4189
movq %rax, %rdi
callq 0x2140
movq 0x34d3(%rip), %rsi      # 0x5fd0
movq 0x34b4(%rip), %rdx      # 0x5fb8
jmp 0x2ad2
jmp 0x2b0a
jmp 0x2b0a
movq %rax, %r14
movq %rbx, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x21b0
nop