// File: /workspace/github_c_makefile_star2_O1/snej[P]zdelta/zdelta.c
// Function: zd_compress1
int ZEXPORT zd_compress1(const Bytef *ref, uLong rsize,
			 const Bytef *tar, uLong tsize,
			 Bytef **delta, uLongf *dsize)
{
  int rval;
  zd_stream strm;
  zd_mem_buffer dbuf;

  /* the zstream output buffer should have size greater than zero try to
   * guess buffer size, such that no memory realocation will be needed 
   */ 
  if(!(*dsize)) *dsize = tsize/EXPECTED_RATIO + 64; /* *dsize should not be 0*/

  /* init io buffers */
  strm.base[0]  = (Bytef*) ref;
  strm.base_avail[0] = rsize;
  strm.base_out[0] = 0;
  strm.refnum      = 1;

  strm.next_in  = (Bytef*) tar;
  strm.total_in = 0;
  strm.avail_in = tsize;

  /* allocate the output buffer */
  zd_alloc(&dbuf, *dsize);	
  
  strm.next_out  = dbuf.pos;
  strm.total_out = 0;
  strm.avail_out = *dsize; 

  strm.zalloc = (alloc_func)0;
  strm.zfree = (free_func)0;
  strm.opaque = (voidpf)0;

  /* init huffman coder */
  rval = zd_deflateInit(&strm, ZD_DEFAULT_COMPRESSION);
  if (rval != ZD_OK)
  {
    fprintf(stderr, "%s error: %d\n", "deflateInit", rval);
    return rval;
  }

  /* compress the data */
  while((rval = zd_deflate(&strm,ZD_FINISH)) == ZD_OK){

    /* set correctly the mem_buffef internal pointer */
    dbuf.pos = strm.next_out; 

    /* allocate more memory */
    zd_realloc(&dbuf,dbuf.size);

    /* restore zstream internal pointer */
    strm.next_out = (uch*)dbuf.pos;
    strm.avail_out = dbuf.size - strm.total_out;
  }

  /* set correcty the mem_buffer pointers */
  dbuf.pos = strm.next_out; 

  if(rval != ZD_STREAM_END){
    fprintf(stderr, "%s error: %d\n", "deflateInit", rval);
    zd_free(&dbuf);
    zd_deflateEnd(&strm);
    return rval;
  }

  *delta = dbuf.buffer;
  *dsize = (uLong) strm.total_out;

  /* release memory */
  return zd_deflateEnd(&strm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, %rbx
movq %r8, %r14
cmpq $0x0, (%r9)
jne 0x177c
movq %rcx, %rax
shrq $0x2, %rax
addq $0x40, %rax
movq %rax, (%rbx)
leaq 0x18(%rsp), %r15
movq %rdi, 0x30(%r15)
movq %rsi, 0x40(%r15)
xorl %r13d, %r13d
movq %r13, 0x38(%r15)
movl $0x1, 0x48(%r15)
movq %rdx, (%r15)
movq %r13, 0x10(%r15)
movl %ecx, 0x8(%r15)
movq (%rbx), %rsi
movq %rsp, %r12
movq %r12, %rdi
callq 0x1474
movq 0x8(%r12), %rax
movq %rax, 0x18(%r15)
movq %r13, 0x28(%r15)
movl (%rbx), %eax
movl %eax, 0x20(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x60(%r15)
movq %r13, 0x70(%r15)
leaq 0x78e4(%rip), %rdx      # 0x90bb
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x90, %ecx
callq 0x222b
testl %eax, %eax
jne 0x1889
leaq 0x18(%rsp), %rdi
movl $0x4, %esi
callq 0x1f2e
testl %eax, %eax
jne 0x184a
movq %rsp, %r15
leaq 0x18(%rsp), %r12
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x14c0
movq 0x8(%rsp), %rax
movq %rax, 0x30(%rsp)
movl 0x10(%rsp), %eax
subl 0x40(%rsp), %eax
movl %eax, 0x38(%rsp)
movq %r12, %rdi
movl $0x4, %esi
callq 0x1f2e
testl %eax, %eax
je 0x180c
movl %eax, %ebp
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpl $0x1, %ebp
jne 0x18ae
movq (%rsp), %rax
movq %rax, (%r14)
leaq 0x18(%rsp), %rdi
movq 0x28(%rdi), %rax
movq %rax, (%rbx)
callq 0x25a2
movl %eax, %ebp
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %ebp
movq 0xc75e(%rip), %rax      # 0xdff0
movq (%rax), %rdi
leaq 0x7825(%rip), %rsi      # 0x90c1
leaq 0x782c(%rip), %rdx      # 0x90cf
movl %ebp, %ecx
xorl %eax, %eax
callq 0x10d0
jmp 0x1875
movq 0xc73b(%rip), %rax      # 0xdff0
movq (%rax), %rdi
leaq 0x7802(%rip), %rsi      # 0x90c1
leaq 0x7809(%rip), %rdx      # 0x90cf
movl %ebp, %ecx
xorl %eax, %eax
callq 0x10d0
movq %rsp, %rdi
callq 0x1526
leaq 0x18(%rsp), %rdi
callq 0x25a2
jmp 0x1875