// File: /workspace/github_c_makefile_star2_O1/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 $0x3ff38, %rsp          # imm = 0x3FF38
movq $0x0, 0x1c493(%rip) # 0x25488
cmpq $0x0, 0x1c473(%rip)     # 0x25470
jne 0x901a
cmpl $0x0, 0x1c472(%rip)     # 0x25478
jne 0x94e1
callq 0xadbc
testq %rax, %rax
je 0x94e1
movq 0x1c44f(%rip), %r14     # 0x25470
decq %r14
movq %r14, 0x1c445(%rip)     # 0x25470
movq 0x1c436(%rip), %rax     # 0x25468
leaq 0x1(%rax), %rcx
movq %rcx, 0x1c42b(%rip)     # 0x25468
movzbl (%rax), %r15d
testb $0x60, %r15b
jne 0x950d
movl %r15d, %eax
andl $0x1f, %eax
leal -0x11(%rax), %ecx
cmpl $-0x9, %ecx
jbe 0x951d
cmpl $0x9, %eax
movl $0xa, %ecx
cmovnel %eax, %ecx
movl %ecx, 0x18(%rsp)
movq 0x1c40d(%rip), %r12     # 0x25480
testq %r14, %r14
je 0x94b6
movq 0x1c3e5(%rip), %rax     # 0x25468
decq 0x1c3e6(%rip)           # 0x25470
leaq 0x1(%rax), %rcx
movq %rcx, 0x1c3d3(%rip)     # 0x25468
movb (%rax), %bpl
jne 0x90b5
cmpl $0x0, 0x1c3d7(%rip)     # 0x25478
jne 0x94e1
callq 0xadbc
testq %rax, %rax
je 0x94e1
movzbl %bpl, %edx
decq 0x1c3b0(%rip)           # 0x25470
movq 0x1c3a1(%rip), %rax     # 0x25468
leaq 0x1(%rax), %rcx
movq %rcx, 0x1c396(%rip)     # 0x25468
movzbl (%rax), %ebx
movl %ebx, %eax
shll $0x8, %eax
orl %eax, %edx
andl $0x1ff, %edx            # imm = 0x1FF
cmpl $0x100, %edx            # imm = 0x100
jae 0x94fd
subq %r14, %r12
movl %r15d, 0x1c(%rsp)
movl %r15d, %eax
shrb $0x7, %al
movzbl %al, %eax
addl $0xff, %eax
shrl %ebx
movb %bpl, 0x243e3(%rip)     # 0x2d4f0
movl $0x9, %r13d
movl $0x1, %r15d
movl $0x7, %esi
movl $0x1ff, %edi            # imm = 0x1FF
movq %rdx, 0x8(%rsp)
movl %edx, 0x4(%rsp)
movq %rbx, %rbp
movl %esi, %r14d
cmpl %edi, %eax
movq %rax, 0x10(%rsp)
jb 0x91ed
cmpl 0x18(%rsp), %r13d
jae 0x91ed
movq 0x1c32f(%rip), %rax     # 0x25480
movq 0x1c318(%rip), %rcx     # 0x25470
addq %rcx, %r12
subq %r12, %rax
movl %r13d, %esi
xorl %edx, %edx
divq %rsi
testq %rdx, %rdx
je 0x91d0
movq %rdx, %r14
testq %rcx, %rcx
jne 0x9194
cmpl $0x0, 0x1c2fe(%rip)     # 0x25478
jne 0x947b
movq %rdi, %rbx
callq 0xadbc
movq %rbx, %rdi
testq %rax, %rax
je 0x947b
movq %rdi, %r12
movl %r13d, %ebx
subl %r14d, %ebx
movl %ebx, %ebx
movq 0x1c2ca(%rip), %rax     # 0x25470
movq %rax, %rcx
subq %rbx, %rcx
jae 0x91bf
subl %eax, %ebx
callq 0xadbc
testq %rax, %rax
jne 0x919d
jmp 0x94e1
movq %rcx, 0x1c2aa(%rip)     # 0x25470
addq %rbx, 0x1c29b(%rip)     # 0x25468
movq %r12, %rdi
movq 0x1c2a9(%rip), %r12     # 0x25480
subq 0x1c292(%rip), %r12     # 0x25470
incl %r13d
leal 0x1(,%rdi,2), %edi
xorl %ebp, %ebp
xorl %r14d, %r14d
cmpq $0x0, 0x1c27b(%rip)     # 0x25470
jne 0x9218
cmpl $0x0, 0x1c27a(%rip)     # 0x25478
jne 0x947b
movq %rdi, %rbx
callq 0xadbc
movq %rbx, %rdi
testq %rax, %rax
je 0x947b
movq 0x1c251(%rip), %rax     # 0x25470
decq %rax
movq %rax, 0x1c247(%rip)     # 0x25470
movq 0x1c238(%rip), %rcx     # 0x25468
leaq 0x1(%rcx), %rdx
movq %rdx, 0x1c22d(%rip)     # 0x25468
movzbl (%rcx), %ebx
movl %r14d, %ecx
shlq %cl, %rbx
addq %rbp, %rbx
leal 0x8(%r14), %edx
cmpl %r13d, %edx
jae 0x92a7
testq %rax, %rax
jne 0x927c
cmpl $0x0, 0x1c21c(%rip)     # 0x25478
jne 0x94e1
movl %edx, (%rsp)
movq %rdi, %rbp
callq 0xadbc
movq %rbp, %rdi
movl (%rsp), %edx
testq %rax, %rax
je 0x94e1
decq 0x1c1ed(%rip)           # 0x25470
movq 0x1c1de(%rip), %rax     # 0x25468
leaq 0x1(%rax), %rcx
movq %rcx, 0x1c1d3(%rip)     # 0x25468
movzbl (%rax), %eax
movl %edx, %ecx
shlq %cl, %rax
addq %rax, %rbx
addl $0x10, %r14d
movl %r14d, %edx
movl %edi, %r14d
andl %ebx, %r14d
movl %r13d, %ecx
cmpb $0x0, 0x1c(%rsp)
jns 0x933c
cmpl $0x100, %r14d           # imm = 0x100
jne 0x933c
movq 0x1c1b5(%rip), %rax     # 0x25480
addq 0x1c19e(%rip), %r12     # 0x25470
subq %r12, %rax
xorl %edx, %edx
divq %rcx
testq %rdx, %rdx
je 0x9314
subl %edx, %r13d
movl %r13d, %r13d
movq 0x1c184(%rip), %rax     # 0x25470
movq %rax, %rcx
subq %r13, %rcx
jae 0x9306
subl %eax, %r13d
callq 0xadbc
testq %rax, %rax
jne 0x92e2
jmp 0x94e1
movq %rcx, 0x1c163(%rip)     # 0x25470
addq %r13, 0x1c154(%rip)     # 0x25468
movq 0x1c165(%rip), %r12     # 0x25480
subq 0x1c14e(%rip), %r12     # 0x25470
movl $0x9, %r13d
movl $0xff, %eax
xorl %ebp, %ebp
movl $0x1ff, %edi            # imm = 0x1FF
xorl %r14d, %r14d
jmp 0x9132
movl %edx, (%rsp)
shrq %cl, %rbx
xorl %ebp, %ebp
movl %r14d, %ecx
movq 0x10(%rsp), %rsi
cmpl %esi, %r14d
jbe 0x9379
leal 0x1(%rsi), %eax
cmpl %eax, %r14d
movq 0x8(%rsp), %rax
jne 0x94fd
cmpl %esi, %eax
ja 0x94fd
movl 0x4(%rsp), %ecx
movb %cl, 0x20(%rsp)
movl $0x1, %ebp
movl %eax, %ecx
cmpl $0x100, %ecx            # imm = 0x100
jb 0x93a2
movl %ecx, %eax
movb 0xff30(%rsp,%rax), %cl
movl %ebp, %edx
incl %ebp
movb %cl, 0x20(%rsp,%rdx)
movzwl 0x1ff30(%rsp,%rax,2), %ecx
cmpl $0xff, %ecx
ja 0x9381
movl %ebp, %eax
movb %cl, 0x20(%rsp,%rax)
cmpl %edi, %esi
jae 0x93c2
incl %esi
movq 0x8(%rsp), %rax
movw %ax, 0x1ff30(%rsp,%rsi,2)
movb %cl, 0xff30(%rsp,%rsi)
movl %ecx, 0x4(%rsp)
incl %ebp
movl $0x8000, %eax           # imm = 0x8000
subl %r15d, %eax
cmpl %eax, %ebp
movq %rsi, 0x10(%rsp)
jbe 0x943b
cmpl $0x7fff, %r15d          # imm = 0x7FFF
ja 0x9405
movl %r15d, %eax
leaq 0x24104(%rip), %rdx     # 0x2d4f0
decl %ebp
movb 0x20(%rsp,%rbp), %cl
movb %cl, (%rax,%rdx)
incq %rax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x93ec
movl $0x8000, %r15d          # imm = 0x8000
movl %r15d, %edx
addq %rdx, 0x1c079(%rip)     # 0x25488
cmpl $0x1, 0x13fb2(%rip)     # 0x1d3c8
jne 0x9430
movq %rdi, %r15
movl 0x13f33(%rip), %edi     # 0x1d354
leaq 0x240c8(%rip), %rsi     # 0x2d4f0
callq 0xbcde
movq %r15, %rdi
xorl %r15d, %r15d
cmpl $0x8000, %ebp           # imm = 0x8000
ja 0x93d9
subl %r13d, (%rsp)
leal -0x1(%rbp), %eax
addq %rsp, %rax
addq $0x20, %rax
leaq 0x240a0(%rip), %rsi     # 0x2d4f0
movl %r15d, %ecx
movl %r15d, %edx
leal 0x1(%rcx), %r15d
movb (%rax), %cl
decq %rax
movb %cl, (%rdx,%rsi)
decl %ebp
jne 0x9450
movl %r14d, %eax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movl (%rsp), %esi
jmp 0x912c
movl %r15d, %edx
addq %rdx, 0x1c003(%rip)     # 0x25488
testl %r15d, %r15d
je 0x94bf
cmpl $0x1, 0x13f37(%rip)     # 0x1d3c8
jne 0x94bf
movl 0x13ebb(%rip), %edi     # 0x1d354
leaq 0x24050(%rip), %rsi     # 0x2d4f0
addq $0x3ff38, %rsp          # imm = 0x3FF38
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbcde
cmpl $0x0, 0x1bfbb(%rip)     # 0x25478
je 0x94d1
addq $0x3ff38, %rsp          # imm = 0x3FF38
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xadbc
testq %rax, %rax
jne 0x907c
jmp 0x94bf
movq 0x13e70(%rip), %rdx     # 0x1d358
leaq 0xd218(%rip), %rsi      # 0x16707
movl $0x21, %edi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xe575
movq 0x13e54(%rip), %rdx     # 0x1d358
leaq 0xd246(%rip), %rsi      # 0x16751
jmp 0x94ef
movq 0x13e44(%rip), %rdx     # 0x1d358
leaq 0xd202(%rip), %rsi      # 0x1671d
jmp 0x94ef
movq 0x13e34(%rip), %rdx     # 0x1d358
leaq 0xd20c(%rip), %rsi      # 0x16737
jmp 0x94ef