// File: /workspace/github_c_makefile_star2_O0/snej[P]zdelta/deflate.c
// Function: zd_deflateInit2_
int ZEXPORT zd_deflateInit2_(strm, level, method, windowBits, memLevel, 
			     strategy, version, stream_size)
    zd_streamp strm;
    int  level;
    int  method;
    int  windowBits;
    int  memLevel;
    int  strategy;
    const char *version;
    int stream_size;
{
  deflate_state *s;
  int noheader = 0;
  int refnum = strm->refnum;
  static const char* zd_version = ZDLIB_VERSION;
  int i;
  
  ushf *overlay;
  /* We overlay pending_buf and d_buf+l_buf. This works since the average
   * output size for (length,distance) codes is <= 24 bits.
   */
  
  if (version == ZD_NULL || version[0] != zd_version[0] ||
      stream_size != sizeof(zd_stream)) {
    return ZD_VERSION_ERROR;
  }
  if (strm == ZD_NULL) return ZD_STREAM_ERROR;

  strm->msg = ZD_NULL;
  if (strm->zalloc == ZD_NULL) {
    strm->zalloc = zd_zcalloc;
    strm->opaque = (voidpf)0;
  }
  if (strm->zfree == ZD_NULL) strm->zfree = zd_zcfree;

  if (level == ZD_DEFAULT_COMPRESSION) level = 7;

#ifdef FASTEST
  level = 1;
#endif

  if (windowBits < 0) { /* undocumented feature: suppress zdlib header */
    noheader = 1;
    windowBits = -windowBits;
  }

#ifdef NO_ERROR_CHECK /* suppress zdlib header at compile time */
  noheader = 1;
#endif

  if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != ZD_DEFLATED ||
      windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
      strategy < ZD_HUFFMAN_ONLY || strategy > 8 || 
      refnum < 0 || refnum > REFNUM)
  {
    return ZD_STREAM_ERROR;
  }

  s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  if (s == ZD_NULL) return ZD_MEM_ERROR;

  strm->state = (struct zd_internal_state FAR *)s;
  s->strm = strm;

  s->noheader = noheader;
  s->w_bits = windowBits;
  s->w_size = 1 << s->w_bits;
  s->w_mask = s->w_size - 1;

  s->hash_bits  = 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);

  /* zdelta: reference window mask */
  s->rw_mask = (s->w_size << 1) - 1;

  /* zdelta: needed for the correctness of reference_longest_match() */
  s->ref_window[0]=(Bytef *) ZALLOC(strm, s->w_size*2*(refnum+1),sizeof(Byte));
  s->window       =(Bytef *) (s->ref_window[0]+(2*refnum*s->w_size)); 

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

  /* zdelta: reference data hash table */ 
  s->ref_prev[0] = (Posf *)  ZALLOC(strm, s->w_size*(2*refnum), sizeof(Pos));  
  s->ref_head[0] = (Posf *)  ZALLOC(strm, s->hash_size*(refnum), sizeof(Pos));

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

  overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, 2*sizeof(ush)+2);
  s->pending_buf = (uchf *) overlay;
  s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);

  if (s->ref_window[0] == ZD_NULL || s->prev        == ZD_NULL ||
      s->head          == ZD_NULL || s->ref_prev[0] == ZD_NULL ||
      s->ref_head[0]   == ZD_NULL || s->pending_buf == ZD_NULL)
  {
    strm->msg = (char*)ERR_MSG(ZD_MEM_ERROR);
    zd_deflateEnd (strm);
    return ZD_MEM_ERROR;
  }

  s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  s->l_buf = s->d_buf + s->lit_bufsize;
  s->z_buf = s->pending_buf + (1+2*sizeof(ush))*s->lit_bufsize;

  /* zdelta: initialize reference window buffers */
  for(i=1;i<refnum;++i){
    s->ref_window[i] = (Bytef *) (s->ref_window[0] +(s->w_size)*2*i);
    s->ref_prev[i]   = (Posf *)  (s->ref_prev[0] + (s->w_size)*2*i);
    s->ref_head[i]   = (Posf *)  (s->ref_head[0] + i*(s->hash_size));
  }

  /* zdelta: these variables are not used; kept for future use */
  s->level = level;
  s->strategy = strategy;
  s->method = (Byte)method;

  if(zd_deflateReset(strm)!=ZD_OK){
    return ZD_STREAM_ERROR;
  };

  return ZD_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x38(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x2b4d
movq 0x10(%rbp), %rax
movsbl (%rax), %eax
movq 0x11576(%rip), %rcx     # 0x140b0
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x2b4d
movslq 0x18(%rbp), %rax
cmpq $0x90, %rax
je 0x2b59
movl $0xfffffffa, -0x4(%rbp) # imm = 0xFFFFFFFA
jmp 0x305b
cmpq $0x0, -0x10(%rbp)
jne 0x2b6c
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x305b
movq -0x10(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x2b9e
movq -0x10(%rbp), %rax
leaq 0x81e2(%rip), %rcx      # 0xad70
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x70(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x68(%rax)
jne 0x2bb8
movq -0x10(%rbp), %rax
leaq 0x81fc(%rip), %rcx      # 0xadb0
movq %rcx, 0x68(%rax)
cmpl $-0x1, -0x14(%rbp)
jne 0x2bc5
movl $0x7, -0x14(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x2bda
movl $0x1, -0x34(%rbp)
xorl %eax, %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x1, -0x20(%rbp)
jl 0x2c1c
cmpl $0x9, -0x20(%rbp)
jg 0x2c1c
cmpl $0x5, -0x18(%rbp)
jne 0x2c1c
cmpl $0x8, -0x1c(%rbp)
jl 0x2c1c
cmpl $0xf, -0x1c(%rbp)
jg 0x2c1c
cmpl $0x0, -0x14(%rbp)
jl 0x2c1c
cmpl $0x9, -0x14(%rbp)
jg 0x2c1c
cmpl $0x0, -0x24(%rbp)
jl 0x2c1c
cmpl $0x8, -0x24(%rbp)
jg 0x2c1c
cmpl $0x0, -0x38(%rbp)
jl 0x2c1c
cmpl $0x1, -0x38(%rbp)
jle 0x2c28
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x305b
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x70(%rcx), %rdi
movl $0x1, %esi
movl $0x1ab0, %edx           # imm = 0x1AB0
callq *%rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x2c5b
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x305b
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl -0x34(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x3c(%rax)
movq -0x30(%rbp), %rax
movl 0x3c(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x30(%rbp), %rax
movl 0x38(%rax), %ecx
subl $0x1, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x40(%rax)
movl -0x20(%rbp), %ecx
addl $0x7, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x94(%rax)
movq -0x30(%rbp), %rax
movl 0x94(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x90(%rax)
movq -0x30(%rbp), %rax
movl 0x90(%rax), %ecx
subl $0x1, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x98(%rax)
movq -0x30(%rbp), %rax
movl 0x94(%rax), %eax
addl $0x3, %eax
subl $0x1, %eax
movl $0x3, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x9c(%rax)
movq -0x30(%rbp), %rax
movl 0x38(%rax), %ecx
shll %ecx
subl $0x1, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x44(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x70(%rcx), %rdi
movq -0x30(%rbp), %rcx
movl 0x38(%rcx), %esi
shll %esi
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
imull %ecx, %esi
movl $0x1, %edx
callq *%rax
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rcx
movl -0x38(%rbp), %eax
shll %eax
movq -0x30(%rbp), %rdx
imull 0x38(%rdx), %eax
movl %eax, %eax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x70(%rcx), %rdi
movq -0x30(%rbp), %rcx
movl 0x38(%rcx), %esi
movl $0x2, %edx
callq *%rax
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x70(%rcx), %rdi
movq -0x30(%rbp), %rcx
movl 0x90(%rcx), %esi
movl $0x2, %edx
callq *%rax
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x70(%rcx), %rdi
movq -0x30(%rbp), %rcx
movl 0x38(%rcx), %esi
movl -0x38(%rbp), %ecx
shll %ecx
imull %ecx, %esi
movl $0x2, %edx
callq *%rax
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x70(%rcx), %rdi
movq -0x30(%rbp), %rcx
movl 0x90(%rcx), %esi
imull -0x38(%rbp), %esi
movl $0x2, %edx
callq *%rax
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x80(%rax)
movl -0x20(%rbp), %ecx
addl $0x6, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x1a40(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x70(%rcx), %rdi
movq -0x30(%rbp), %rcx
movl 0x1a40(%rcx), %esi
movl $0x6, %edx
callq *%rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movl 0x1a40(%rax), %eax
movl %eax, %ecx
shlq $0x2, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x2ee0
movq -0x30(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x2ee0
movq -0x30(%rbp), %rax
cmpq $0x0, 0x78(%rax)
je 0x2ee0
movq -0x30(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x2ee0
movq -0x30(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x2ee0
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x2f08
leaq 0x11259(%rip), %rax     # 0x14140
movq 0x28(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x10(%rbp), %rdi
callq 0x3070
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x305b
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rax
movl 0x1a40(%rax), %eax
shrq %rax
shlq %rax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x1a48(%rax)
movq -0x30(%rbp), %rax
movq 0x1a48(%rax), %rcx
movq -0x30(%rbp), %rax
movl 0x1a40(%rax), %eax
shlq %rax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x1a38(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movl 0x1a40(%rax), %eax
imulq $0x5, %rax, %rax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x1a50(%rax)
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x3017
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rdx
movq -0x30(%rbp), %rax
movl 0x38(%rax), %eax
shll %eax
imull -0x3c(%rbp), %eax
movl %eax, %eax
addq %rax, %rdx
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, 0x50(%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq 0x70(%rax), %rdx
movq -0x30(%rbp), %rax
movl 0x38(%rax), %eax
shll %eax
imull -0x3c(%rbp), %eax
movl %eax, %eax
shlq %rax
addq %rax, %rdx
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, 0x70(%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rdx
movl -0x3c(%rbp), %eax
movq -0x30(%rbp), %rcx
imull 0x90(%rcx), %eax
movl %eax, %eax
shlq %rax
addq %rax, %rdx
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, 0x80(%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2f7b
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xf4(%rax)
movl -0x24(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xf8(%rax)
movl -0x18(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x31(%rax)
movq -0x10(%rbp), %rdi
callq 0x1ef0
cmpl $0x0, %eax
je 0x3054
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x305b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)