// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x40(%rdi), %rbp
movl 0x60(%rdi), %ecx
testl %ecx, %ecx
je 0x2951
cmpq %r14, %r15
je 0x299c
leaq 0x50(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rbx), %rdi
movq 0x38(%rbx), %rax
cmpq %rax, %rdi
je 0x29aa
cmpl $0x1, %ecx
jne 0x2802
movq 0x50(%rbx), %rdx
movq 0x58(%rbx), %rcx
movzbl (%r15), %esi
testb %sil, %sil
jns 0x27dc
andl $0x7f, %esi
shlq %cl, %rsi
orq %rsi, %rdx
movq %rdx, 0x50(%rbx)
addq $0x7, %rcx
movq %rcx, 0x58(%rbx)
incq %r15
cmpq %r14, %r15
jne 0x27b1
jmp 0x29a6
shlq %cl, %rsi
orq %rdx, %rsi
movq 0x8(%rsp), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
incq %r15
movl %esi, %ecx
andl $0x1, %ecx
xorl $0x3, %ecx
movl %ecx, 0x60(%rbx)
shrq %rsi
movq %rsi, 0x40(%rbx)
cmpl $0x3, %ecx
je 0x285a
cmpl $0x2, %ecx
jne 0x2925
movq (%rbp), %r13
leaq (%rdi,%r13), %rcx
cmpq %rax, %rcx
ja 0x2a51
cmpq %r14, %r15
je 0x29a6
movq %rbp, 0x10(%rsp)
movq %r12, %rbp
leaq (%r15,%r13), %r12
cmpq %r14, %r12
ja 0x2a36
movq %r15, %rsi
movq %r13, %rdx
callq 0x20f0
movq %r12, %r15
movq %rbp, %r12
movq 0x10(%rsp), %rbp
jmp 0x290e
movq (%rbp), %rdx
movq %rdx, %r8
andq $0x7, %r8
je 0x286d
movq %r8, 0x48(%rbx)
jmp 0x28c2
cmpq %r14, %r15
je 0x29a6
movq 0x50(%rbx), %rsi
movq 0x58(%rbx), %rcx
movzbl (%r15), %r8d
testb %r8b, %r8b
jns 0x28aa
andl $0x7f, %r8d
shlq %cl, %r8
orq %r8, %rsi
movq %rsi, 0x50(%rbx)
addq $0x7, %rcx
movq %rcx, 0x58(%rbx)
incq %r15
cmpq %r14, %r15
jne 0x287e
jmp 0x29a6
shlq %cl, %r8
orq %rsi, %r8
movq %r8, 0x48(%rbx)
movq 0x8(%rsp), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
incq %r15
shrq $0x3, %rdx
movq %rdi, %rsi
subq %rdx, %rsi
cmpq %rax, %rsi
jae 0x2a6f
cmpq 0x30(%rbx), %rsi
jb 0x2a6f
movq %r8, %r13
addq $0x4, %r13
js 0x2a6f
leaq (%rdi,%r8), %rcx
addq $0x4, %rcx
cmpq %rax, %rcx
ja 0x2a6f
leaq (%rsi,%r13), %rax
cmpq %rdi, %rax
jae 0x2930
movq %r13, %rdx
callq 0x20f0
addq 0x28(%rbx), %r13
movq %r13, 0x28(%rbx)
movq %r13, %rdi
movl $0x1, 0x60(%rbx)
movl $0x1, %ecx
cmpq %r14, %r15
jne 0x2797
jmp 0x29a0
testq %r13, %r13
je 0x2919
xorl %eax, %eax
movb (%rsi,%rax), %cl
movb %cl, (%rdi)
movq 0x28(%rbx), %rdi
incq %rdi
movq %rdi, 0x28(%rbx)
incq %rax
cmpq %rax, %r13
jne 0x2937
jmp 0x2919
movq $0x0, 0x10(%rbx)
movq 0x8(%rbx), %rax
movb $0x0, (%rax)
movb $0x1, %al
cmpq %r14, %r15
je 0x29cd
leaq 0x8(%rbx), %rdi
movq 0x50(%rbx), %rdx
movq 0x58(%rbx), %rcx
movzbl (%r15), %r13d
testb %r13b, %r13b
jns 0x29dc
andl $0x7f, %r13d
shlq %cl, %r13
orq %r13, %rdx
movq %rdx, 0x50(%rbx)
addq $0x7, %rcx
movq %rcx, 0x58(%rbx)
incq %r15
cmpq %r14, %r15
jne 0x2973
jmp 0x29cd
movq 0x28(%rbx), %rdi
cmpq 0x38(%rbx), %rdi
je 0x29aa
xorl %eax, %eax
jmp 0x29cd
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %r12, %rdi
movq %r15, %rcx
movq %r14, %r8
callq 0x35b0
movl $0x0, 0x60(%rbx)
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shlq %cl, %r13
orq %rdx, %r13
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbp)
movups %xmm0, (%rbp)
movl $0x0, 0x20(%rbp)
movq (%rbx), %rax
testq %rax, %rax
je 0x2a05
cmpq %rax, %r13
ja 0x2aa1
incq %r15
movq %r13, %rsi
xorl %edx, %edx
callq 0x2040
movq 0x8(%rbx), %rax
movq %rax, 0x30(%rbx)
addq %rax, %r13
movq %r13, 0x38(%rbx)
movq %rax, 0x28(%rbx)
movl $0x1, 0x60(%rbx)
movl $0x1, %ecx
jmp 0x2781
subq %r15, %r14
movq %r15, %rsi
movq %r14, %rdx
callq 0x20f0
addq %r14, 0x28(%rbx)
subq %r14, 0x40(%rbx)
jmp 0x29a6
movl $0x10, %edi
callq 0x2090
movq %rax, %rbx
leaq 0x1762(%rip), %rsi      # 0x41c7
movq %rax, %rdi
callq 0x2070
jmp 0x2a8b
movl $0x10, %edi
callq 0x2090
movq %rax, %rbx
leaq 0x1744(%rip), %rsi      # 0x41c7
movq %rax, %rdi
callq 0x2070
movq 0x355e(%rip), %rsi      # 0x5ff0
movq 0x3527(%rip), %rdx      # 0x5fc0
movq %rbx, %rdi
callq 0x21a0
movl $0x10, %edi
callq 0x2090
movq %rax, %rbx
leaq 0x16e4(%rip), %rsi      # 0x4199
movq %rax, %rdi
callq 0x2140
movq 0x350c(%rip), %rsi      # 0x5fd0
movq 0x34ed(%rip), %rdx      # 0x5fb8
jmp 0x2a99
jmp 0x2ad1
jmp 0x2ad1
movq %rax, %r14
movq %rbx, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x21b0