// File: /workspace/github_c_makefile_star2_O2/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 $0x3ff48, %rsp          # imm = 0x3FF48
andq $0x0, 0x1b1fd(%rip)     # 0x24488
movq 0x1b1de(%rip), %rbx     # 0x24470
testq %rbx, %rbx
jne 0x92b9
cmpl $0x0, 0x1b1da(%rip)     # 0x24478
jne 0x97bc
callq 0xb020
testq %rax, %rax
je 0x97bc
movq 0x1b1b7(%rip), %rbx     # 0x24470
decq %rbx
movq %rbx, 0x1b1ad(%rip)     # 0x24470
movq 0x1b19e(%rip), %rcx     # 0x24468
leaq 0x1(%rcx), %rax
movq %rax, 0x1b193(%rip)     # 0x24468
movzbl (%rcx), %r15d
testb $0x60, %r15b
jne 0x97e6
movl %r15d, %ecx
andl $0x1f, %ecx
leal -0x11(%rcx), %edx
cmpl $-0x9, %edx
jbe 0x97f6
cmpl $0x9, %ecx
pushq $0xa
popq %rdx
cmovnel %ecx, %edx
movl %edx, 0x24(%rsp)
movq 0x1b177(%rip), %r12     # 0x24480
movq %rbx, %rcx
testq %rbx, %rbx
je 0x9784
leaq 0x1(%rax), %rdx
decq %rcx
movq %rcx, 0x1b14d(%rip)     # 0x24470
movq %rdx, 0x1b13e(%rip)     # 0x24468
movb (%rax), %r14b
jne 0x9358
cmpl $0x0, 0x1b142(%rip)     # 0x24478
jne 0x97bc
callq 0xb020
testq %rax, %rax
je 0x97bc
movq 0x1b11f(%rip), %rcx     # 0x24470
movq 0x1b110(%rip), %rdx     # 0x24468
movzbl %r14b, %edi
decq %rcx
movq %rcx, 0x1b10a(%rip)     # 0x24470
leaq 0x1(%rdx), %rax
movq %rax, 0x1b0f7(%rip)     # 0x24468
movzbl (%rdx), %ebp
movl %ebp, %eax
shll $0x8, %eax
orl %eax, %edi
andl $0x1ff, %edi            # imm = 0x1FF
cmpl $0x100, %edi            # imm = 0x100
jae 0x97d6
movq %r12, %rdx
subq %rbx, %rdx
movl %r15d, 0xc(%rsp)
movl %r15d, %eax
shrb $0x7, %al
movzbl %al, %esi
addl $0xff, %esi
shrl %ebp
movb %r14b, 0x23140(%rip)    # 0x2c4f0
pushq $0x9
popq %rax
pushq $0x1
popq %r13
pushq $0x7
popq %r8
movl $0x1ff, %ecx            # imm = 0x1FF
movq %rcx, 0x10(%rsp)
leaq 0x23124(%rip), %rbx     # 0x2c4f0
movl %edi, 0x8(%rsp)
movl %r13d, 0x4(%rsp)
movq %rsi, %r13
movl %eax, %r12d
movq %rdi, 0x28(%rsp)
movq %rbp, %r15
movl %r8d, %r14d
movq 0x10(%rsp), %rbp
cmpl %ebp, %r13d
jb 0x9468
cmpl 0x24(%rsp), %r12d
jae 0x9468
movq 0x1b082(%rip), %rcx     # 0x24480
movq 0x1b06b(%rip), %rsi     # 0x24470
addq %rsi, %rdx
movq %rcx, %rax
subq %rdx, %rax
movl %r12d, %edi
xorl %edx, %edx
divq %rdi
testq %rdx, %rdx
je 0x9486
movq %rdx, %r14
testq %rsi, %rsi
jne 0x943e
cmpl $0x0, 0x1b04e(%rip)     # 0x24478
jne 0x9747
callq 0xb020
testq %rax, %rax
je 0x9747
movl %r12d, %r15d
subl %r14d, %r15d
movl %r15d, %r15d
movq 0x1b022(%rip), %rax     # 0x24470
movq %rax, %rsi
subq %r15, %rsi
jae 0x9471
subl %eax, %r15d
callq 0xb020
testq %rax, %rax
jne 0x9444
jmp 0x97bc
movq 0x1b001(%rip), %rsi     # 0x24470
jmp 0x949c
movq %rsi, 0x1aff8(%rip)     # 0x24470
addq %r15, 0x1afe9(%rip)     # 0x24468
movq 0x1affa(%rip), %rcx     # 0x24480
subq %rsi, %rcx
incl %r12d
leal 0x1(,%rbp,2), %ebp
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %rcx, %rdx
testq %rsi, %rsi
movq %rbp, 0x10(%rsp)
jne 0x94d4
cmpl $0x0, 0x1afcb(%rip)     # 0x24478
jne 0x9747
movq %r13, %rbp
movq %rdx, %r13
callq 0xb020
testq %rax, %rax
je 0x9747
movq %r13, %rdx
movq %rbp, %r13
movq 0x1af9c(%rip), %rsi     # 0x24470
decq %rsi
movq %rsi, 0x1af92(%rip)     # 0x24470
movq 0x1af83(%rip), %rcx     # 0x24468
leaq 0x1(%rcx), %rax
movq %rax, 0x1af78(%rip)     # 0x24468
movzbl (%rcx), %ebp
movl %r14d, %ecx
shlq %cl, %rbp
addq %r15, %rbp
leal 0x8(%r14), %r8d
cmpl %r12d, %r8d
jae 0x957c
testq %rsi, %rsi
movl 0xc(%rsp), %r15d
jne 0x9552
movl %r8d, 0x20(%rsp)
movq %r13, 0x18(%rsp)
cmpl $0x0, 0x1af58(%rip)     # 0x24478
jne 0x97bc
movq %rdx, %r13
callq 0xb020
testq %rax, %rax
je 0x97bc
movq 0x1af32(%rip), %rsi     # 0x24470
movq 0x1af23(%rip), %rax     # 0x24468
movq %r13, %rdx
movq 0x18(%rsp), %r13
movl 0x20(%rsp), %r8d
decq %rsi
movq %rsi, 0x1af14(%rip)     # 0x24470
leaq 0x1(%rax), %rcx
movq %rcx, 0x1af01(%rip)     # 0x24468
movzbl (%rax), %eax
movl %r8d, %ecx
shlq %cl, %rax
addq %rax, %rbp
addl $0x10, %r14d
movl %r14d, %r8d
jmp 0x9581
movl 0xc(%rsp), %r15d
movq 0x10(%rsp), %rax
movl %eax, %r14d
andl %ebp, %r14d
movl %r12d, %ecx
testb %r15b, %r15b
jns 0x9619
cmpl $0x100, %r14d           # imm = 0x100
jne 0x9619
movq 0x1aed8(%rip), %rdi     # 0x24480
addq %rsi, %rdx
movq %rdi, %rax
subq %rdx, %rax
xorl %edx, %edx
divq %rcx
testq %rdx, %rdx
je 0x95f7
subl %edx, %r12d
movl %r12d, %r12d
movq 0x1aea8(%rip), %rax     # 0x24470
movq %rax, %rsi
subq %r12, %rsi
jae 0x95e2
subl %eax, %r12d
callq 0xb020
testq %rax, %rax
jne 0x95be
jmp 0x97bc
movq %rsi, 0x1ae87(%rip)     # 0x24470
addq %r12, 0x1ae78(%rip)     # 0x24468
movq 0x1ae89(%rip), %rdi     # 0x24480
subq %rsi, %rdi
movl $0xff, %r13d
xorl %r15d, %r15d
movl $0x1ff, %ebp            # imm = 0x1FF
xorl %r14d, %r14d
movq %rdi, %rdx
pushq $0x9
popq %rax
movl %eax, %r12d
jmp 0x93eb
shrq %cl, %rbp
xorl %r15d, %r15d
movl %r14d, %eax
cmpl %r13d, %r14d
movl 0x4(%rsp), %esi
jbe 0x9656
leal 0x1(%r13), %eax
cmpl %eax, %r14d
movq 0x28(%rsp), %rcx
jne 0x97d6
cmpl %r13d, %ecx
ja 0x97d6
movl 0x8(%rsp), %eax
movb %al, 0x30(%rsp)
movl %ecx, %eax
pushq $0x1
popq %rcx
movl %ecx, %r15d
movq %rdx, 0x18(%rsp)
subl %r12d, %r8d
movl %eax, %ecx
movl %r15d, %eax
cmpl $0x100, %ecx            # imm = 0x100
jb 0x9685
movl %ecx, %ecx
movb 0xff40(%rsp,%rcx), %dl
incl %r15d
movb %dl, 0x30(%rsp,%rax)
movzwl 0x1ff40(%rsp,%rcx,2), %ecx
jmp 0x9660
movb %cl, 0x30(%rsp,%rax)
cmpl 0x10(%rsp), %r13d
jae 0x96ab
movl %r13d, %eax
leaq 0x1(%rax), %r13
movq 0x28(%rsp), %rdx
movw %dx, 0x1ff42(%rsp,%rax,2)
movb %cl, 0xff41(%rsp,%rax)
incl %r15d
movl %ecx, 0x8(%rsp)
movl $0x8000, %eax           # imm = 0x8000
subl %esi, %eax
cmpl %eax, %r15d
jbe 0x9717
movl %esi, %eax
cmpq $0x7fff, %rax           # imm = 0x7FFF
ja 0x96d8
decl %r15d
movb 0x30(%rsp,%r15), %cl
movb %cl, (%rax,%rbx)
incq %rax
jmp 0x96c0
movl %eax, %edx
addq %rdx, 0x1ada7(%rip)     # 0x24488
xorl %esi, %esi
cmpl $0x1, 0x12cde(%rip)     # 0x1c3c8
jne 0x96b2
movl 0x12c62(%rip), %edi     # 0x1c354
movq %rbx, %rsi
movq %rbp, %rbx
movq %r13, %rbp
movl %r8d, %r13d
callq 0xb58d
movl %r13d, %r8d
movq %rbp, %r13
movq %rbx, %rbp
leaq 0x22ddd(%rip), %rbx     # 0x2c4f0
xorl %esi, %esi
jmp 0x96b2
leal -0x1(%r15), %eax
addq %rsp, %rax
addq $0x30, %rax
movl %esi, %ecx
movl %esi, %edx
leal 0x1(%rcx), %esi
movb (%rax), %cl
decq %rax
movb %cl, (%rdx,%rbx)
decl %r15d
jne 0x9722
movl %esi, 0x4(%rsp)
movl %r14d, %edi
movq 0x18(%rsp), %rdx
jmp 0x93db
movl 0x4(%rsp), %eax
movl %eax, %edx
addq %rdx, 0x1ad34(%rip)     # 0x24488
testl %eax, %eax
je 0x978d
cmpl $0x1, 0x12c69(%rip)     # 0x1c3c8
jne 0x978d
movl 0x12bed(%rip), %edi     # 0x1c354
leaq 0x22d82(%rip), %rsi     # 0x2c4f0
addq $0x3ff48, %rsp          # imm = 0x3FF48
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb58d
cmpl $0x0, 0x1aced(%rip)     # 0x24478
je 0x979f
addq $0x3ff48, %rsp          # imm = 0x3FF48
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xb020
testq %rax, %rax
je 0x978d
movq 0x1acc0(%rip), %rcx     # 0x24470
movq 0x1acb1(%rip), %rax     # 0x24468
jmp 0x9315
movq 0x12b95(%rip), %rdx     # 0x1c358
leaq 0xbf45(%rip), %rsi      # 0x1570f
pushq $0x21
popq %rdi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xdd45
movq 0x12b7b(%rip), %rdx     # 0x1c358
leaq 0xbf75(%rip), %rsi      # 0x15759
jmp 0x97ca
movq 0x12b6b(%rip), %rdx     # 0x1c358
leaq 0xbf31(%rip), %rsi      # 0x15725
jmp 0x97ca
movq 0x12b5b(%rip), %rdx     # 0x1c358
leaq 0xbf3b(%rip), %rsi      # 0x1573f
jmp 0x97ca