// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x19c0
movq -0x28(%rbp), %rcx
shrq $0x2, %rcx
addq $0x40, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movl $0x1, -0x88(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq $0x0, -0xc0(%rbp)
movq -0x28(%rbp), %rax
movl %eax, -0xc8(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x1490
movq -0xe0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq $0x0, -0xa8(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl %eax, -0xb0(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
leaq -0xd0(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0xe65c(%rip), %rdx      # 0x100cb
movl $0x90, %ecx
callq 0x2aa0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x1aaf
movq 0x1256f(%rip), %rax     # 0x13ff8
movq (%rax), %rdi
movl -0x3c(%rbp), %ecx
leaq 0xe63b(%rip), %rsi      # 0x100d1
leaq 0xe642(%rip), %rdx      # 0x100df
movb $0x0, %al
callq 0x10b0
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1b90
jmp 0x1ab1
leaq -0xd0(%rbp), %rdi
movl $0x4, %esi
callq 0x26c0
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jne 0x1b0f
movq -0xb8(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x1520
movq -0xe0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xd8(%rbp), %rax
subq -0xa8(%rbp), %rax
movl %eax, -0xb0(%rbp)
jmp 0x1ab1
movq -0xb8(%rbp), %rax
movq %rax, -0xe0(%rbp)
cmpl $0x1, -0x3c(%rbp)
je 0x1b65
movq 0x124ce(%rip), %rax     # 0x13ff8
movq (%rax), %rdi
movl -0x3c(%rbp), %ecx
leaq 0xe59a(%rip), %rsi      # 0x100d1
leaq 0xe5a1(%rip), %rdx      # 0x100df
movb $0x0, %al
callq 0x10b0
leaq -0xe8(%rbp), %rdi
callq 0x15e0
leaq -0xd0(%rbp), %rdi
callq 0x3070
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1b90
movq -0xe8(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0xa8(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
leaq -0xd0(%rbp), %rdi
callq 0x3070
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)