// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/src/../foreign/miniz-c.h
// Function: tdefl_flush_block
static int tdefl_flush_block(tdefl_compressor *d, int flush)
{
    mz_uint saved_bit_buf, saved_bits_in;
    mz_uint8 *pSaved_output_buf;
    mz_bool comp_block_succeeded = MZ_FALSE;
    int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size;
    mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf;

    d->m_pOutput_buf = pOutput_buf_start;
    d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16;

    MZ_ASSERT(!d->m_output_flush_remaining);
    d->m_output_flush_ofs = 0;
    d->m_output_flush_remaining = 0;

    *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
    d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);

    if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index))
    {
        const mz_uint8 cmf = 0x78;
        mz_uint8 flg, flevel = 3;
        mz_uint header, i, mz_un = sizeof(s_tdefl_num_probes) / sizeof(mz_uint);

        /* Determine compression level by reversing the process in tdefl_create_comp_flags_from_zip_params() */
        for (i = 0; i < mz_un; i++)
            if (s_tdefl_num_probes[i] == (d->m_flags & 0xFFF)) break;

        if (i < 2)
            flevel = 0;
        else if (i < 6)
            flevel = 1;
        else if (i == 6)
            flevel = 2;

        header = cmf << 8 | (flevel << 6);
        header += 31 - (header % 31);
        flg = header & 0xFF;

        TDEFL_PUT_BITS(cmf, 8);
        TDEFL_PUT_BITS(flg, 8);
    }

    TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1);

    pSaved_output_buf = d->m_pOutput_buf;
    saved_bit_buf = d->m_bit_buffer;
    saved_bits_in = d->m_bits_in;

    if (!use_raw_block)
        comp_block_succeeded = tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48));

    /* If the block gets expanded, forget the current contents of the output buffer and send a raw block instead. */
    if (((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) &&
        ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size))
    {
        mz_uint i;
        d->m_pOutput_buf = pSaved_output_buf;
        d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
        TDEFL_PUT_BITS(0, 2);
        if (d->m_bits_in)
        {
            TDEFL_PUT_BITS(0, 8 - d->m_bits_in);
        }
        for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF)
        {
            TDEFL_PUT_BITS(d->m_total_lz_bytes & 0xFFFF, 16);
        }
        for (i = 0; i < d->m_total_lz_bytes; ++i)
        {
            TDEFL_PUT_BITS(d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK], 8);
        }
    }
    /* Check for the extremely unlikely (if not impossible) case of the compressed block not fitting into the output buffer when using dynamic codes. */
    else if (!comp_block_succeeded)
    {
        d->m_pOutput_buf = pSaved_output_buf;
        d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
        tdefl_compress_block(d, MZ_TRUE);
    }

    if (flush)
    {
        if (flush == TDEFL_FINISH)
        {
            if (d->m_bits_in)
            {
                TDEFL_PUT_BITS(0, 8 - d->m_bits_in);
            }
            if (d->m_flags & TDEFL_WRITE_ZLIB_HEADER)
            {
                mz_uint i, a = d->m_adler32;
                for (i = 0; i < 4; i++)
                {
                    TDEFL_PUT_BITS((a >> 24) & 0xFF, 8);
                    a <<= 8;
                }
            }
        }
        else
        {
            mz_uint i, z = 0;
            TDEFL_PUT_BITS(0, 3);
            if (d->m_bits_in)
            {
                TDEFL_PUT_BITS(0, 8 - d->m_bits_in);
            }
            for (i = 2; i; --i, z ^= 0xFFFF)
            {
                TDEFL_PUT_BITS(z & 0xFFFF, 16);
            }
        }
    }

    MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end);

    memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
    memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);

    d->m_pLZ_code_buf = d->m_lz_code_buf + 1;
    d->m_pLZ_flags = d->m_lz_code_buf;
    d->m_num_flags_left = 8;
    d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes;
    d->m_total_lz_bytes = 0;
    d->m_block_index++;

    if ((n = (int)(d->m_pOutput_buf - pOutput_buf_start)) != 0)
    {
        if (d->m_pPut_buf_func)
        {
            *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf;
            if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user))
                return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED);
        }
        else if (pOutput_buf_start == d->m_output_buf)
        {
            int bytes_to_copy = (int)MZ_MIN((size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs));
            memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy);
            d->m_out_buf_ofs += bytes_to_copy;
            if ((n -= bytes_to_copy) != 0)
            {
                d->m_output_flush_ofs = bytes_to_copy;
                d->m_output_flush_remaining = n;
            }
        }
        else
        {
            d->m_out_buf_ofs += n;
        }
    }

    return d->m_output_flush_remaining;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
testb $0x8, 0x12(%rdi)
jne 0x10cecd
xorl %eax, %eax
jmp 0x10ced9
movl 0x24(%rbx), %eax
subl 0x58(%rbx), %eax
cmpl 0x2c(%rbx), %eax
setbe %al
cmpq $0x0, (%rbx)
jne 0x10cf05
movq 0xa0(%rbx), %rcx
movq 0xc0(%rbx), %r15
movq (%rcx), %rcx
subq %r15, %rcx
cmpq $0x14ccc, %rcx          # imm = 0x14CCC
jb 0x10cf05
addq 0x90(%rbx), %r15
jmp 0x10cf0c
leaq 0x392aa(%rbx), %r15
movq %r15, 0x40(%rbx)
leaq 0x14cbc(%r15), %rcx
movq %rcx, 0x48(%rbx)
cmpl $0x0, 0x74(%rbx)
jne 0x10d4ed
movl $0x0, 0x70(%rbx)
movq 0x38(%rbx), %rdx
movzbl (%rdx), %esi
movb 0x50(%rbx), %cl
shrl %cl, %esi
movb %sil, (%rdx)
movl 0x10(%rbx), %ecx
xorl %edx, %edx
cmpl $0x8, 0x50(%rbx)
sete %dl
subq %rdx, 0x30(%rbx)
btl $0xc, %ecx
jae 0x10d053
cmpl $0x0, 0x7c(%rbx)
jne 0x10d053
andl $0xfff, %ecx            # imm = 0xFFF
leaq 0x3fb24(%rip), %rdx     # 0x14ca90
xorl %esi, %esi
cmpl %ecx, (%rdx)
je 0x10cf86
decq %rsi
addq $0x4, %rdx
cmpq $-0xb, %rsi
jne 0x10cf6e
movl $0x78c0, %edx           # imm = 0x78C0
jmp 0x10cfb4
movq %rsi, %rcx
negq %rcx
movl $0x7800, %edx           # imm = 0x7800
cmpq $0x2, %rcx
jb 0x10cfb4
movl $0x7840, %edx           # imm = 0x7840
cmpq $0x6, %rcx
jb 0x10cfb4
xorl %edx, %edx
cmpq $-0x6, %rsi
setne %dl
shll $0x6, %edx
orl $0x7880, %edx           # imm = 0x7880
imull $0x4211, %edx, %edi     # imm = 0x4211
shrl $0x13, %edi
movl %edi, %r8d
shll $0x5, %r8d
movl 0x5c(%rbx), %ecx
movl $0x78, %esi
shll %cl, %esi
subl %r8d, %edi
addl %edx, %edi
orl 0x60(%rbx), %esi
movzwl %di, %edi
movl %esi, 0x60(%rbx)
subl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
jae 0x10d010
movq 0x40(%rbx), %r8
cmpq 0x48(%rbx), %r8
jae 0x10cfff
leaq 0x1(%r8), %rcx
movq %rcx, 0x40(%rbx)
movb %sil, (%r8)
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %esi
shrl $0x8, %esi
movl %esi, 0x60(%rbx)
addl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
cmpl $0x7, %ecx
ja 0x10cfe4
andl $0xc0, %edx
orl %edi, %edx
xorl $0x1f, %edx
shll %cl, %edx
orl %esi, %edx
movl %edx, 0x60(%rbx)
orl $0x8, %ecx
movl %ecx, 0x5c(%rbx)
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
jae 0x10d042
leaq 0x1(%rsi), %rcx
movq %rcx, 0x40(%rbx)
movb %dl, (%rsi)
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %edx
shrl $0x8, %edx
movl %edx, 0x60(%rbx)
addl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
cmpl $0x7, %ecx
ja 0x10d028
xorl %r12d, %r12d
cmpl $0x4, %ebp
sete %r12b
movl 0x5c(%rbx), %r14d
movl %r14d, %ecx
shll %cl, %r12d
orl 0x60(%rbx), %r12d
movl %r12d, 0x60(%rbx)
incl %r14d
movl %r14d, 0x5c(%rbx)
cmpl $0x8, %r14d
jb 0x10d0af
movq 0x40(%rbx), %rcx
cmpq 0x48(%rbx), %rcx
jae 0x10d099
leaq 0x1(%rcx), %rdx
movq %rdx, 0x40(%rbx)
movb %r12b, (%rcx)
movl 0x5c(%rbx), %r14d
movl 0x60(%rbx), %r12d
shrl $0x8, %r12d
movl %r12d, 0x60(%rbx)
addl $-0x8, %r14d
movl %r14d, 0x5c(%rbx)
cmpl $0x7, %r14d
ja 0x10d07c
movq 0x40(%rbx), %r13
movb $0x1, %cl
testb %al, %al
jne 0x10d0f2
movl $0x1, %esi
testb $0x4, 0x12(%rbx)
jne 0x10d0ce
xorl %esi, %esi
cmpl $0x30, 0x54(%rbx)
setb %sil
movq %rbx, %rdi
callq 0x10dddc
testl %eax, %eax
sete %cl
movl 0x54(%rbx), %eax
testq %rax, %rax
je 0x10d0fd
movq 0x40(%rbx), %rdx
subq %r13, %rdx
incq %rdx
cmpq %rax, %rdx
jl 0x10d0fd
movl 0x24(%rbx), %eax
subl 0x58(%rbx), %eax
cmpl 0x2c(%rbx), %eax
jbe 0x10d123
testb %cl, %cl
je 0x10d268
movq %r13, 0x40(%rbx)
movl %r12d, 0x60(%rbx)
movl %r14d, 0x5c(%rbx)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x10dddc
jmp 0x10d268
movq %r13, 0x40(%rbx)
movl %r12d, 0x60(%rbx)
leal 0x2(%r14), %eax
movl %eax, 0x5c(%rbx)
cmpl $0x6, %r14d
jb 0x10d16f
movq 0x40(%rbx), %rcx
cmpq 0x48(%rbx), %rcx
jae 0x10d154
leaq 0x1(%rcx), %rax
movq %rax, 0x40(%rbx)
movb %r12b, (%rcx)
movl 0x5c(%rbx), %eax
movl 0x60(%rbx), %r12d
shrl $0x8, %r12d
movl %r12d, 0x60(%rbx)
addl $-0x8, %eax
movl %eax, 0x5c(%rbx)
cmpl $0x7, %eax
ja 0x10d138
testl %eax, %eax
je 0x10d4e6
movl $0x8, 0x5c(%rbx)
movl $0x8, %ecx
movq 0x40(%rbx), %rax
cmpq 0x48(%rbx), %rax
jae 0x10d197
leaq 0x1(%rax), %rcx
movq %rcx, 0x40(%rbx)
movb %r12b, (%rax)
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %r12d
shrl $0x8, %r12d
movl %r12d, 0x60(%rbx)
addl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
cmpl $0x7, %ecx
ja 0x10d17b
movzwl 0x54(%rbx), %edx
movl $0x2, %eax
movzwl %dx, %edx
shll %cl, %edx
orl %edx, %r12d
movl %r12d, 0x60(%rbx)
addl $0x10, %ecx
movl %ecx, 0x5c(%rbx)
movq 0x40(%rbx), %rdx
cmpq 0x48(%rbx), %rdx
jae 0x10d1e1
leaq 0x1(%rdx), %rcx
movq %rcx, 0x40(%rbx)
movb %r12b, (%rdx)
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %r12d
shrl $0x8, %r12d
movl %r12d, 0x60(%rbx)
addl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
cmpl $0x7, %ecx
ja 0x10d1c5
movl 0x54(%rbx), %esi
movl %esi, %edx
xorl $0xffff, %edx           # imm = 0xFFFF
movl %edx, 0x54(%rbx)
decl %eax
jne 0x10d1b3
cmpl $0xffff, %esi           # imm = 0xFFFF
je 0x10d268
xorl %eax, %eax
movl 0x58(%rbx), %edx
addl %eax, %edx
andl $0x7fff, %edx           # imm = 0x7FFF
movzbl 0xc8(%rbx,%rdx), %edx
shll %cl, %edx
orl %edx, %r12d
movl %r12d, 0x60(%rbx)
addl $0x8, %ecx
movl %ecx, 0x5c(%rbx)
movq 0x40(%rbx), %rdx
cmpq 0x48(%rbx), %rdx
jae 0x10d24e
leaq 0x1(%rdx), %rcx
movq %rcx, 0x40(%rbx)
movb %r12b, (%rdx)
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %r12d
shrl $0x8, %r12d
movl %r12d, 0x60(%rbx)
addl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
cmpl $0x7, %ecx
ja 0x10d232
incl %eax
cmpl 0x54(%rbx), %eax
jb 0x10d210
testl %ebp, %ebp
je 0x10d3e2
movl 0x5c(%rbx), %ecx
cmpl $0x4, %ebp
jne 0x10d2bc
testl %ecx, %ecx
je 0x10d338
movl $0x8, 0x5c(%rbx)
movl 0x60(%rbx), %eax
movl $0x8, %ecx
movq 0x40(%rbx), %rdx
cmpq 0x48(%rbx), %rdx
jae 0x10d2a9
leaq 0x1(%rdx), %rcx
movq %rcx, 0x40(%rbx)
movb %al, (%rdx)
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %eax
shrl $0x8, %eax
movl %eax, 0x60(%rbx)
addl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
cmpl $0x7, %ecx
ja 0x10d28f
jmp 0x10d33a
addl $0x3, %ecx
movl %ecx, 0x5c(%rbx)
movl 0x60(%rbx), %eax
cmpl $0x8, %ecx
jb 0x10d2f5
movq 0x40(%rbx), %rdx
cmpq 0x48(%rbx), %rdx
jae 0x10d2e4
leaq 0x1(%rdx), %rcx
movq %rcx, 0x40(%rbx)
movb %al, (%rdx)
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %eax
shrl $0x8, %eax
movl %eax, 0x60(%rbx)
addl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
cmpl $0x7, %ecx
ja 0x10d2ca
xorl %edx, %edx
testl %ecx, %ecx
je 0x10d396
movl $0x8, 0x5c(%rbx)
movl $0x8, %ecx
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
jae 0x10d325
leaq 0x1(%rsi), %rcx
movq %rcx, 0x40(%rbx)
movb %al, (%rsi)
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %eax
shrl $0x8, %eax
movl %eax, 0x60(%rbx)
addl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
cmpl $0x7, %ecx
ja 0x10d30b
jmp 0x10d398
xorl %ecx, %ecx
testb $0x10, 0x11(%rbx)
je 0x10d3e2
movl 0x20(%rbx), %eax
movl 0x60(%rbx), %esi
xorl %edx, %edx
movl %eax, %edi
shrl $0x18, %edi
shll %cl, %edi
orl %edi, %esi
movl %esi, 0x60(%rbx)
addl $0x8, %ecx
movl %ecx, 0x5c(%rbx)
movq 0x40(%rbx), %rdi
cmpq 0x48(%rbx), %rdi
jae 0x10d379
leaq 0x1(%rdi), %rcx
movq %rcx, 0x40(%rbx)
movb %sil, (%rdi)
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %esi
shrl $0x8, %esi
movl %esi, 0x60(%rbx)
addl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
cmpl $0x7, %ecx
ja 0x10d35e
shll $0x8, %eax
incl %edx
cmpl $0x4, %edx
jne 0x10d34c
jmp 0x10d3e2
xorl %ecx, %ecx
movl $0x2, %esi
movzwl %dx, %edi
shll %cl, %edi
orl %edi, %eax
movl %eax, 0x60(%rbx)
addl $0x10, %ecx
movl %ecx, 0x5c(%rbx)
movq 0x40(%rbx), %rdi
cmpq 0x48(%rbx), %rdi
jae 0x10d3c7
leaq 0x1(%rdi), %rcx
movq %rcx, 0x40(%rbx)
movb %al, (%rdi)
movl 0x5c(%rbx), %ecx
movl 0x60(%rbx), %eax
shrl $0x8, %eax
movl %eax, 0x60(%rbx)
addl $-0x8, %ecx
movl %ecx, 0x5c(%rbx)
cmpl $0x7, %ecx
ja 0x10d3ad
xorl $0xffff, %edx           # imm = 0xFFFF
decl %esi
jne 0x10d39d
movq 0x40(%rbx), %r14
cmpq 0x48(%rbx), %r14
jae 0x10d50c
leaq 0x81ca(%rbx), %rdi
leaq 0x92aa(%rbx), %r12
leaq 0x92ab(%rbx), %r13
movl $0x280, %edx            # imm = 0x280
xorl %esi, %esi
callq 0x18140
movq %r13, 0x30(%rbx)
movq %r12, 0x38(%rbx)
movl 0x54(%rbx), %eax
movq $0x8, 0x50(%rbx)
addl %eax, 0x58(%rbx)
incl 0x7c(%rbx)
subq %r15, %r14
testl %r14d, %r14d
je 0x10d4d4
movq (%rbx), %rax
testq %rax, %rax
je 0x10d47b
movq 0xb0(%rbx), %rcx
subq 0x88(%rbx), %rcx
movq 0x98(%rbx), %rdx
movq %rcx, (%rdx)
leaq 0x392aa(%rbx), %rdi
movq 0x8(%rbx), %rdx
movl %r14d, %esi
callq *%rax
testl %eax, %eax
jne 0x10d4d4
movl $0xffffffff, 0x84(%rbx) # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x10d4d7
leaq 0x392aa(%rbx), %rsi
movslq %r14d, %rax
cmpq %rsi, %r15
je 0x10d493
addq %rax, 0xc0(%rbx)
jmp 0x10d4d4
movq 0xa0(%rbx), %rcx
movq 0xc0(%rbx), %rdi
movq (%rcx), %r12
subq %rdi, %r12
cmpq %r12, %rax
cmovbq %rax, %r12
addq 0x90(%rbx), %rdi
movslq %r12d, %r15
movq %r15, %rdx
callq 0x181e0
addq %r15, 0xc0(%rbx)
subl %r15d, %r14d
je 0x10d4d4
movl %r12d, 0x70(%rbx)
movl %r14d, 0x74(%rbx)
movl 0x74(%rbx), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ecx, %ecx
jmp 0x10d1aa
leaq 0x40232(%rip), %rdi     # 0x14d726
leaq 0x3ffa3(%rip), %rsi     # 0x14d49e
leaq 0x40241(%rip), %rcx     # 0x14d743
movl $0x4f3, %edx            # imm = 0x4F3
callq 0x18120
leaq 0x4027a(%rip), %rdi     # 0x14d78d
leaq 0x3ff84(%rip), %rsi     # 0x14d49e
leaq 0x40222(%rip), %rcx     # 0x14d743
movl $0x55a, %edx            # imm = 0x55A
callq 0x18120