// File: tomfunkhouser[P]gaps/pkgs/png/deflate.c
// Function: deflateSetDictionary
int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
    z_streamp strm;
    const Bytef *dictionary;
    uInt  dictLength;
{
    deflate_state *s;
    uInt length = dictLength;
    uInt n;
    IPos hash_head = 0;

    if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
        strm->state->wrap == 2 ||
        (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
        return Z_STREAM_ERROR;

    s = strm->state;
    if (s->wrap)
        strm->adler = adler32(strm->adler, dictionary, dictLength);

    if (length < MIN_MATCH) return Z_OK;
    if (length > s->w_size) {
        length = s->w_size;
        dictionary += dictLength - length; /* use the tail of the dictionary */
    }
    zmemcpy(s->window, dictionary, length);
    s->strstart = length;
    s->block_start = (long)length;

    /* Insert all strings in the hash table (except for the last two bytes).
     * s->lookahead stays null, so s->ins_h will be recomputed at the next
     * call of fill_window.
     */
    s->ins_h = s->window[0];
    UPDATE_HASH(s, s->ins_h, s->window[1]);
    for (n = 0; n <= length - MIN_MATCH; n++) {
        INSERT_STRING(s, n, hash_head);
    }
    if (hash_head) hash_head = 0;  /* to make compiler happy */
    return Z_OK;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movl %edx, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x4(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x11569b
movq 0x28(%rsp), %rax
cmpq $0x0, 0x38(%rax)
je 0x11569b
cmpq $0x0, 0x20(%rsp)
je 0x11569b
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
cmpl $0x2, 0x2c(%rax)
je 0x11569b
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
cmpl $0x1, 0x2c(%rax)
jne 0x1156a8
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
cmpl $0x2a, 0x8(%rax)
je 0x1156a8
movl $0xfffffffe, 0x34(%rsp) # imm = 0xFFFFFFFE
jmp 0x115881
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x1156e4
movq 0x28(%rsp), %rax
movq 0x60(%rax), %rdi
movq 0x20(%rsp), %rsi
movl 0x1c(%rsp), %edx
callq 0x131400
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x60(%rax)
cmpl $0x3, 0xc(%rsp)
jae 0x1156f8
movl $0x0, 0x34(%rsp)
jmp 0x115881
movl 0xc(%rsp), %eax
movq 0x10(%rsp), %rcx
cmpl 0x44(%rcx), %eax
jbe 0x115729
movq 0x10(%rsp), %rax
movl 0x44(%rax), %eax
movl %eax, 0xc(%rsp)
movl 0x1c(%rsp), %ecx
subl 0xc(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rdi
movq 0x20(%rsp), %rsi
movl 0xc(%rsp), %eax
movl %eax, %edx
callq 0xf3d0
movl 0xc(%rsp), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x9c(%rax)
movl 0xc(%rsp), %eax
movl %eax, %ecx
movq 0x10(%rsp), %rax
movq %rcx, 0x88(%rax)
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rax
movzbl (%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x70(%rax)
movq 0x10(%rsp), %rax
movl 0x70(%rax), %eax
movq 0x10(%rsp), %rcx
movl 0x80(%rcx), %ecx
shll %cl, %eax
movl %eax, %ecx
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rax
movzbl 0x1(%rax), %eax
xorl %eax, %ecx
movq 0x10(%rsp), %rax
andl 0x7c(%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x70(%rax)
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
subl $0x3, %ecx
cmpl %ecx, %eax
ja 0x11586a
movq 0x10(%rsp), %rax
movl 0x70(%rax), %eax
movq 0x10(%rsp), %rcx
movl 0x80(%rcx), %ecx
shll %cl, %eax
movl %eax, %ecx
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rax
movl 0x8(%rsp), %edx
addl $0x2, %edx
movl %edx, %edx
movzbl (%rax,%rdx), %eax
xorl %eax, %ecx
movq 0x10(%rsp), %rax
andl 0x7c(%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x70(%rax)
movq 0x10(%rsp), %rax
movq 0x68(%rax), %rax
movq 0x10(%rsp), %rcx
movl 0x70(%rcx), %ecx
movw (%rax,%rcx,2), %ax
movq 0x10(%rsp), %rcx
movq 0x60(%rcx), %rcx
movl 0x8(%rsp), %edx
movq 0x10(%rsp), %rsi
andl 0x4c(%rsi), %edx
movl %edx, %edx
movw %ax, (%rcx,%rdx,2)
movzwl %ax, %eax
movl %eax, 0x4(%rsp)
movl 0x8(%rsp), %eax
movw %ax, %dx
movq 0x10(%rsp), %rax
movq 0x68(%rax), %rax
movq 0x10(%rsp), %rcx
movl 0x70(%rcx), %ecx
movw %dx, (%rax,%rcx,2)
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x1157b5
cmpl $0x0, 0x4(%rsp)
je 0x115879
movl $0x0, 0x4(%rsp)
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw (%rax,%rax)