// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x50(%rsp), %rax
movl $0xfffffffa, %r15d      # imm = 0xFFFFFFFA
testq %rax, %rax
je 0x24ce
cmpl $0x90, 0x58(%rsp)
jne 0x24ce
cmpb $0x32, (%rax)
jne 0x24ce
movl %ecx, %r12d
movq %rdi, %rbx
movl 0x48(%rdi), %r10d
movq $0x0, 0x50(%rdi)
movq 0x60(%rdi), %rax
testq %rax, %rax
jne 0x22a4
leaq 0x4405(%rip), %rax      # 0x669d
movq %rax, 0x60(%rbx)
movq $0x0, 0x70(%rbx)
cmpq $0x0, 0x68(%rbx)
jne 0x22b6
leaq 0x43f4(%rip), %rcx      # 0x66a6
movq %rcx, 0x68(%rbx)
cmpl $-0x1, %esi
movl $0x7, %edi
cmovnel %esi, %edi
movl %r12d, %ebp
negl %ebp
cmovsl %r12d, %ebp
leal -0xa(%r8), %ecx
cmpl $-0x9, %ecx
setb %cl
cmpl $0x5, %edx
setne %dl
leal -0x10(%rbp), %esi
cmpl $-0x8, %esi
setb %sil
orb %cl, %dl
cmpl $0xa, %edi
setae %cl
orb %dl, %cl
orb %sil, %cl
cmpl $0x9, %r9d
setae %dl
orb %cl, %dl
cmpl $0x2, %r10d
setae %cl
orb %dl, %cl
movl $0xfffffffe, %r15d      # imm = 0xFFFFFFFE
jne 0x24ce
movq %r10, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movl %edi, (%rsp)
movl %r9d, 0x4(%rsp)
movq 0x70(%rbx), %rdi
movl $0x1, %r14d
movl $0x1, %esi
movl $0x1ab0, %edx           # imm = 0x1AB0
callq *%rax
movl $0xfffffffc, %r15d      # imm = 0xFFFFFFFC
testq %rax, %rax
je 0x24ce
movq %rax, %r13
shrl $0x1f, %r12d
movq %rax, 0x58(%rbx)
movq %rbx, (%rax)
movl %r12d, 0x2c(%rax)
movl %ebp, 0x3c(%rax)
movl %ebp, %ecx
shll %cl, %r14d
movl %r14d, 0x38(%rax)
decl %r14d
movl %r14d, 0x40(%rax)
movl $0x80, %eax
movq 0x10(%rsp), %r14
movl %r14d, %ecx
shll %cl, %eax
leal 0x7(%r14), %ecx
movl %ecx, 0x94(%r13)
movl %eax, 0x90(%r13)
decl %eax
movl %eax, 0x98(%r13)
leal 0x9(%r14), %eax
movzbl %al, %eax
imull $0xab, %eax, %eax
shrl $0x9, %eax
movl %eax, 0x9c(%r13)
movl $0x2, %eax
movl %ebp, %ecx
shll %cl, %eax
decl %eax
movl %eax, 0x44(%r13)
movq 0x70(%rbx), %rdi
movq 0x8(%rsp), %r12
leal 0x1(%r12), %esi
incb %bpl
movl %ebp, %ecx
shll %cl, %esi
movl $0x1, %edx
callq *0x60(%rbx)
movq %rax, 0x50(%r13)
leal (%r12,%r12), %ebp
movl 0x38(%r13), %esi
movl %esi, %ecx
imull %ebp, %ecx
addq %rax, %rcx
movq %rcx, 0x48(%r13)
movq 0x70(%rbx), %rdi
movl $0x2, %edx
callq *0x60(%rbx)
movq %rax, 0x68(%r13)
movq 0x70(%rbx), %rdi
movl 0x90(%r13), %esi
movl $0x2, %edx
callq *0x60(%rbx)
movq %rax, 0x78(%r13)
movq 0x70(%rbx), %rdi
imull 0x38(%r13), %ebp
movl %ebp, %esi
movl $0x2, %edx
callq *0x60(%rbx)
movq %rax, 0x70(%r13)
movq 0x70(%rbx), %rdi
imull 0x90(%r13), %r12d
movl %r12d, %esi
movl $0x2, %edx
callq *0x60(%rbx)
movl $0x40, %esi
movl %r14d, %ecx
shll %cl, %esi
movq %rax, 0x80(%r13)
movl %esi, 0x1a40(%r13)
movq 0x70(%rbx), %rdi
movl $0x6, %edx
callq *0x60(%rbx)
movq %rax, 0x10(%r13)
movl 0x1a40(%r13), %ecx
leaq (,%rcx,4), %rdx
movq %rdx, 0x18(%r13)
cmpq $0x0, 0x50(%r13)
je 0x24b7
cmpq $0x0, 0x68(%r13)
je 0x24b7
cmpq $0x0, 0x78(%r13)
je 0x24b7
cmpq $0x0, 0x70(%r13)
je 0x24b7
cmpq $0x0, 0x80(%r13)
sete %dl
testq %rax, %rax
sete %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x24e0
leaq 0xbc82(%rip), %rax      # 0xe140
movq 0x28(%rax), %rax
movq %rax, 0x50(%rbx)
movq %rbx, %rdi
callq 0x253b
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, %edx
andl $-0x2, %edx
addq %rax, %rdx
movq %rdx, 0x1a48(%r13)
leaq (%rdx,%rcx,2), %rdx
movq %rdx, 0x1a38(%r13)
leaq (%rcx,%rcx,4), %rcx
addq %rax, %rcx
movq %rcx, 0x1a50(%r13)
movl (%rsp), %eax
movl %eax, 0xf4(%r13)
movl 0x4(%rsp), %eax
movl %eax, 0xf8(%r13)
movb $0x5, 0x31(%r13)
movq %rbx, %rdi
callq 0x1b44
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leal -0x2(,%rcx,2), %r15d
jmp 0x24ce