// File: /workspace/github_c_makefile_star2_O1/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, %rbx
leaq 0x558(%rsp), %r11
movl $0x0, -0x548(%r11)
xorl %r13d, %r13d
leaq 0xc2d5(%rip), %r12      # 0x12df0
leaq 0xc98e(%rip), %rsi      # 0x134b0
movabsq $0x500000009, %rdi      # imm = 0x500000009
leaq 0xc87d(%rip), %rbp      # 0x133b0
xorl %r15d, %r15d
movl 0x10(%rsp), %ecx
movl %ecx, %eax
cmpl $0x4, %ecx
ja 0x6b3c
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
testl %r15d, %r15d
jne 0x6b5f
movzbl (%r14), %eax
incq %r14
addl %eax, %r13d
movl $0x8, %r15d
movl $0x1, %eax
testb $0x1, %r13b
je 0x6b85
movq %rsi, 0x68(%rsp)
movq %rdi, 0x78(%rsp)
leaq 0xd135(%rip), %rax      # 0x13cb0
movq %rax, 0x70(%rsp)
movl $0x2, %eax
movl %eax, 0x10(%rsp)
shrl %r13d
decl %r15d
jmp 0x6b36
cmpl $0x3, %r15d
ja 0x6bb0
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), %rax
movl $0x1, %edx
xorl %esi, %esi
cmpl $0x2, %r15d
ja 0x6c0d
movl %r15d, %edi
movzbl (%r14), %r8d
movl %r15d, %ecx
shlq %cl, %r8
orl $0x8, %edi
incq %r14
addl %r8d, %r13d
movl %edi, %r15d
movl %r13d, %ecx
andl $0x7, %ecx
movl %edx, 0x8c(%rsp)
movzwl (%rsi,%rbp), %edi
movw %cx, 0x98(%rsp,%rdi,2)
shrl $0x3, %r13d
addl $-0x3, %r15d
addq $0x2, %rsi
incl %edx
cmpq %rsi, %rax
jne 0x6bee
movl 0x8c(%rsp), %eax
cmpq $0x12, %rax
ja 0x6c7e
leaq (,%rax,2), %rcx
addq %rbp, %rcx
incq %rax
movq %rax, %rdx
movzwl (%rcx), %esi
movw $0x0, 0x98(%rsp,%rsi,2)
addq $0x2, %rcx
incq %rdx
cmpl $0x13, %eax
movq %rdx, %rax
jne 0x6c57
movl $0x13, 0x8c(%rsp)
movq %r11, 0x90(%rsp)
movq %r11, 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 0x668a
testl %eax, %eax
je 0x6ce6
movl $0x4, 0x10(%rsp)
leaq 0x558(%rsp), %r11
leaq 0xc7d9(%rip), %rsi      # 0x134b0
movabsq $0x500000009, %rdi      # imm = 0x500000009
jmp 0x6b36
movl $0x0, 0x8c(%rsp)
movl 0x84(%rsp), %edx
testl %edx, %edx
je 0x6ea2
movb 0x78(%rsp), %cl
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
shll %cl, %esi
movq 0x68(%rsp), %rdi
notl %esi
xorl %r8d, %r8d
leaq 0x558(%rsp), %r11
movl %r13d, %ecx
andl %esi, %ecx
movzbl 0x1(%rdi,%rcx,4), %eax
cmpl %eax, %r15d
jae 0x6d52
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 0x6d2f
movzwl 0x2(%rdi,%rcx,4), %r9d
cmpl $0xf, %r9d
ja 0x6d85
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 0x6e97
cmpl $0x10, %r9d
je 0x6dda
cmpl $0x11, %r9d
jne 0x6e31
leal 0x3(%rax), %ecx
cmpl %ecx, %r15d
jae 0x6dbc
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 0x6da3
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 0x6e71
leal 0x2(%rax), %ecx
cmpl %ecx, %r15d
jae 0x6e01
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 0x6de8
movl %eax, %ecx
shrl %cl, %r13d
subl %eax, %r15d
testl %r8d, %r8d
je 0x6eac
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 0x6e73
leal 0x7(%rax), %ecx
cmpl %ecx, %r15d
jae 0x6e58
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 0x6e3f
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 0x6eac
movl %r8d, %r9d
incl %r8d
movw %ax, 0x98(%rsp,%r9,2)
decl %ecx
jne 0x6e7c
movl %r8d, 0x8c(%rsp)
cmpl %edx, %r8d
jb 0x6d1d
jmp 0x6eb4
leaq 0x558(%rsp), %r11
jmp 0x6eb4
movl $0x4, 0x10(%rsp)
cmpl $0x4, 0x10(%rsp)
leaq 0xc5f0(%rip), %rsi      # 0x134b0
movabsq $0x500000009, %rdi      # imm = 0x500000009
je 0x6b36
cmpw $0x0, 0x298(%rsp)
je 0x6f4a
movq %rbx, 0x8(%rsp)
movq %rsi, %rbx
movq %r11, 0x90(%rsp)
movq %r11, 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 0x668a
testl %eax, %eax
je 0x6f66
movl $0x4, 0x10(%rsp)
leaq 0x558(%rsp), %r11
movq %rbx, %rsi
movq 0x8(%rsp), %rbx
movabsq $0x500000009, %rdi      # imm = 0x500000009
jmp 0x6b36
movl $0x4, 0x10(%rsp)
jmp 0x6b36
movq %rbx, %rax
jmp 0x7009
xorl %eax, %eax
jmp 0x700b
movl $0x2, 0x10(%rsp)
movq 0x8(%rsp), %rbx
movb 0x78(%rsp), %cl
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
shll %cl, %esi
movq 0x68(%rsp), %rdi
notl %esi
movq %rbx, %rax
cmpl $0xe, %r15d
ja 0x6fb5
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 0x6ff4
testb $0x40, %cl
jne 0x6ffc
movzwl %r8w, %edx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
shll %cl, %r8d
notl %r8d
andl %r13d, %r8d
addl %edx, %r8d
jmp 0x6fbb
movb %r8b, (%rax)
incq %rax
jmp 0x6f88
testb $0x20, %cl
je 0x6f88
movl $0x3, 0x10(%rsp)
subl %ebx, %eax
addq $0x1bf8, %rsp           # imm = 0x1BF8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq