// File: /workspace/github_c_makefile_star2_O2/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
andw $0x0, 0x8(%rsp)
andq $0x0, (%rsp)
xorl %ebx, %ebx
testq %rdx, %rdx
je 0x79e11
movq %rdx, %r13
movl %esi, 0xc(%rsp)
movl %ecx, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
pushq $0x9
popq %r12
pushq $0x1
popq %rbp
xorl %r15d, %r15d
movzbl (%r13), %eax
cmpl $0x72, %eax
je 0x79d1c
cmpl $0x73, %eax
je 0x79d17
cmpl $0x77, %eax
je 0x79d20
testl %eax, %eax
je 0x79d27
movsbl %al, %r14d
callq 0xb6e0
movq (%rax), %rax
movslq %r14d, %rcx
leal -0x30(%rcx), %edx
testb $0x8, 0x1(%rax,%rcx,2)
cmovnel %edx, %r12d
jmp 0x79d22
movl %ebp, %r15d
jmp 0x79d22
xorl %ebx, %ebx
jmp 0x79d22
movl %ebp, %ebx
incq %r13
jmp 0x79ce2
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)
cmpl $0x0, 0x10(%rsp)
je 0x79d69
movq %rsp, %rsi
movl 0xc(%rsp), %edi
callq 0xb6d0
movq %rax, %r14
jmp 0x79d99
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x79d82
cmpb $0x0, (%rdi)
je 0x79d82
movq %rsp, %rsi
callq 0xb720
jmp 0x79d64
testl %ebx, %ebx
jne 0x79d8f
movq 0xb41f3(%rip), %rax     # 0x12df80
jmp 0x79d96
movq 0xb41b2(%rip), %rax     # 0x12df48
movq (%rax), %r14
testq %r14, %r14
je 0x79e0f
testl %ebx, %ebx
je 0x79dcb
cmpl $0x2, %r12d
pushq $0x1
popq %rax
cmovgel %r12d, %eax
cmpl $0x9, %eax
pushq $0x9
popq %rdx
cmovll %eax, %edx
leaq 0x14(%rsp), %rdi
pushq $0x1e
popq %r8
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x79226
jmp 0x79de5
leaq 0x14(%rsp), %rdi
leaq 0x20(%rsp), %r8
movq %r14, %rsi
xorl %edx, %edx
movl %r15d, %ecx
xorl %r9d, %r9d
callq 0x796ae
movq %rax, %rbx
testq %rax, %rax
jne 0x79e11
movq 0xb418c(%rip), %rax     # 0x12df80
xorl %ebx, %ebx
cmpq (%rax), %r14
je 0x79e11
movq 0xb4146(%rip), %rax     # 0x12df48
cmpq (%rax), %r14
je 0x79e11
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