// File: afinit[P]afin/gzip.cpp
// Function: Gzip::fill_buffer()
void Gzip::fill_buffer(){
  unsigned char in[BUFF_SIZE];
  unsigned char out[BUFF_SIZE];
  int next_pos = 0;
  unsigned int char_in = 0;

  // read in data from gzipd file
  zs.avail_in = fread(in, 1, BUFF_SIZE, fp);

  // handle read errors
  if (ferror(fp)) {
    (void)inflateEnd(&zs);
    status = Z_ERRNO;
    return;
  }

  // handle data error
  if (zs.avail_in == 0){
    status = Z_DATA_ERROR;
    return;
  }

  // set next_in pointer to data from fread
  zs.next_in = in;
  do{
    zs.avail_out = BUFF_SIZE;
    zs.next_out = out;

    // decompress data
    status = inflate(&zs, Z_NO_FLUSH);

    // check for errors
    switch (status) {
      case Z_BUF_ERROR:
        status = Z_OK;
        return;
      case Z_NEED_DICT:
        status = Z_DATA_ERROR;     /* and fall through */
      case Z_DATA_ERROR:
      case Z_MEM_ERROR:
        (void)inflateEnd(&zs);
        zerr();
        return;
    }

    int have = BUFF_SIZE - zs.avail_out;
    char out_str[have+1];
    strncpy( out_str, (char*)out, have );
    out_str[have] = '\0';

    // append data to buffer
    buffer.append( out_str );
  }while( zs.avail_out == 0 );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl 0x8(%rax), %ecx
movq %rsp, %rdx
movq %rdx, -0x10(%rbp)
movq %rcx, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rdi
subq %rdx, %rdi
movq %rdi, -0x58(%rbp)
movq %rdi, %rsp
movq %rcx, -0x18(%rbp)
movl 0x8(%rax), %ecx
movq %rcx, %rsi
addq $0xf, %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x50(%rbp)
movq %rdx, %rsp
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movslq 0x8(%rax), %rdx
movq 0xa0(%rax), %rcx
movl $0x1, %esi
callq 0x45d0
movq %rax, %rcx
movq -0x48(%rbp), %rax
movl %ecx, 0x38(%rax)
movq 0xa0(%rax), %rdi
callq 0x4720
cmpl $0x0, %eax
je 0x10fbb
movq -0x48(%rbp), %rdi
addq $0x30, %rdi
callq 0x4410
movq -0x48(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movl $0x1, -0x2c(%rbp)
jmp 0x110ef
movq -0x48(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x10fdc
movq -0x48(%rbp), %rax
movl $0xfffffffd, 0xc(%rax)  # imm = 0xFFFFFFFD
movl $0x1, -0x2c(%rbp)
jmp 0x110ef
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, 0x30(%rax)
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
movl 0x8(%rax), %edx
movq %rax, %rdi
addq $0x30, %rdi
movl %edx, 0x50(%rax)
movq %rcx, 0x48(%rax)
xorl %esi, %esi
callq 0x4330
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0xc(%rax)
movl 0xc(%rax), %eax
movl %eax, -0x5c(%rbp)
subl $-0x5, %eax
je 0x11035
jmp 0x1101e
movl -0x5c(%rbp), %eax
addl $0x4, %eax
subl $0x2, %eax
jb 0x11057
jmp 0x1102b
movl -0x5c(%rbp), %eax
subl $0x2, %eax
je 0x1104c
jmp 0x11076
movq -0x48(%rbp), %rax
movl $0x0, 0xc(%rax)
movl $0x1, -0x2c(%rbp)
jmp 0x110ef
movq -0x48(%rbp), %rax
movl $0xfffffffd, 0xc(%rax)  # imm = 0xFFFFFFFD
movq -0x48(%rbp), %rdi
addq $0x30, %rdi
callq 0x4410
movq -0x48(%rbp), %rdi
callq 0x108e0
movl $0x1, -0x2c(%rbp)
jmp 0x110ef
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %rsi
movl 0x8(%rcx), %eax
movl 0x50(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
incl %eax
movq %rsp, %rcx
movq %rcx, -0x38(%rbp)
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x68(%rbp)
movq %rdi, %rsp
movq %rax, -0x40(%rbp)
movslq -0x30(%rbp), %rdx
callq 0x4210
movq -0x48(%rbp), %rdi
movq -0x68(%rbp), %rsi
movslq -0x30(%rbp), %rax
movb $0x0, (%rsi,%rax)
addq $0x10, %rdi
callq 0x4730
movq -0x38(%rbp), %rax
movq %rax, %rsp
movq -0x48(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x10fe8
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)