// File: /workspace/github_c_makefile_star2_O3/Cyan4973[P]FiniteStateEntropy/programs/zlibh.c
// Function: ZLIBH_inflate
int ZLIBH_inflate(unsigned char* dest, const unsigned char* compressed)
{
    const unsigned char *next = (const unsigned char*)compressed;   /* next input */
    unsigned char *put  = (unsigned char*)dest;         /* next output */
    unsigned hold;              /* bit buffer */
    unsigned bits;              /* bits in bit buffer */
    unsigned copy;              /* number of stored or match bytes to copy */
    code here;                  /* current decoding table entry */
    unsigned len;               /* length to copy for repeats, bits to drop */
    int ret;                    /* return code */
    struct inflate_state state;
    static const unsigned short order[19] = /* permutation of code lengths */
    {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
    code const *lcode;
    unsigned lmask;             /* mask for first level of length codes */
    unsigned codebits;          /* code bits, operation, was op */

    state.mode = TYPEDO;      /* skip check */

    /* Clear the input bit accumulator */
    hold = 0;
    bits = 0;
    for (;;)
        switch (state.mode) {
        case TYPEDO:
            NEEDBITS(1);
            switch (BITS(1)) {
            case 0:                             /* dynamic block */
                state.mode = TABLE;
                break;

            case 1:                             /* fixed block */
                fixedtables(&state);
                state.mode = LEN;             /* decode codes */
                break;
            }
            DROPBITS(1);
            break;

        case TABLE:
            NEEDBITS(4);
            state.nlen = 257;
            state.ndist = 0;
            state.ncode = BITS(4) + 4;
            DROPBITS(4);

            state.have = 0;

            while (state.have < state.ncode) {
                NEEDBITS(3);
                state.lens[order[state.have++]] = (unsigned short)BITS(3);
                DROPBITS(3);
            }
            while (state.have < 19)
                state.lens[order[state.have++]] = 0;
            state.next = state.codes;
            state.lencode = (const code *)(state.next);
            state.lenbits = 7;
            ret = inflate_table(CODES, state.lens, 19, &(state.next),
                &(state.lenbits), state.work);
            if (ret) {
                state.mode = BAD;
                break;
            }
            state.have = 0;

            while (state.have < state.nlen) {
                for (;;) {
                    here = state.lencode[BITS(state.lenbits)];
                    if ((unsigned)(here.bits) <= bits) break;
                    PULLBYTE();
                }
                if (here.val < 16) {
                    DROPBITS(here.bits);
                    state.lens[state.have++] = here.val;
                }
                else {
                    if (here.val == 16) {
                        NEEDBITS(here.bits + 2);
                        DROPBITS(here.bits);
                        if (state.have == 0) {
                            state.mode = BAD;
                            break;
                        }
                        len = state.lens[state.have - 1];
                        copy = 3 + BITS(2);
                        DROPBITS(2);
                    }
                    else if (here.val == 17) {
                        NEEDBITS(here.bits + 3);
                        DROPBITS(here.bits);
                        len = 0;
                        copy = 3 + BITS(3);
                        DROPBITS(3);
                    }
                    else {
                        NEEDBITS(here.bits + 7);
                        DROPBITS(here.bits);
                        len = 0;
                        copy = 11 + BITS(7);
                        DROPBITS(7);
                    }
                    if (state.have + copy > state.nlen) {
                        state.mode = BAD;
                        break;
                    }
                    while (copy--)
                        state.lens[state.have++] = (unsigned short)len;
                }
            }

            /* handle error breaks in while */
            if (state.mode == BAD) break;

            /* check for end-of-block code (better have one) */
            if (state.lens[256] == 0) {
                state.mode = BAD;
                break;
            }

            /* build code tables -- note: do not change the lenbits or distbits
            values here (9 and 6) without reading the comments in inftrees.h
            concerning the ENOUGH constants, which depend on those values */
            state.next = state.codes;
            state.lencode = (const code *)(state.next);
            state.lenbits = 9;
            ret = inflate_table(LENS, state.lens, state.nlen, &(state.next),
                &(state.lenbits), state.work);
            if (ret) {
                state.mode = BAD;
                break;
            }
            state.mode = LEN;
            /* fallthrough */

        case LEN:
            lcode = state.lencode;
            lmask = (1U << state.lenbits) - 1;
            do {
                if (bits < 15) {
                    hold += (unsigned long)(*next++) << bits;
                    bits += 8;
                    hold += (unsigned long)(*next++) << bits;
                    bits += 8;
                }
                here = lcode[hold & lmask];
dolen:
                codebits = (unsigned)(here.bits);
                hold >>= codebits;
                bits -= codebits;
                codebits = (unsigned)(here.op);
                if (codebits == 0) {                          /* literal */
                    *put++ = (unsigned char)(here.val);
                }
                else if ((codebits & 64) == 0) {              /* 2nd level length code */
                    here = lcode[here.val + (hold & ((1U << codebits) - 1))];
                    goto dolen;
                }
                else if (codebits & 32) {                     /* end-of-block */
                    //len = bits >> 3;                        /* restitute unused bytes */
                    //next -= len;
                    break;
                }
            } while (1);
            state.mode = DONE;

        case DONE:
            goto inf_leave;
        case BAD:
            return 0;
    }
inf_leave:
    //return (int)(next-compressed);   // compressed size
    return (int)(put-dest);          // original size
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1bf8, %rsp           # imm = 0x1BF8
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
leaq 0x98(%rsp), %rax
movl $0x0, -0x88(%rax)
xorl %ebp, %ebp
leaq 0xcd4f(%rip), %rbx      # 0x13f10
leaq 0xd308(%rip), %r12      # 0x144d0
xorl %r13d, %r13d
xorl %r15d, %r15d
cmpl $0x4, %ebp
ja 0x71ce
movl %ebp, %eax
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
testl %r15d, %r15d
jne 0x71f3
movzbl (%r14), %eax
incq %r14
addl %eax, %r13d
movl $0x8, %r15d
movl $0x1, %ebp
testb $0x1, %r13b
je 0x722a
leaq 0xd3cb(%rip), %rax      # 0x145d0
movq %rax, 0x68(%rsp)
movabsq $0x500000009, %rax      # imm = 0x500000009
movq %rax, 0x78(%rsp)
leaq 0xdbb0(%rip), %rax      # 0x14dd0
movq %rax, 0x70(%rsp)
movl $0x2, %ebp
movl %ebp, 0x10(%rsp)
shrl %r13d
decl %r15d
jmp 0x71ce
cmpl $0x3, %r15d
ja 0x7255
movl %r15d, %eax
movzbl (%r14), %edx
movl %r15d, %ecx
shlq %cl, %rdx
orl $0x8, %eax
incq %r14
addl %edx, %r13d
movl %eax, %r15d
movq $0x101, 0x84(%rsp) # imm = 0x101
movl %r13d, %eax
andl $0xf, %eax
leal 0x4(%rax), %ecx
movl %ecx, 0x80(%rsp)
movl $0x0, 0x8c(%rsp)
addl $-0x4, %r15d
shrl $0x4, %r13d
leaq 0x8(,%rax,2), %rdx
movl $0x1, %esi
xorl %edi, %edi
cmpl $0x2, %r15d
ja 0x72b3
movl %r15d, %r8d
movzbl (%r14), %r9d
movl %r15d, %ecx
shlq %cl, %r9
orl $0x8, %r8d
incq %r14
addl %r9d, %r13d
movl %r8d, %r15d
movl %r13d, %ecx
andl $0x7, %ecx
movl %esi, 0x8c(%rsp)
movzwl (%rdi,%r12), %r8d
movw %cx, 0x98(%rsp,%r8,2)
shrl $0x3, %r13d
addl $-0x3, %r15d
addq $0x2, %rdi
incl %esi
cmpq %rdi, %rdx
jne 0x7293
cmpl $0xf, %eax
je 0x7313
addq $0x5, %rax
movq %rax, %rcx
movzwl -0x2(%r12,%rax,2), %edx
movw $0x0, 0x98(%rsp,%rdx,2)
incq %rcx
cmpl $0x13, %eax
movq %rcx, %rax
jne 0x72ed
movl $0x13, 0x8c(%rsp)
leaq 0x558(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %rax, 0x68(%rsp)
movl $0x7, 0x78(%rsp)
xorl %edi, %edi
leaq 0x98(%rsp), %rsi
movl $0x13, %edx
leaq 0x90(%rsp), %rcx
leaq 0x78(%rsp), %r8
leaq 0x318(%rsp), %r9
callq 0x6d62
testl %eax, %eax
je 0x736f
movl $0x4, 0x10(%rsp)
movl $0x4, %ebp
jmp 0x71ce
movl $0x0, 0x8c(%rsp)
movl 0x84(%rsp), %edx
testl %edx, %edx
je 0x7525
movb 0x78(%rsp), %cl
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
shll %cl, %esi
movq 0x68(%rsp), %rdi
notl %esi
xorl %r8d, %r8d
movl %r13d, %ecx
andl %esi, %ecx
movzbl 0x1(%rdi,%rcx,4), %eax
cmpl %eax, %r15d
jae 0x73d3
movl %r15d, %r15d
movzbl (%r14), %eax
movl %r15d, %ecx
shlq %cl, %rax
incq %r14
addl %eax, %r13d
addq $0x8, %r15
movl %r13d, %ecx
andl %esi, %ecx
movzbl 0x1(%rdi,%rcx,4), %eax
cmpq %rax, %r15
jb 0x73b0
movzwl 0x2(%rdi,%rcx,4), %r9d
cmpl $0xf, %r9d
ja 0x7406
movl %eax, %ecx
shrl %cl, %r13d
subl %eax, %r15d
movl %r8d, %eax
leal 0x1(%r8), %ecx
movl %ecx, 0x8c(%rsp)
movw %r9w, 0x98(%rsp,%rax,2)
movl %ecx, %r8d
jmp 0x751c
cmpl $0x10, %r9d
je 0x745b
cmpl $0x11, %r9d
jne 0x74b2
leal 0x3(%rax), %ecx
cmpl %ecx, %r15d
jae 0x743d
movl %r15d, %r15d
movl %ecx, %r9d
movzbl (%r14), %r10d
movl %r15d, %ecx
shlq %cl, %r10
incq %r14
addl %r10d, %r13d
addq $0x8, %r15
cmpq %r9, %r15
jb 0x7424
movl %eax, %ecx
shrl %cl, %r13d
movl %r13d, %ecx
andl $0x7, %ecx
addl $0x3, %ecx
shrl $0x3, %r13d
subl %eax, %r15d
addl $-0x3, %r15d
jmp 0x74f2
leal 0x2(%rax), %ecx
cmpl %ecx, %r15d
jae 0x7482
movl %r15d, %r15d
movl %ecx, %r9d
movzbl (%r14), %r10d
movl %r15d, %ecx
shlq %cl, %r10
incq %r14
addl %r10d, %r13d
addq $0x8, %r15
cmpq %r9, %r15
jb 0x7469
movl %eax, %ecx
shrl %cl, %r13d
subl %eax, %r15d
testl %r8d, %r8d
je 0x735d
leal -0x1(%r8), %eax
movzwl 0x98(%rsp,%rax,2), %eax
movl %r13d, %ecx
andl $0x3, %ecx
addl $0x3, %ecx
shrl $0x2, %r13d
addl $-0x2, %r15d
jmp 0x74f4
leal 0x7(%rax), %ecx
cmpl %ecx, %r15d
jae 0x74d9
movl %r15d, %r15d
movl %ecx, %r9d
movzbl (%r14), %r10d
movl %r15d, %ecx
shlq %cl, %r10
incq %r14
addl %r10d, %r13d
addq $0x8, %r15
cmpq %r9, %r15
jb 0x74c0
movl %eax, %ecx
shrl %cl, %r13d
movl %r13d, %ecx
andl $0x7f, %ecx
addl $0xb, %ecx
shrl $0x7, %r13d
subl %eax, %r15d
addl $-0x7, %r15d
xorl %eax, %eax
leal (%rcx,%r8), %r9d
cmpl %edx, %r9d
ja 0x735d
movl %r8d, %r9d
incl %r8d
movw %ax, 0x98(%rsp,%r9,2)
decl %ecx
jne 0x7501
movl %r8d, 0x8c(%rsp)
cmpl %edx, %r8d
jb 0x739e
movl $0x4, %ebp
cmpl $0x4, 0x10(%rsp)
je 0x71ce
cmpw $0x0, 0x298(%rsp)
je 0x7588
leaq 0x558(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %rax, 0x68(%rsp)
movl $0x9, 0x78(%rsp)
movl $0x1, %edi
leaq 0x98(%rsp), %rsi
leaq 0x90(%rsp), %rcx
leaq 0x78(%rsp), %r8
leaq 0x318(%rsp), %r9
callq 0x6d62
testl %eax, %eax
je 0x75a9
movl $0x4, 0x10(%rsp)
jmp 0x71ce
xorl %eax, %eax
jmp 0x7647
movq 0x8(%rsp), %r9
movq %r9, %rax
jmp 0x7644
movl $0x2, 0x10(%rsp)
movb 0x78(%rsp), %cl
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
shll %cl, %esi
movq 0x68(%rsp), %rdi
notl %esi
movq 0x8(%rsp), %r9
movq %r9, %rax
cmpl $0xe, %r15d
ja 0x75f8
movzbl (%r14), %edx
movl %r15d, %ecx
shlq %cl, %rdx
addl %edx, %r13d
movzbl 0x1(%r14), %edx
leal 0x8(%r15), %ecx
shlq %cl, %rdx
addq $0x2, %r14
addl %r13d, %edx
orl $0x10, %r15d
movl %edx, %r13d
movl %r13d, %r8d
andl %esi, %r8d
movzbl 0x1(%rdi,%r8,4), %edx
movl %edx, %ecx
shrl %cl, %r13d
movb (%rdi,%r8,4), %cl
movzwl 0x2(%rdi,%r8,4), %r8d
subl %edx, %r15d
testb %cl, %cl
je 0x7637
testb $0x40, %cl
jne 0x763f
movzwl %r8w, %edx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
shll %cl, %r8d
notl %r8d
andl %r13d, %r8d
addl %edx, %r8d
jmp 0x75fe
movb %r8b, (%rax)
incq %rax
jmp 0x75cb
testb $0x20, %cl
je 0x75cb
subl %r9d, %eax
addq $0x1bf8, %rsp           # imm = 0x1BF8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq