// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/bzip2-1.0.6/bzlib.c
// Function: BZ2_bzRead
int BZ_API(BZ2_bzRead) 
           ( int*    bzerror, 
             BZFILE* b, 
             void*   buf, 
             int     len )
{
   Int32   n, ret;
   bzFile* bzf = (bzFile*)b;

   BZ_SETERR(BZ_OK);

   if (bzf == NULL || buf == NULL || len < 0)
      { BZ_SETERR(BZ_PARAM_ERROR); return 0; };

   if (bzf->writing)
      { BZ_SETERR(BZ_SEQUENCE_ERROR); return 0; };

   if (len == 0)
      { BZ_SETERR(BZ_OK); return 0; };

   bzf->strm.avail_out = len;
   bzf->strm.next_out = buf;

   while (True) {

      if (ferror(bzf->handle)) 
         { BZ_SETERR(BZ_IO_ERROR); return 0; };

      if (bzf->strm.avail_in == 0 && !myfeof(bzf->handle)) {
         n = fread ( bzf->buf, sizeof(UChar), 
                     BZ_MAX_UNUSED, bzf->handle );
         if (ferror(bzf->handle))
            { BZ_SETERR(BZ_IO_ERROR); return 0; };
         bzf->bufN = n;
         bzf->strm.avail_in = bzf->bufN;
         bzf->strm.next_in = bzf->buf;
      }

      ret = BZ2_bzDecompress ( &(bzf->strm) );

      if (ret != BZ_OK && ret != BZ_STREAM_END)
         { BZ_SETERR(ret); return 0; };

      if (ret == BZ_OK && myfeof(bzf->handle) && 
          bzf->strm.avail_in == 0 && bzf->strm.avail_out > 0)
         { BZ_SETERR(BZ_UNEXPECTED_EOF); return 0; };

      if (ret == BZ_STREAM_END)
         { BZ_SETERR(BZ_STREAM_END);
           return len - bzf->strm.avail_out; };
      if (bzf->strm.avail_out == 0)
         { BZ_SETERR(BZ_OK); return len; };
      
   }

   return 0; /*not reached*/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
testq %rdi, %rdi
je 0x798ae
andl $0x0, (%r14)
testq %rbx, %rbx
je 0x798ba
andl $0x0, 0x13e8(%rbx)
testq %rbx, %rbx
je 0x798e5
testq %rdx, %rdx
je 0x798e5
testl %ebp, %ebp
js 0x798e5
cmpb $0x0, 0x1394(%rbx)
je 0x79913
testq %r14, %r14
je 0x798da
orl $-0x1, (%r14)
orl $-0x1, 0x13e8(%rbx)
xorl %ebp, %ebp
jmp 0x79902
testq %r14, %r14
je 0x798f1
movl $0xfffffffe, (%r14)     # imm = 0xFFFFFFFE
xorl %ebp, %ebp
testq %rbx, %rbx
je 0x79902
movl $0xfffffffe, 0x13e8(%rbx) # imm = 0xFFFFFFFE
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ebp, %ebp
je 0x799e7
leaq 0x1398(%rbx), %r15
movl %ebp, 0x13b8(%rbx)
movq %rdx, 0x13b0(%rbx)
leaq 0x8(%rbx), %r12
movq (%rbx), %r13
movq %r13, %rdi
callq 0xbc20
testl %eax, %eax
jne 0x799fc
cmpl $0x0, 0x13a0(%rbx)
jne 0x79992
movq %r13, %rdi
callq 0x79a73
testb %al, %al
jne 0x79992
movq (%rbx), %rcx
movl $0x1388, %edx           # imm = 0x1388
movq %r12, %rdi
pushq $0x1
popq %rsi
callq 0xb930
movq %rax, %r13
movq (%rbx), %rdi
callq 0xbc20
testl %eax, %eax
jne 0x799fc
movl %r13d, 0x1390(%rbx)
movl %r13d, 0x13a0(%rbx)
movq %r12, 0x1398(%rbx)
movq %r15, %rdi
callq 0x783d0
testl $0xfffffffb, %eax       # imm = 0xFFFFFFFB
jne 0x79a17
testl %eax, %eax
je 0x799ac
cmpl $0x4, %eax
jne 0x799c5
jmp 0x79a2a
movq (%rbx), %rdi
callq 0x79a73
testb %al, %al
je 0x799c5
cmpl $0x0, 0x13a0(%rbx)
je 0x79a4b
cmpl $0x0, 0x13b8(%rbx)
jne 0x79933
testq %r14, %r14
je 0x799db
andl $0x0, (%r14)
andl $0x0, 0x13e8(%rbx)
jmp 0x79902
testq %r14, %r14
je 0x799f0
andl $0x0, (%r14)
andl $0x0, 0x13e8(%rbx)
jmp 0x798e1
testq %r14, %r14
je 0x79a08
movl $0xfffffffa, (%r14)     # imm = 0xFFFFFFFA
movl $0xfffffffa, 0x13e8(%rbx) # imm = 0xFFFFFFFA
jmp 0x798e1
testq %r14, %r14
je 0x79a1f
movl %eax, (%r14)
movl %eax, 0x13e8(%rbx)
jmp 0x798e1
testq %r14, %r14
je 0x79a36
movl $0x4, (%r14)
movl $0x4, 0x13e8(%rbx)
subl 0x13b8(%rbx), %ebp
jmp 0x79902
cmpl $0x0, 0x13b8(%rbx)
je 0x799d2
testq %r14, %r14
je 0x79a64
movl $0xfffffff9, (%r14)     # imm = 0xFFFFFFF9
movl $0xfffffff9, 0x13e8(%rbx) # imm = 0xFFFFFFF9
jmp 0x798e1