// File: /workspace/github_c_makefile_star2_O1/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 0x99ad5
movl $0x0, (%r14)
testq %rbx, %rbx
je 0x99ae4
movl $0x0, 0x13e8(%rbx)
testq %rbx, %rbx
je 0x99b15
testq %rdx, %rdx
je 0x99b15
testl %ebp, %ebp
js 0x99b15
cmpb $0x0, 0x1394(%rbx)
je 0x99b43
testq %r14, %r14
je 0x99b07
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
movl $0xffffffff, 0x13e8(%rbx) # imm = 0xFFFFFFFF
xorl %ebp, %ebp
jmp 0x99b32
testq %r14, %r14
je 0x99b21
movl $0xfffffffe, (%r14)     # imm = 0xFFFFFFFE
xorl %ebp, %ebp
testq %rbx, %rbx
je 0x99b32
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 0x99c33
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 0x99c4e
cmpl $0x0, 0x13a0(%rbx)
jne 0x99bc8
movq %r13, %rdi
callq 0x99cb9
testb %al, %al
jne 0x99bc8
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 0x99c4e
movl %r13d, 0x1390(%rbx)
movl %r13d, 0x13a0(%rbx)
movq %r12, 0x1398(%rbx)
movq %r15, %rdi
callq 0x98471
movl %eax, %r13d
testl $0xfffffffb, %eax       # imm = 0xFFFFFFFB
jne 0x99c69
testl %r13d, %r13d
jne 0x99c05
movq (%rbx), %rdi
callq 0x99cb9
testb %al, %al
je 0x99c05
cmpl $0x0, 0x13a0(%rbx)
jne 0x99c05
cmpl $0x0, 0x13b8(%rbx)
jne 0x99c9e
cmpl $0x4, %r13d
je 0x99c7d
cmpl $0x0, 0x13b8(%rbx)
jne 0x99b63
testq %r14, %r14
je 0x99c24
movl $0x0, (%r14)
movl $0x0, 0x13e8(%rbx)
jmp 0x99b32
testq %r14, %r14
je 0x99c3f
movl $0x0, (%r14)
movl $0x0, 0x13e8(%rbx)
jmp 0x99b11
testq %r14, %r14
je 0x99c5a
movl $0xfffffffa, (%r14)     # imm = 0xFFFFFFFA
movl $0xfffffffa, 0x13e8(%rbx) # imm = 0xFFFFFFFA
jmp 0x99b11
testq %r14, %r14
je 0x99c71
movl %r13d, (%r14)
movl %r13d, 0x13e8(%rbx)
jmp 0x99b11
testq %r14, %r14
je 0x99c89
movl $0x4, (%r14)
movl $0x4, 0x13e8(%rbx)
subl 0x13b8(%rbx), %ebp
jmp 0x99b32
testq %r14, %r14
je 0x99caa
movl $0xfffffff9, (%r14)     # imm = 0xFFFFFFF9
movl $0xfffffff9, 0x13e8(%rbx) # imm = 0xFFFFFFF9
jmp 0x99b11