// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/deflate.c
// Function: deflateCopy
int ZEXPORT deflateCopy (dest, source)
    z_streamp dest;
    z_streamp source;
{
#ifdef MAXSEG_64K
    return Z_STREAM_ERROR;
#else
    deflate_state *ds;
    deflate_state *ss;
    ushf *overlay;


    if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
        return Z_STREAM_ERROR;
    }

    ss = source->state;

    zmemcpy(dest, source, sizeof(z_stream));

    ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
    if (ds == Z_NULL) return Z_MEM_ERROR;
    dest->state = (struct internal_state FAR *) ds;
    zmemcpy(ds, ss, sizeof(deflate_state));
    ds->strm = dest;

    ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
    ds->prev   = (Posf *)  ZALLOC(dest, ds->w_size, sizeof(Pos));
    ds->head   = (Posf *)  ZALLOC(dest, ds->hash_size, sizeof(Pos));
    overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
    ds->pending_buf = (uchf *) overlay;

    if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
        ds->pending_buf == Z_NULL) {
        deflateEnd (dest);
        return Z_MEM_ERROR;
    }
    /* following zmemcpy do not work for 16-bit MSDOS */
    zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
    zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
    zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
    zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);

    ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
    ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
    ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;

    ds->l_desc.dyn_tree = ds->dyn_ltree;
    ds->d_desc.dyn_tree = ds->dyn_dtree;
    ds->bl_desc.dyn_tree = ds->bl_tree;

    return Z_OK;
#endif /* MAXSEG_64K */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rsi, %rsi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
pushq $-0x2
popq %rbp
jne 0x8669d
movq 0x38(%rsi), %r14
testq %r14, %r14
je 0x8669d
movq %rdi, %r15
pushq $0xe
popq %rcx
rep  movsq (%rsi), %es:(%rdi)
movq 0x50(%r15), %rdi
pushq $0x1
popq %rsi
movl $0x1730, %edx           # imm = 0x1730
callq *0x40(%r15)
pushq $-0x4
popq %rbp
testq %rax, %rax
je 0x8669d
movq %rax, %rbx
movq %rax, 0x38(%r15)
movl $0x1730, %edx           # imm = 0x1730
movq %rax, %rdi
movq %r14, %rsi
callq 0xe380
movq %r15, (%rbx)
movq 0x50(%r15), %rdi
movl 0x44(%rbx), %esi
pushq $0x2
popq %r12
movl %r12d, %edx
callq *0x40(%r15)
movq %rax, 0x50(%rbx)
movq 0x50(%r15), %rdi
movl 0x44(%rbx), %esi
movl %r12d, %edx
callq *0x40(%r15)
movq %rax, 0x60(%rbx)
movq 0x50(%r15), %rdi
movl 0x74(%rbx), %esi
movl %r12d, %edx
callq *0x40(%r15)
movq %rax, 0x68(%rbx)
movq 0x50(%r15), %rdi
movl 0x16f8(%rbx), %esi
pushq $0x4
popq %rdx
callq *0x40(%r15)
movq %rax, 0x10(%rbx)
movq 0x50(%rbx), %rdi
testq %rdi, %rdi
je 0x86695
cmpq $0x0, 0x60(%rbx)
je 0x86695
movq %rax, %r12
cmpq $0x0, 0x68(%rbx)
sete %al
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x866a8
movq %r15, %rdi
callq 0x852ab
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%r14), %rsi
movl 0x44(%rbx), %edx
addl %edx, %edx
callq 0xe380
movq 0x60(%rbx), %rdi
movq 0x60(%r14), %rsi
movl 0x44(%rbx), %edx
addq %rdx, %rdx
callq 0xe380
movq 0x68(%rbx), %rdi
movq 0x68(%r14), %rsi
movl 0x74(%rbx), %edx
addq %rdx, %rdx
callq 0xe380
movq 0x10(%rbx), %rdi
movq 0x10(%r14), %rsi
movl 0x18(%rbx), %edx
callq 0xe380
movq 0x10(%rbx), %rax
movq 0x20(%r14), %rcx
subq 0x10(%r14), %rcx
addq %rax, %rcx
movq %rcx, 0x20(%rbx)
movl 0x16f8(%rbx), %ecx
leaq (%rcx,%rcx,2), %rdx
andl $-0x2, %ecx
addq %rcx, %r12
movq %r12, 0x1700(%rbx)
addq %rax, %rdx
movq %rdx, 0x16f0(%rbx)
leaq 0xc4(%rbx), %rax
movq %rax, 0xb48(%rbx)
leaq 0x9b8(%rbx), %rax
movq %rax, 0xb60(%rbx)
movq %rbx, %rax
addq $0xaac, %rax            # imm = 0xAAC
movq %rax, 0xb78(%rbx)
xorl %ebp, %ebp
jmp 0x8669d