// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/bzip2-1.0.6/bzlib.c
// Function: bzopen_or_bzdopen
static
BZFILE * bzopen_or_bzdopen
               ( const char *path,   /* no use when bzdopen */
                 int fd,             /* no use when bzdopen */
                 const char *mode,
                 int open_mode)      /* bzopen: 0, bzdopen:1 */
{
   int    bzerr;
   char   unused[BZ_MAX_UNUSED];
   int    blockSize100k = 9;
   int    writing       = 0;
   char   mode2[10]     = "";
   FILE   *fp           = NULL;
   BZFILE *bzfp         = NULL;
   int    verbosity     = 0;
   int    workFactor    = 30;
   int    smallMode     = 0;
   int    nUnused       = 0; 

   if (mode == NULL) return NULL;
   while (*mode) {
      switch (*mode) {
      case 'r':
         writing = 0; break;
      case 'w':
         writing = 1; break;
      case 's':
         smallMode = 1; break;
      default:
         if (isdigit((int)(*mode))) {
            blockSize100k = *mode-BZ_HDR_0;
         }
      }
      mode++;
   }
   strcat(mode2, writing ? "w" : "r" );
   strcat(mode2,"b");   /* binary mode */

   if (open_mode==0) {
      if (path==NULL || strcmp(path,"")==0) {
        fp = (writing ? stdout : stdin);
        SET_BINARY_MODE(fp);
      } else {
        fp = fopen(path,mode2);
      }
   } else {
#ifdef BZ_STRICT_ANSI
      fp = NULL;
#else
      fp = fdopen(fd,mode2);
#endif
   }
   if (fp == NULL) return NULL;

   if (writing) {
      /* Guard against total chaos and anarchy -- JRS */
      if (blockSize100k < 1) blockSize100k = 1;
      if (blockSize100k > 9) blockSize100k = 9; 
      bzfp = BZ2_bzWriteOpen(&bzerr,fp,blockSize100k,
                             verbosity,workFactor);
   } else {
      bzfp = BZ2_bzReadOpen(&bzerr,fp,verbosity,smallMode,
                            unused,nUnused);
   }
   if (bzfp == NULL) {
      if (fp != stdin && fp != stdout) fclose(fp);
      return NULL;
   }
   return bzfp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x13a8, %rsp           # imm = 0x13A8
movw $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
xorl %ebx, %ebx
testq %rdx, %rdx
je 0x9a086
movl %ecx, %r12d
movq %rdx, %r13
movl %esi, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
movl $0x9, %r15d
xorl %ebp, %ebp
movzbl (%r13), %eax
cmpl $0x72, %eax
jle 0x99f68
cmpl $0x73, %eax
je 0x99f6e
cmpl $0x77, %eax
jne 0x99f79
movl $0x1, %ebx
jmp 0x99f94
jne 0x99f75
xorl %ebx, %ebx
jmp 0x99f94
movl $0x1, %ebp
jmp 0x99f94
testl %eax, %eax
je 0x99f99
movsbl %al, %r14d
callq 0xb6e0
movq (%rax), %rax
movslq %r14d, %rcx
leal -0x30(%rcx), %edx
testb $0x8, 0x1(%rax,%rcx,2)
cmovnel %edx, %r15d
incq %r13
jmp 0x99f4d
movq %rsp, %r13
movq %r13, %rdi
callq 0xb260
xorl %ecx, %ecx
testl %ebx, %ebx
setne %cl
leal (%rcx,%rcx,4), %ecx
addl $0x72, %ecx
movw %cx, (%rsp,%rax)
movq %r13, %rdi
callq 0xb260
movw $0x62, (%rsp,%rax)
testl %r12d, %r12d
je 0x99fd9
movq %rsp, %rsi
movl 0x10(%rsp), %edi
callq 0xb6d0
movq %rax, %r14
jmp 0x9a009
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x99ff2
cmpb $0x0, (%rdi)
je 0x99ff2
movq %rsp, %rsi
callq 0xb720
jmp 0x99fd4
testl %ebx, %ebx
jne 0x99fff
movq 0xb6f93(%rip), %rax     # 0x150f90
jmp 0x9a006
movq 0xb6f52(%rip), %rax     # 0x150f58
movq (%rax), %r14
testq %r14, %r14
je 0x9a084
testl %ebx, %ebx
je 0x9a041
cmpl $0x2, %r15d
movl $0x1, %eax
cmovgel %r15d, %eax
cmpl $0x9, %eax
movl $0x9, %edx
cmovll %eax, %edx
leaq 0x14(%rsp), %rdi
movq %r14, %rsi
xorl %ecx, %ecx
movl $0x1e, %r8d
callq 0x993fb
jmp 0x9a05a
leaq 0x14(%rsp), %rdi
leaq 0x20(%rsp), %r8
movq %r14, %rsi
xorl %edx, %edx
movl %ebp, %ecx
xorl %r9d, %r9d
callq 0x998ba
movq %rax, %rbx
testq %rax, %rax
jne 0x9a086
movq 0xb6f27(%rip), %rax     # 0x150f90
xorl %ebx, %ebx
cmpq (%rax), %r14
je 0x9a086
movq 0xb6ee1(%rip), %rax     # 0x150f58
cmpq (%rax), %r14
je 0x9a086
movq %r14, %rdi
callq 0xb690
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x13a8, %rsp           # imm = 0x13A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq