// File: /workspace/github_c_makefile_star2_O3/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 0x99077
movl $0x0, (%r14)
testq %rbx, %rbx
je 0x99095
movl $0x0, 0x13e8(%rbx)
testq %rdx, %rdx
setne %al
testl %ebp, %ebp
setns %cl
testb %cl, %al
jne 0x990b4
testq %r14, %r14
je 0x990a1
movl $0xfffffffe, (%r14)     # imm = 0xFFFFFFFE
xorl %ebp, %ebp
testq %rbx, %rbx
je 0x990d5
movl $0xfffffffe, 0x13e8(%rbx) # imm = 0xFFFFFFFE
jmp 0x990d5
cmpb $0x0, 0x1394(%rbx)
je 0x990e6
testq %r14, %r14
je 0x990c9
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
movl $0xffffffff, 0x13e8(%rbx) # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ebp, %ebp
je 0x991cd
leaq 0x1398(%rbx), %r15
movl %ebp, 0x13b8(%rbx)
movq %rdx, 0x13b0(%rbx)
leaq 0x8(%rbx), %r12
movq (%rbx), %r13
movq %r13, %rdi
callq 0xbc30
testl %eax, %eax
jne 0x991e8
cmpl $0x0, 0x13a0(%rbx)
jne 0x9916b
movq %r13, %rdi
callq 0x9925f
testb %al, %al
jne 0x9916b
movq (%rbx), %rcx
movl $0x1, %esi
movl $0x1388, %edx           # imm = 0x1388
movq %r12, %rdi
callq 0xb940
movq %rax, %r13
movq (%rbx), %rdi
callq 0xbc30
testl %eax, %eax
jne 0x991e8
movl %r13d, 0x1390(%rbx)
movl %r13d, 0x13a0(%rbx)
movq %r12, 0x1398(%rbx)
movq %r15, %rdi
callq 0x979dd
testl $0xfffffffb, %eax       # imm = 0xFFFFFFFB
jne 0x99203
testl %eax, %eax
je 0x9918c
cmpl $0x4, %eax
jne 0x991a5
jmp 0x99216
movq (%rbx), %rdi
callq 0x9925f
testb %al, %al
je 0x991a5
cmpl $0x0, 0x13a0(%rbx)
je 0x99237
cmpl $0x0, 0x13b8(%rbx)
jne 0x99106
testq %r14, %r14
je 0x991be
movl $0x0, (%r14)
movl $0x0, 0x13e8(%rbx)
jmp 0x990d5
testq %r14, %r14
je 0x991d9
movl $0x0, (%r14)
movl $0x0, 0x13e8(%rbx)
jmp 0x990d3
testq %r14, %r14
je 0x991f4
movl $0xfffffffa, (%r14)     # imm = 0xFFFFFFFA
movl $0xfffffffa, 0x13e8(%rbx) # imm = 0xFFFFFFFA
jmp 0x990d3
testq %r14, %r14
je 0x9920b
movl %eax, (%r14)
movl %eax, 0x13e8(%rbx)
jmp 0x990d3
testq %r14, %r14
je 0x99222
movl $0x4, (%r14)
movl $0x4, 0x13e8(%rbx)
subl 0x13b8(%rbx), %ebp
jmp 0x990d5
cmpl $0x0, 0x13b8(%rbx)
je 0x991b2
testq %r14, %r14
je 0x99250
movl $0xfffffff9, (%r14)     # imm = 0xFFFFFFF9
movl $0xfffffff9, 0x13e8(%rbx) # imm = 0xFFFFFFF9
jmp 0x990d3