// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/zlib-1.3.0.1/deflate.c
// Function: deflateInit2_
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
                          int windowBits, int memLevel, int strategy,
                          const char *version, int stream_size) {
    deflate_state *s;
    int wrap = 1;
    static const char my_version[] = ZLIB_VERSION;

    if (version == Z_NULL || version[0] != my_version[0] ||
        stream_size != sizeof(z_stream)) {
        return Z_VERSION_ERROR;
    }
    if (strm == Z_NULL) return Z_STREAM_ERROR;

    strm->msg = Z_NULL;
    if (strm->zalloc == (alloc_func)0) {
#ifdef Z_SOLO
        return Z_STREAM_ERROR;
#else
        strm->zalloc = zcalloc;
        strm->opaque = (voidpf)0;
#endif
    }
    if (strm->zfree == (free_func)0)
#ifdef Z_SOLO
        return Z_STREAM_ERROR;
#else
        strm->zfree = zcfree;
#endif

#ifdef FASTEST
    if (level != 0) level = 1;
#else
    if (level == Z_DEFAULT_COMPRESSION) level = 6;
#endif

    if (windowBits < 0) { /* suppress zlib wrapper */
        wrap = 0;
        if (windowBits < -15)
            return Z_STREAM_ERROR;
        windowBits = -windowBits;
    }
#ifdef GZIP
    else if (windowBits > 15) {
        wrap = 2;       /* write gzip wrapper instead */
        windowBits -= 16;
    }
#endif
    if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
        windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
        strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) {
        return Z_STREAM_ERROR;
    }
    if (windowBits == 8) windowBits = 9;  /* until 256-byte window bug fixed */
    s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
    if (s == Z_NULL) return Z_MEM_ERROR;
    strm->state = (struct internal_state FAR *)s;
    s->strm = strm;
    s->status = INIT_STATE;     /* to pass state test in deflateReset() */

    s->wrap = wrap;
    s->gzhead = Z_NULL;
    s->w_bits = (uInt)windowBits;
    s->w_size = 1 << s->w_bits;
    s->w_mask = s->w_size - 1;

    s->hash_bits = (uInt)memLevel + 7;
    s->hash_size = 1 << s->hash_bits;
    s->hash_mask = s->hash_size - 1;
    s->hash_shift =  ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH);

    s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
    s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));
    s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));

    s->high_water = 0;      /* nothing written to s->window yet */

    s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */

    /* We overlay pending_buf and sym_buf. This works since the average size
     * for length/distance pairs over any compressed block is assured to be 31
     * bits or less.
     *
     * Analysis: The longest fixed codes are a length code of 8 bits plus 5
     * extra bits, for lengths 131 to 257. The longest fixed distance codes are
     * 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
     * possible fixed-codes length/distance pair is then 31 bits total.
     *
     * sym_buf starts one-fourth of the way into pending_buf. So there are
     * three bytes in sym_buf for every four bytes in pending_buf. Each symbol
     * in sym_buf is three bytes -- two for the distance and one for the
     * literal/length. As each symbol is consumed, the pointer to the next
     * sym_buf value to read moves forward three bytes. From that symbol, up to
     * 31 bits are written to pending_buf. The closest the written pending_buf
     * bits gets to the next sym_buf symbol to read is just before the last
     * code is written. At that time, 31*(n - 2) bits have been written, just
     * after 24*(n - 2) bits have been consumed from sym_buf. sym_buf starts at
     * 8*n bits into pending_buf. (Note that the symbol buffer fills when n - 1
     * symbols are written.) The closest the writing gets to what is unread is
     * then n + 14 bits. Here n is lit_bufsize, which is 16384 by default, and
     * can range from 128 to 32768.
     *
     * Therefore, at a minimum, there are 142 bits of space between what is
     * written and what is read in the overlain buffers, so the symbols cannot
     * be overwritten by the compressed data. That space is actually 139 bits,
     * due to the three-bit fixed-code block header.
     *
     * That covers the case where either Z_FIXED is specified, forcing fixed
     * codes, or when the use of fixed codes is chosen, because that choice
     * results in a smaller compressed block than dynamic codes. That latter
     * condition then assures that the above analysis also covers all dynamic
     * blocks. A dynamic-code block will only be chosen to be emitted if it has
     * fewer bits than a fixed-code block would for the same set of symbols.
     * Therefore its average symbol length is assured to be less than 31. So
     * the compressed data for a dynamic block also cannot overwrite the
     * symbols from which it is being constructed.
     */

#ifdef LIT_MEM
    s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 5);
#else
    s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4);
#endif
    s->pending_buf_size = (ulg)s->lit_bufsize * 4;

    if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
        s->pending_buf == Z_NULL) {
        s->status = FINISH_STATE;
        strm->msg = ERR_MSG(Z_MEM_ERROR);
        deflateEnd (strm);
        return Z_MEM_ERROR;
    }
#ifdef LIT_MEM
    s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1));
    s->l_buf = s->pending_buf + (s->lit_bufsize << 2);
    s->sym_end = s->lit_bufsize - 1;
#else
    s->sym_buf = s->pending_buf + s->lit_bufsize;
    s->sym_end = (s->lit_bufsize - 1) * 3;
#endif
    /* We avoid equality with lit_bufsize*3 because of wraparound at 64K
     * on 16 bit machines and because stored blocks are restricted to
     * 64K-1 bytes.
     */

    s->level = level;
    s->strategy = strategy;
    s->method = (Byte)method;

    return deflateReset(strm);
}

// Assembly:
subq $0x38, %rsp
movl 0x48(%rsp), %eax
movq 0x40(%rsp), %rax
movq %rdi, 0x28(%rsp)
movl %esi, 0x24(%rsp)
movl %edx, 0x20(%rsp)
movl %ecx, 0x1c(%rsp)
movl %r8d, 0x18(%rsp)
movl %r9d, 0x14(%rsp)
movl $0x1, 0x4(%rsp)
cmpq $0x0, 0x40(%rsp)
je 0xcffb6
movq 0x40(%rsp), %rax
movsbl (%rax), %eax
movsbl 0xa63ff(%rip), %ecx     # 0x1763a6
cmpl %ecx, %eax
jne 0xcffb6
movslq 0x48(%rsp), %rax
cmpq $0x70, %rax
je 0xcffc3
movl $0xfffffffa, 0x34(%rsp) # imm = 0xFFFFFFFA
jmp 0xd03ea
cmpq $0x0, 0x28(%rsp)
jne 0xcffd8
movl $0xfffffffe, 0x34(%rsp) # imm = 0xFFFFFFFE
jmp 0xd03ea
movq 0x28(%rsp), %rax
movq $0x0, 0x30(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x40(%rax)
jne 0xd000e
movq 0x28(%rsp), %rax
leaq 0x9be3(%rip), %rcx      # 0xd9be0
movq %rcx, 0x40(%rax)
movq 0x28(%rsp), %rax
movq $0x0, 0x50(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x48(%rax)
jne 0xd002a
movq 0x28(%rsp), %rax
leaq 0x9bea(%rip), %rcx      # 0xd9c10
movq %rcx, 0x48(%rax)
cmpl $-0x1, 0x24(%rsp)
jne 0xd0039
movl $0x6, 0x24(%rsp)
cmpl $0x0, 0x1c(%rsp)
jge 0xd0068
movl $0x0, 0x4(%rsp)
cmpl $-0xf, 0x1c(%rsp)
jge 0xd005c
movl $0xfffffffe, 0x34(%rsp) # imm = 0xFFFFFFFE
jmp 0xd03ea
xorl %eax, %eax
subl 0x1c(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0xd0084
cmpl $0xf, 0x1c(%rsp)
jle 0xd0082
movl $0x2, 0x4(%rsp)
movl 0x1c(%rsp), %eax
subl $0x10, %eax
movl %eax, 0x1c(%rsp)
jmp 0xd0084
cmpl $0x1, 0x18(%rsp)
jl 0xd00d1
cmpl $0x9, 0x18(%rsp)
jg 0xd00d1
cmpl $0x8, 0x20(%rsp)
jne 0xd00d1
cmpl $0x8, 0x1c(%rsp)
jl 0xd00d1
cmpl $0xf, 0x1c(%rsp)
jg 0xd00d1
cmpl $0x0, 0x24(%rsp)
jl 0xd00d1
cmpl $0x9, 0x24(%rsp)
jg 0xd00d1
cmpl $0x0, 0x14(%rsp)
jl 0xd00d1
cmpl $0x4, 0x14(%rsp)
jg 0xd00d1
cmpl $0x8, 0x1c(%rsp)
jne 0xd00de
cmpl $0x1, 0x4(%rsp)
je 0xd00de
movl $0xfffffffe, 0x34(%rsp) # imm = 0xFFFFFFFE
jmp 0xd03ea
cmpl $0x8, 0x1c(%rsp)
jne 0xd00ed
movl $0x9, 0x1c(%rsp)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x28(%rsp), %rcx
movq 0x50(%rcx), %rdi
movl $0x1, %esi
movl $0x1740, %edx           # imm = 0x1740
callq *%rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0xd0125
movl $0xfffffffc, 0x34(%rsp) # imm = 0xFFFFFFFC
jmp 0xd03ea
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x28(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, (%rax)
movq 0x8(%rsp), %rax
movl $0x2a, 0x8(%rax)
movl 0x4(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x30(%rax)
movq 0x8(%rsp), %rax
movq $0x0, 0x38(%rax)
movl 0x1c(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x54(%rax)
movq 0x8(%rsp), %rax
movl 0x54(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x50(%rax)
movq 0x8(%rsp), %rax
movl 0x50(%rax), %ecx
subl $0x1, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x58(%rax)
movl 0x18(%rsp), %ecx
addl $0x7, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x88(%rax)
movq 0x8(%rsp), %rax
movl 0x88(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x84(%rax)
movq 0x8(%rsp), %rax
movl 0x84(%rax), %ecx
subl $0x1, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x8c(%rax)
movq 0x8(%rsp), %rax
movl 0x88(%rax), %eax
addl $0x3, %eax
subl $0x1, %eax
movl $0x3, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x90(%rax)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x28(%rsp), %rcx
movq 0x50(%rcx), %rdi
movq 0x8(%rsp), %rcx
movl 0x50(%rcx), %esi
movl $0x2, %edx
callq *%rax
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x60(%rax)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x28(%rsp), %rcx
movq 0x50(%rcx), %rdi
movq 0x8(%rsp), %rcx
movl 0x50(%rcx), %esi
movl $0x2, %edx
callq *%rax
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x70(%rax)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x28(%rsp), %rcx
movq 0x50(%rcx), %rdi
movq 0x8(%rsp), %rcx
movl 0x84(%rcx), %esi
movl $0x2, %edx
callq *%rax
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x78(%rax)
movq 0x8(%rsp), %rax
movq $0x0, 0x1738(%rax)
movl 0x18(%rsp), %ecx
addl $0x6, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x1708(%rax)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x28(%rsp), %rcx
movq 0x50(%rcx), %rdi
movq 0x8(%rsp), %rcx
movl 0x1708(%rcx), %esi
movl $0x4, %edx
callq *%rax
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x8(%rsp), %rax
movl 0x1708(%rax), %eax
movl %eax, %ecx
shlq $0x2, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x8(%rsp), %rax
cmpq $0x0, 0x60(%rax)
je 0xd033d
movq 0x8(%rsp), %rax
cmpq $0x0, 0x70(%rax)
je 0xd033d
movq 0x8(%rsp), %rax
cmpq $0x0, 0x78(%rax)
je 0xd033d
movq 0x8(%rsp), %rax
cmpq $0x0, 0x10(%rax)
jne 0xd0371
movq 0x8(%rsp), %rax
movl $0x29a, 0x8(%rax)       # imm = 0x29A
leaq 0xe30b0(%rip), %rax     # 0x1b3400
movq 0x30(%rax), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x28(%rsp), %rdi
callq 0xd0400
movl $0xfffffffc, 0x34(%rsp) # imm = 0xFFFFFFFC
jmp 0xd03ea
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x8(%rsp), %rax
movl 0x1708(%rax), %eax
addq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x1700(%rax)
movq 0x8(%rsp), %rax
movl 0x1708(%rax), %eax
subl $0x1, %eax
imull $0x3, %eax, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x1710(%rax)
movl 0x24(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0xc4(%rax)
movl 0x14(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0xc8(%rax)
movl 0x20(%rsp), %eax
movb %al, %cl
movq 0x8(%rsp), %rax
movb %cl, 0x48(%rax)
movq 0x28(%rsp), %rdi
callq 0xd0550
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)