// File: /workspace/github_c_makefile_star2_O3/madler[P]pigz/pigz.c
// Function: unlzw
local void unlzw(void) {
    unsigned bits;              // current bits per code (9..16)
    unsigned mask;              // mask for current bits codes = (1<<bits)-1
    bits_t buf;                 // bit buffer (need 23 bits)
    unsigned left;              // bits left in buf (0..7 after code pulled)
    length_t mark;              // offset where last change in bits began
    unsigned code;              // code, table traversal index
    unsigned max;               // maximum bits per code for this stream
    unsigned flags;             // compress flags, then block compress flag
    unsigned end;               // last valid entry in prefix/suffix tables
    unsigned prev;              // previous code
    unsigned final;             // last character written for previous code
    unsigned stack;             // next position for reversed string
    unsigned outcnt;            // bytes in output buffer
    // memory for unlzw() -- the first 256 entries of prefix[] and suffix[] are
    // never used, so could have offset the index but it's faster to waste a
    // little memory
    prefix_t prefix[65536];             // index to LZW prefix string
    unsigned char suffix[65536];        // one-character LZW suffix
    unsigned char match[65280 + 2];     // buffer for reversed match

    // process remainder of compress header -- a flags byte
    g.out_tot = 0;
    if (NOMORE())
        throw(EDOM, "%s: lzw premature end", g.inf);
    flags = NEXT();
    if (flags & 0x60)
        throw(EDOM, "%s: unknown lzw flags set", g.inf);
    max = flags & 0x1f;
    if (max < 9 || max > 16)
        throw(EDOM, "%s: lzw bits out of range", g.inf);
    if (max == 9)                           // 9 doesn't really mean 9
        max = 10;
    flags &= 0x80;                          // true if block compress

    // mark the start of the compressed data for computing the first flush
    mark = g.in_tot - g.in_left;

    // clear table, start at nine bits per symbol
    bits = 9;
    mask = 0x1ff;
    end = flags ? 256 : 255;

    // set up: get first 9-bit code, which is the first decompressed byte, but
    // don't create a table entry until the next code
    if (NOMORE())                           // no compressed data is ok
        return;
    buf = NEXT();
    if (NOMORE())
        throw(EDOM, "%s: lzw premature end", g.inf);  // need nine bits
    buf += NEXT() << 8;
    final = prev = buf & mask;              // code
    buf >>= bits;
    left = 16 - bits;
    if (prev > 255)
        throw(EDOM, "%s: invalid lzw code", g.inf);
    out_buf[0] = (unsigned char)final;      // write first decompressed byte
    outcnt = 1;

    // decode codes
    stack = 0;
    for (;;) {
        // if the table will be full after this, increment the code size
        if (end >= mask && bits < max) {
            // flush unused input bits and bytes to next 8*bits bit boundary
            // (this is a vestigial aspect of the compressed data format
            // derived from an implementation that made use of a special VAX
            // machine instruction!)
            {
                unsigned rem = ((g.in_tot - g.in_left) - mark) % bits;
                if (rem) {
                    rem = bits - rem;
                    if (NOMORE())
                        break;              // end of compressed data
                    while (rem > g.in_left) {
                        rem -= g.in_left;
                        if (load() == 0)
                            throw(EDOM, "%s: lzw premature end", g.inf);
                    }
                    g.in_left -= rem;
                    g.in_next += rem;
                }
            }
            buf = 0;
            left = 0;

            // mark this new location for computing the next flush
            mark = g.in_tot - g.in_left;

            // go to the next number of bits per symbol
            bits++;
            mask <<= 1;
            mask++;
        }

        // get a code of bits bits
        if (NOMORE())
            break;                          // end of compressed data
        buf += (bits_t)(NEXT()) << left;
        left += 8;
        if (left < bits) {
            if (NOMORE())
                throw(EDOM, "%s: lzw premature end", g.inf);
            buf += (bits_t)(NEXT()) << left;
            left += 8;
        }
        code = buf & mask;
        buf >>= bits;
        left -= bits;

        // process clear code (256)
        if (code == 256 && flags) {
            // flush unused input bits and bytes to next 8*bits bit boundary
            {
                unsigned rem = ((g.in_tot - g.in_left) - mark) % bits;
                if (rem) {
                    rem = bits - rem;
                    while (rem > g.in_left) {
                        rem -= g.in_left;
                        if (load() == 0)
                            throw(EDOM, "%s: lzw premature end", g.inf);
                    }
                    g.in_left -= rem;
                    g.in_next += rem;
                }
            }
            buf = 0;
            left = 0;

            // mark this new location for computing the next flush
            mark = g.in_tot - g.in_left;

            // go back to nine bits per symbol
            bits = 9;                       // initialize bits and mask
            mask = 0x1ff;
            end = 255;                      // empty table
            continue;                       // get next code
        }

        // special code to reuse last match
        {
            unsigned temp = code;           // save the current code
            if (code > end) {
                // be picky on the allowed code here, and make sure that the
                // code we drop through (prev) will be a valid index so that
                // random input does not cause an exception
                if (code != end + 1 || prev > end)
                    throw(EDOM, "%s: invalid lzw code", g.inf);
                match[stack++] = (unsigned char)final;
                code = prev;
            }

            // walk through linked list to generate output in reverse order
            while (code >= 256) {
                match[stack++] = suffix[code];
                code = prefix[code];
            }
            match[stack++] = (unsigned char)code;
            final = code;

            // link new table entry
            if (end < mask) {
                end++;
                prefix[end] = (prefix_t)prev;
                suffix[end] = (unsigned char)final;
            }

            // set previous code for next iteration
            prev = temp;
        }

        // write output in forward order
        while (stack > OUTSIZE - outcnt) {
            while (outcnt < OUTSIZE)
                out_buf[outcnt++] = match[--stack];
            g.out_tot += outcnt;
            if (g.decode == 1)
                writen(g.outd, out_buf, outcnt);
            outcnt = 0;
        }
        do {
            out_buf[outcnt++] = match[--stack];
        } while (stack);
    }

    // write any remaining buffered output
    g.out_tot += outcnt;
    if (outcnt && g.decode == 1)
        writen(g.outd, out_buf, outcnt);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3ff58, %rsp          # imm = 0x3FF58
movq $0x0, 0x1c1e2(%rip) # 0x25498
movq 0x1c1c3(%rip), %r14     # 0x25480
testq %r14, %r14
jne 0x92e4
cmpl $0x0, 0x1c1bf(%rip)     # 0x25488
jne 0x97ed
callq 0xb08c
testq %rax, %rax
je 0x97ed
movq 0x1c19c(%rip), %r14     # 0x25480
decq %r14
movq %r14, 0x1c192(%rip)     # 0x25480
movq 0x1c183(%rip), %rcx     # 0x25478
leaq 0x1(%rcx), %rax
movq %rax, 0x1c178(%rip)     # 0x25478
movzbl (%rcx), %ebx
testb $0x60, %bl
jne 0x9819
movl %ebx, %ecx
andl $0x1f, %ecx
leal -0x11(%rcx), %edx
cmpl $-0x9, %edx
jbe 0x9829
cmpl $0x9, %ecx
movl $0xa, %edx
cmovnel %ecx, %edx
movl %edx, 0x34(%rsp)
movq 0x1c15d(%rip), %r15     # 0x25490
movq %r14, %rcx
testq %r14, %r14
je 0x97b5
movl %ebx, 0x1c(%rsp)
leaq 0x1(%rax), %rdx
decq %rcx
movq %rcx, 0x1c12f(%rip)     # 0x25480
movq %rdx, 0x1c120(%rip)     # 0x25478
movb (%rax), %bpl
jne 0x9386
cmpl $0x0, 0x1c124(%rip)     # 0x25488
jne 0x97ed
callq 0xb08c
testq %rax, %rax
je 0x97ed
movq 0x1c101(%rip), %rcx     # 0x25480
movq 0x1c0f2(%rip), %rdx     # 0x25478
movzbl %bpl, %esi
decq %rcx
movq %rcx, 0x1c0ec(%rip)     # 0x25480
leaq 0x1(%rdx), %rax
movq %rax, 0x1c0d9(%rip)     # 0x25478
movzbl (%rdx), %ebx
movl %ebx, %eax
shll $0x8, %eax
orl %eax, %esi
andl $0x1ff, %esi            # imm = 0x1FF
cmpl $0x100, %esi            # imm = 0x100
jae 0x9809
movq %r15, %rdx
subq %r14, %rdx
movl 0x1c(%rsp), %eax
shrb $0x7, %al
movzbl %al, %eax
addl $0xff, %eax
shrl %ebx
movb %bpl, 0x24127(%rip)     # 0x2d500
movl $0x9, %r13d
movl $0x1, 0x4(%rsp)
movl $0x7, %edi
movl $0x1ff, %ecx            # imm = 0x1FF
movq %rsi, 0x28(%rsp)
movl %esi, 0x14(%rsp)
movl 0x1c(%rsp), %r12d
movq %rbx, %r15
movl %edi, %r14d
movq %rax, 0x20(%rsp)
movq %rcx, 0x8(%rsp)
cmpl %ecx, %eax
jb 0x9489
cmpl 0x34(%rsp), %r13d
jae 0x9489
movq 0x1c06f(%rip), %rcx     # 0x25490
movq 0x1c058(%rip), %rsi     # 0x25480
addq %rsi, %rdx
movq %rcx, %rax
subq %rdx, %rax
movl %r13d, %edi
xorl %edx, %edx
divq %rdi
testq %rdx, %rdx
je 0x94a7
movq %rdx, %r14
testq %rsi, %rsi
jne 0x9461
cmpl $0x0, 0x1c03b(%rip)     # 0x25488
jne 0x9778
callq 0xb08c
testq %rax, %rax
je 0x9778
movl %r13d, %ebx
subl %r14d, %ebx
movl %ebx, %ebx
movq 0x1c010(%rip), %rax     # 0x25480
movq %rax, %rsi
subq %rbx, %rsi
jae 0x9492
subl %eax, %ebx
callq 0xb08c
testq %rax, %rax
jne 0x9467
jmp 0x97ed
movq 0x1bff0(%rip), %rsi     # 0x25480
jmp 0x94c7
movq %rsi, 0x1bfe7(%rip)     # 0x25480
addq %rbx, 0x1bfd8(%rip)     # 0x25478
movq 0x1bfe9(%rip), %rcx     # 0x25490
subq %rsi, %rcx
incl %r13d
movq 0x8(%rsp), %rax
leal 0x1(,%rax,2), %eax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %rcx, %rdx
testq %rsi, %rsi
jne 0x94f4
cmpl $0x0, 0x1bfb5(%rip)     # 0x25488
jne 0x9778
movq %rdx, %rbx
callq 0xb08c
testq %rax, %rax
je 0x9778
movq %rbx, %rdx
movq 0x1bf8c(%rip), %rsi     # 0x25480
decq %rsi
movq %rsi, 0x1bf82(%rip)     # 0x25480
movq 0x1bf73(%rip), %rcx     # 0x25478
leaq 0x1(%rcx), %rax
movq %rax, 0x1bf68(%rip)     # 0x25478
movzbl (%rcx), %ebx
movl %r14d, %ecx
shlq %cl, %rbx
addq %r15, %rbx
leal 0x8(%r14), %edi
cmpl %r13d, %edi
jae 0x9584
testq %rsi, %rsi
jne 0x955d
cmpl $0x0, 0x1bf57(%rip)     # 0x25488
jne 0x97ed
movl %edi, %ebp
movq %rdx, %r15
callq 0xb08c
testq %rax, %rax
je 0x97ed
movq 0x1bf2f(%rip), %rsi     # 0x25480
movq 0x1bf20(%rip), %rax     # 0x25478
movq %r15, %rdx
movl %ebp, %edi
decq %rsi
movq %rsi, 0x1bf19(%rip)     # 0x25480
leaq 0x1(%rax), %rcx
movq %rcx, 0x1bf06(%rip)     # 0x25478
movzbl (%rax), %eax
movl %edi, %ecx
shlq %cl, %rax
addq %rax, %rbx
addl $0x10, %r14d
movl %r14d, %edi
movq 0x8(%rsp), %rax
movl %eax, %r14d
andl %ebx, %r14d
movl %r13d, %ecx
testb %r12b, %r12b
jns 0x961b
cmpl $0x100, %r14d           # imm = 0x100
jne 0x961b
movq 0x1bee5(%rip), %rdi     # 0x25490
addq %rsi, %rdx
movq %rdi, %rax
subq %rdx, %rax
xorl %edx, %edx
divq %rcx
testq %rdx, %rdx
je 0x95fa
subl %edx, %r13d
movl %r13d, %r13d
movq 0x1beb5(%rip), %rax     # 0x25480
movq %rax, %rsi
subq %r13, %rsi
jae 0x95e5
subl %eax, %r13d
callq 0xb08c
testq %rax, %rax
jne 0x95c1
jmp 0x97ed
movq %rsi, 0x1be94(%rip)     # 0x25480
addq %r13, 0x1be85(%rip)     # 0x25478
movq 0x1be96(%rip), %rdi     # 0x25490
subq %rsi, %rdi
movl $0x9, %r13d
movl $0xff, %eax
xorl %r15d, %r15d
movl $0x1ff, %ecx            # imm = 0x1FF
xorl %r14d, %r14d
movq %rdi, %rdx
jmp 0x9405
movl %edi, 0x18(%rsp)
shrq %cl, %rbx
xorl %ebp, %ebp
movl %r14d, %r15d
movq 0x20(%rsp), %rcx
cmpl %ecx, %r14d
leaq 0x23eca(%rip), %rsi     # 0x2d500
movl 0x4(%rsp), %edi
jbe 0x9665
leal 0x1(%rcx), %eax
cmpl %eax, %r14d
movq 0x28(%rsp), %rax
jne 0x9809
cmpl %ecx, %eax
ja 0x9809
movl 0x14(%rsp), %ecx
movb %cl, 0x40(%rsp)
movl $0x1, %ebp
movl %eax, %r15d
movq %rdx, 0x38(%rsp)
cmpl $0x100, %r15d           # imm = 0x100
jb 0x9697
movl %r15d, %eax
movb 0xff50(%rsp,%rax), %cl
movl %ebp, %edx
incl %ebp
movb %cl, 0x40(%rsp,%rdx)
movzwl 0x1ff50(%rsp,%rax,2), %r15d
cmpl $0xff, %r15d
ja 0x9673
movl %ebp, %eax
movb %r15b, 0x40(%rsp,%rax)
movq 0x20(%rsp), %rcx
cmpl 0x8(%rsp), %ecx
jae 0x96c4
movl %ecx, %eax
leaq 0x1(%rax), %rcx
movq 0x28(%rsp), %rdx
movw %dx, 0x1ff52(%rsp,%rax,2)
movb %r15b, 0xff51(%rsp,%rax)
incl %ebp
movl $0x8000, %eax           # imm = 0x8000
subl %edi, %eax
cmpl %eax, %ebp
movq %rcx, 0x20(%rsp)
jbe 0x972d
cmpl $0x7fff, %edi           # imm = 0x7FFF
ja 0x96f8
movl %edi, %eax
decl %ebp
movb 0x40(%rsp,%rbp), %cl
movb %cl, (%rax,%rsi)
incq %rax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x96e0
movl $0x8000, %edi           # imm = 0x8000
movl %edi, %edx
addq %rdx, 0x1bd97(%rip)     # 0x25498
cmpl $0x1, 0x13cd0(%rip)     # 0x1d3d8
jne 0x9723
movl 0x13c54(%rip), %edi     # 0x1d364
leaq 0x23de9(%rip), %rsi     # 0x2d500
callq 0xc0bf
leaq 0x23ddd(%rip), %rsi     # 0x2d500
xorl %edi, %edi
cmpl $0x8000, %ebp           # imm = 0x8000
ja 0x96d6
subl %r13d, 0x18(%rsp)
leal -0x1(%rbp), %eax
addq %rsp, %rax
addq $0x40, %rax
movl %edi, %ecx
movl %edi, %edx
leal 0x1(%rcx), %edi
movb (%rax), %cl
decq %rax
movb %cl, (%rdx,%rsi)
decl %ebp
jne 0x973c
movl %edi, 0x4(%rsp)
movl %r14d, %eax
movq %rax, 0x28(%rsp)
movl %r15d, 0x14(%rsp)
movq 0x38(%rsp), %rdx
movq 0x20(%rsp), %rax
movq 0x8(%rsp), %rcx
movl 0x18(%rsp), %edi
jmp 0x93ff
movl 0x4(%rsp), %eax
movl %eax, %edx
addq %rdx, 0x1bd13(%rip)     # 0x25498
testl %eax, %eax
je 0x97be
cmpl $0x1, 0x13c48(%rip)     # 0x1d3d8
jne 0x97be
movl 0x13bcc(%rip), %edi     # 0x1d364
leaq 0x23d61(%rip), %rsi     # 0x2d500
addq $0x3ff58, %rsp          # imm = 0x3FF58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc0bf
cmpl $0x0, 0x1bccc(%rip)     # 0x25488
je 0x97d0
addq $0x3ff58, %rsp          # imm = 0x3FF58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xb08c
testq %rax, %rax
je 0x97be
movq 0x1bc9f(%rip), %rcx     # 0x25480
movq 0x1bc90(%rip), %rax     # 0x25478
jmp 0x933f
movq 0x13b74(%rip), %rdx     # 0x1d368
leaq 0xcf0c(%rip), %rsi      # 0x16707
movl $0x21, %edi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xe90d
movq 0x13b58(%rip), %rdx     # 0x1d368
leaq 0xcf3a(%rip), %rsi      # 0x16751
jmp 0x97fb
movq 0x13b48(%rip), %rdx     # 0x1d368
leaq 0xcef6(%rip), %rsi      # 0x1671d
jmp 0x97fb
movq 0x13b38(%rip), %rdx     # 0x1d368
leaq 0xcf00(%rip), %rsi      # 0x16737
jmp 0x97fb