// File: /workspace/github_cpp_makefile_star2_O1/sisong[P]ApkDiffPatch/zlib1.3.1/deflate.c
// Function: deflate_stored
local block_state deflate_stored(deflate_state *s, int flush) {
    /* Smallest worthy block size when not flushing or finishing. By default
     * this is 32K. This can be as small as 507 bytes for memLevel == 1. For
     * large input and output buffers, the stored block size will be larger.
     */
    unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);

    /* Copy as many min_block or larger stored blocks directly to next_out as
     * possible. If flushing, copy the remaining available input to next_out as
     * stored blocks, if there is enough space.
     */
    unsigned len, left, have, last = 0;
    unsigned used = s->strm->avail_in;
    do {
        /* Set len to the maximum size block that we can copy directly with the
         * available input data and output space. Set left to how much of that
         * would be copied from what's left in the window.
         */
        len = MAX_STORED;       /* maximum deflate stored block length */
        have = (s->bi_valid + 42) >> 3;         /* number of header bytes */
        if (s->strm->avail_out < have)          /* need room for header */
            break;
            /* maximum stored block length that will fit in avail_out: */
        have = s->strm->avail_out - have;
        left = s->strstart - s->block_start;    /* bytes left in window */
        if (len > (ulg)left + s->strm->avail_in)
            len = left + s->strm->avail_in;     /* limit len to the input */
        if (len > have)
            len = have;                         /* limit len to the output */

        /* If the stored block would be less than min_block in length, or if
         * unable to copy all of the available input when flushing, then try
         * copying to the window and the pending buffer instead. Also don't
         * write an empty block when flushing -- deflate() does that.
         */
        if (len < min_block && ((len == 0 && flush != Z_FINISH) ||
                                flush == Z_NO_FLUSH ||
                                len != left + s->strm->avail_in))
            break;

        /* Make a dummy stored block in pending to get the header bytes,
         * including any pending bits. This also updates the debugging counts.
         */
        last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
        _tr_stored_block(s, (char *)0, 0L, last);

        /* Replace the lengths in the dummy stored block with len. */
        s->pending_buf[s->pending - 4] = len;
        s->pending_buf[s->pending - 3] = len >> 8;
        s->pending_buf[s->pending - 2] = ~len;
        s->pending_buf[s->pending - 1] = ~len >> 8;

        /* Write the stored block header bytes. */
        flush_pending(s->strm);

#ifdef ZLIB_DEBUG
        /* Update debugging counts for the data about to be copied. */
        s->compressed_len += len << 3;
        s->bits_sent += len << 3;
#endif

        /* Copy uncompressed bytes from the window to next_out. */
        if (left) {
            if (left > len)
                left = len;
            zmemcpy(s->strm->next_out, s->window + s->block_start, left);
            s->strm->next_out += left;
            s->strm->avail_out -= left;
            s->strm->total_out += left;
            s->block_start += left;
            len -= left;
        }

        /* Copy uncompressed bytes directly from next_in to next_out, updating
         * the check value.
         */
        if (len) {
            read_buf(s->strm, s->strm->next_out, len);
            s->strm->next_out += len;
            s->strm->avail_out -= len;
            s->strm->total_out += len;
        }
    } while (last == 0);

    /* Update the sliding window with the last s->w_size bytes of the copied
     * data, or append all of the copied data to the existing window if less
     * than s->w_size bytes were copied. Also update the number of bytes to
     * insert in the hash tables, in the event that deflateParams() switches to
     * a non-zero compression level.
     */
    used -= s->strm->avail_in;      /* number of input bytes directly copied */
    if (used) {
        /* If any input was used, then no unused input remains in the window,
         * therefore s->block_start == s->strstart.
         */
        if (used >= s->w_size) {    /* supplant the previous history */
            s->matches = 2;         /* clear hash */
            zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
            s->strstart = s->w_size;
            s->insert = s->strstart;
        }
        else {
            if (s->window_size - s->strstart <= used) {
                /* Slide the window down. */
                s->strstart -= s->w_size;
                zmemcpy(s->window, s->window + s->w_size, s->strstart);
                if (s->matches < 2)
                    s->matches++;   /* add a pending slide_hash() */
                if (s->insert > s->strstart)
                    s->insert = s->strstart;
            }
            zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
            s->strstart += used;
            s->insert += MIN(used, s->w_size - s->insert);
        }
        s->block_start = s->strstart;
    }
    if (s->high_water < s->strstart)
        s->high_water = s->strstart;

    /* If the last block was written to next_out, then done. */
    if (last)
        return finish_done;

    /* If flushing and all input has been consumed, then done. */
    if (flush != Z_NO_FLUSH && flush != Z_FINISH &&
        s->strm->avail_in == 0 && (long)s->strstart == s->block_start)
        return block_done;

    /* Fill the window with any remaining input. */
    have = s->window_size - s->strstart;
    if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) {
        /* Slide the window down. */
        s->block_start -= s->w_size;
        s->strstart -= s->w_size;
        zmemcpy(s->window, s->window + s->w_size, s->strstart);
        if (s->matches < 2)
            s->matches++;           /* add a pending slide_hash() */
        have += s->w_size;          /* more space now */
        if (s->insert > s->strstart)
            s->insert = s->strstart;
    }
    if (have > s->strm->avail_in)
        have = s->strm->avail_in;
    if (have) {
        read_buf(s->strm, s->window + s->strstart, have);
        s->strstart += have;
        s->insert += MIN(have, s->w_size - s->insert);
    }
    if (s->high_water < s->strstart)
        s->high_water = s->strstart;

    /* There was not enough avail_out to write a complete worthy or flushed
     * stored block to next_out. Write a stored block to pending instead, if we
     * have enough input for a worthy block, or if flushing and there is enough
     * room for the remaining input as a stored block in the pending buffer.
     */
    have = (s->bi_valid + 42) >> 3;         /* number of header bytes */
        /* maximum stored block length that will fit in pending: */
    have = MIN(s->pending_buf_size - have, MAX_STORED);
    min_block = MIN(have, s->w_size);
    left = s->strstart - s->block_start;
    if (left >= min_block ||
        ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH &&
         s->strm->avail_in == 0 && left <= have)) {
        len = MIN(left, have);
        last = flush == Z_FINISH && s->strm->avail_in == 0 &&
               len == left ? 1 : 0;
        _tr_stored_block(s, (charf *)s->window + s->block_start, len, last);
        s->block_start += len;
        flush_pending(s->strm);
    }

    /* We've done all we can with the available input and output. */
    return last ? finish_started : need_more;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %r8d
movq %rdi, %r14
movq 0x18(%rdi), %rcx
addq $-0x5, %rcx
movl 0x50(%rdi), %eax
cmpq %rax, %rcx
cmoval %eax, %ecx
movq %rcx, 0x10(%rsp)
movq (%rdi), %rax
movl 0x8(%rax), %eax
movl %eax, 0x4(%rsp)
movl %esi, %eax
xorl $0x4, %eax
movl %eax, 0x8(%rsp)
movl %esi, 0xc(%rsp)
movl 0x1734(%r14), %edx
addl $0x2a, %edx
sarl $0x3, %edx
movq (%r14), %rax
movl 0x20(%rax), %ecx
movb $0x1, %r12b
subl %edx, %ecx
jb 0x4c652
movl 0x98(%r14), %ebp
movl 0xac(%r14), %r13d
movl %r13d, %r15d
subl %ebp, %r15d
movl 0x8(%rax), %edx
leal (%rdx,%r15), %eax
addq %r15, %rdx
cmpq $0xffff, %rdx           # imm = 0xFFFF
movl $0xffff, %ebx           # imm = 0xFFFF
cmovbl %eax, %ebx
cmpl %ecx, %ebx
cmovael %ecx, %ebx
cmpl 0x10(%rsp), %ebx
jae 0x4c588
cmpl $0x4, %r8d
sete %cl
testl %ebx, %ebx
setne %dl
cmpl %eax, %ebx
jne 0x4c652
testl %r8d, %r8d
je 0x4c652
orb %dl, %cl
je 0x4c652
xorl %ebx, %eax
xorl %r12d, %r12d
orl 0x8(%rsp), %eax
sete %r12b
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x518d6
movq 0x10(%r14), %rax
movq 0x28(%r14), %rcx
movb %bl, -0x4(%rax,%rcx)
movq 0x10(%r14), %rax
movq 0x28(%r14), %rcx
movb %bh, -0x3(%rax,%rcx)
movl %ebx, %eax
notl %eax
movq 0x10(%r14), %rcx
movq 0x28(%r14), %rdx
movb %al, -0x2(%rcx,%rdx)
movq 0x10(%r14), %rcx
movq 0x28(%r14), %rdx
movb %ah, -0x1(%rcx,%rdx)
movq (%r14), %rdi
callq 0x4c46a
cmpl %ebp, %r13d
je 0x4c61f
cmpl %ebx, %r15d
cmovael %ebx, %r15d
movq (%r14), %rax
movq 0x60(%r14), %rsi
movq 0x18(%rax), %rdi
addq 0x98(%r14), %rsi
movq %r15, %rdx
callq 0x4290
movq (%r14), %rax
addq %r15, 0x18(%rax)
subl %r15d, 0x20(%rax)
addq %r15, 0x28(%rax)
addq %r15, 0x98(%r14)
subl %r15d, %ebx
testl %ebx, %ebx
je 0x4c641
movq (%r14), %rdi
movq 0x18(%rdi), %rsi
movl %ebx, %edx
callq 0x4d066
movq (%r14), %rax
movl %ebx, %ecx
addq %rcx, 0x18(%rax)
subl %ebx, 0x20(%rax)
addq %rcx, 0x28(%rax)
testb %r12b, %r12b
movl 0xc(%rsp), %r8d
je 0x4c50d
xorl %r12d, %r12d
movq (%r14), %rax
movl 0x4(%rsp), %esi
subl 0x8(%rax), %esi
je 0x4c748
movl 0x50(%r14), %edx
movl %r8d, %ebp
cmpl %edx, %esi
jae 0x4c70b
movq 0x68(%r14), %rcx
movl 0xac(%r14), %eax
subq %rax, %rcx
movl %esi, %r15d
movl %esi, %ebx
cmpq %rbx, %rcx
ja 0x4c6d0
subl %edx, %eax
movl %eax, 0xac(%r14)
movq 0x60(%r14), %rdi
addq %rdi, %rdx
movq %rdx, %rsi
movq %rax, %rdx
callq 0x4290
movl 0x1728(%r14), %eax
cmpl $0x1, %eax
ja 0x4c6b9
incl %eax
movl %eax, 0x1728(%r14)
movl 0xac(%r14), %eax
cmpl %eax, 0x172c(%r14)
jbe 0x4c6d0
movl %eax, 0x172c(%r14)
movl 0xac(%r14), %edi
addq 0x60(%r14), %rdi
movq (%r14), %rax
movq (%rax), %rsi
subq %rbx, %rsi
movq %rbx, %rdx
callq 0x4290
addl %r15d, 0xac(%r14)
movl 0x50(%r14), %eax
movl 0x172c(%r14), %ecx
subl %ecx, %eax
cmpl %eax, %r15d
cmovbl %r15d, %eax
addl %ecx, %eax
jmp 0x4c730
movl $0x2, 0x1728(%r14)
movq 0x60(%r14), %rdi
movq (%rax), %rsi
subq %rdx, %rsi
callq 0x4290
movl 0x50(%r14), %eax
movl %eax, 0xac(%r14)
movl %eax, 0x172c(%r14)
movl 0xac(%r14), %eax
movq %rax, 0x98(%r14)
movl %ebp, %r8d
movl 0xac(%r14), %edx
cmpq %rdx, 0x1738(%r14)
jae 0x4c75f
movq %rdx, 0x1738(%r14)
movl $0x3, %ebx
testb %r12b, %r12b
je 0x4c903
testl $0xfffffffb, %r8d       # imm = 0xFFFFFFFB
je 0x4c791
movq (%r14), %rax
cmpl $0x0, 0x8(%rax)
jne 0x4c791
movl $0x1, %ebx
cmpq %rdx, 0x98(%r14)
je 0x4c903
movl 0x68(%r14), %ebp
subl %edx, %ebp
movq (%r14), %rax
cmpl %ebp, 0x8(%rax)
jbe 0x4c801
movq 0x98(%r14), %rax
movl 0x50(%r14), %esi
subq %rsi, %rax
jl 0x4c801
movl %r8d, %ebx
movq %rax, 0x98(%r14)
subl %esi, %edx
movl %edx, 0xac(%r14)
movq 0x60(%r14), %rdi
addq %rdi, %rsi
callq 0x4290
movl 0x1728(%r14), %eax
cmpl $0x1, %eax
ja 0x4c7e3
incl %eax
movl %eax, 0x1728(%r14)
addl 0x50(%r14), %ebp
movl 0xac(%r14), %eax
cmpl %eax, 0x172c(%r14)
jbe 0x4c7fe
movl %eax, 0x172c(%r14)
movl %ebx, %r8d
movq (%r14), %rdi
movl 0x8(%rdi), %ebx
cmpl %ebx, %ebp
cmovbl %ebp, %ebx
testl %ebx, %ebx
je 0x4c84a
movl 0xac(%r14), %esi
addq 0x60(%r14), %rsi
movl %ebx, %edx
movl %r8d, %ebp
callq 0x4d066
movl %ebp, %r8d
addl %ebx, 0xac(%r14)
movl 0x50(%r14), %eax
movl 0x172c(%r14), %ecx
subl %ecx, %eax
cmpl %eax, %ebx
cmovbl %ebx, %eax
addl %ecx, %eax
movl %eax, 0x172c(%r14)
movl 0xac(%r14), %edx
cmpq %rdx, 0x1738(%r14)
jae 0x4c861
movq %rdx, 0x1738(%r14)
movl 0x1734(%r14), %ecx
addl $0x2a, %ecx
sarl $0x3, %ecx
movq 0x18(%r14), %rax
subq %rcx, %rax
movl $0xffff, %ecx           # imm = 0xFFFF
cmpq %rcx, %rax
cmovaeq %rcx, %rax
movl 0x50(%r14), %edi
cmpl %eax, %edi
cmovael %eax, %edi
movq 0x98(%r14), %rsi
movl %edx, %ecx
subl %esi, %ecx
cmpl %edi, %ecx
jae 0x4c8bf
cmpl %esi, %edx
setne %dl
cmpl $0x4, %r8d
sete %dil
xorl %ebx, %ebx
testl %r8d, %r8d
je 0x4c903
orb %dl, %dil
je 0x4c903
cmpl %eax, %ecx
ja 0x4c903
movq (%r14), %rdx
cmpl $0x0, 0x8(%rdx)
jne 0x4c903
cmpl %eax, %ecx
movl %eax, %edx
cmovbl %ecx, %edx
xorl %ebx, %ebx
cmpl $0x4, %r8d
jne 0x4c8de
movq (%r14), %rdi
cmpl $0x0, 0x8(%rdi)
jne 0x4c8de
xorl %ebx, %ebx
cmpl %eax, %ecx
setbe %bl
addq 0x60(%r14), %rsi
movl %edx, %r15d
movq %r14, %rdi
movq %r15, %rdx
movl %ebx, %ecx
callq 0x518d6
addq %r15, 0x98(%r14)
movq (%r14), %rdi
callq 0x4c46a
addl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq