// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x1408, %rsp           # imm = 0x1408
movq %rdi, 0x13f8(%rsp)
movl %esi, 0x13f4(%rsp)
movq %rdx, 0x13e8(%rsp)
movl %ecx, 0x13e4(%rsp)
movl $0x9, 0x4c(%rsp)
movl $0x0, 0x48(%rsp)
leaq 0x3e(%rsp), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0xb2d0
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl $0x1e, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
cmpq $0x0, 0x13e8(%rsp)
jne 0xcbb64
movq $0x0, 0x1400(%rsp)
jmp 0xcbdb2
jmp 0xcbb66
movq 0x13e8(%rsp), %rax
cmpb $0x0, (%rax)
je 0xcbc12
movq 0x13e8(%rsp), %rax
movsbl (%rax), %eax
movl %eax, 0x14(%rsp)
subl $0x72, %eax
je 0xcbba3
jmp 0xcbb8d
movl 0x14(%rsp), %eax
subl $0x73, %eax
je 0xcbbb7
jmp 0xcbb98
movl 0x14(%rsp), %eax
subl $0x77, %eax
je 0xcbbad
jmp 0xcbbc1
movl $0x0, 0x48(%rsp)
jmp 0xcbbf9
movl $0x1, 0x48(%rsp)
jmp 0xcbbf9
movl $0x1, 0x1c(%rsp)
jmp 0xcbbf9
callq 0xb6b0
movq (%rax), %rax
movq 0x13e8(%rsp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0xcbbf7
movq 0x13e8(%rsp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
movl %eax, 0x4c(%rsp)
jmp 0xcbbf9
movq 0x13e8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x13e8(%rsp)
jmp 0xcbb66
leaq 0x3e(%rsp), %rdi
movl 0x48(%rsp), %ecx
leaq 0xa05ea(%rip), %rsi     # 0x16c20c
leaq 0xbf66e(%rip), %rax     # 0x18b297
cmpl $0x0, %ecx
cmovneq %rax, %rsi
callq 0xbb00
leaq 0x3e(%rsp), %rdi
leaq 0xa287c(%rip), %rsi     # 0x16e4bd
callq 0xbb00
cmpl $0x0, 0x13e4(%rsp)
jne 0xcbcc0
cmpq $0x0, 0x13f8(%rsp)
je 0xcbc74
movq 0x13f8(%rsp), %rdi
leaq 0xa0279(%rip), %rsi     # 0x16bee3
callq 0xb850
cmpl $0x0, %eax
jne 0xcbca7
cmpl $0x0, 0x48(%rsp)
je 0xcbc8c
movq 0xe832e(%rip), %rax     # 0x1b3fb0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0xcbc9b
movq 0xe8335(%rip), %rax     # 0x1b3fc8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x30(%rsp)
jmp 0xcbcbe
movq 0x13f8(%rsp), %rdi
leaq 0x3e(%rsp), %rsi
callq 0xb6f0
movq %rax, 0x30(%rsp)
jmp 0xcbcd6
movl 0x13f4(%rsp), %edi
leaq 0x3e(%rsp), %rsi
callq 0xb6a0
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0xcbcef
movq $0x0, 0x1400(%rsp)
jmp 0xcbdb2
cmpl $0x0, 0x48(%rsp)
je 0xcbd3a
cmpl $0x1, 0x4c(%rsp)
jge 0xcbd05
movl $0x1, 0x4c(%rsp)
cmpl $0x9, 0x4c(%rsp)
jle 0xcbd14
movl $0x9, 0x4c(%rsp)
movq 0x30(%rsp), %rsi
movl 0x4c(%rsp), %edx
movl 0x24(%rsp), %ecx
movl 0x20(%rsp), %r8d
leaq 0x13e0(%rsp), %rdi
callq 0xca590
movq %rax, 0x28(%rsp)
jmp 0xcbd63
movq 0x30(%rsp), %rsi
movl 0x24(%rsp), %edx
movl 0x1c(%rsp), %ecx
leaq 0x50(%rsp), %r8
movl 0x18(%rsp), %r9d
leaq 0x13e0(%rsp), %rdi
callq 0xcaea0
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0xcbda5
movq 0x30(%rsp), %rax
movq 0xe8251(%rip), %rcx     # 0x1b3fc8
cmpq (%rcx), %rax
je 0xcbd97
movq 0x30(%rsp), %rax
movq 0xe8228(%rip), %rcx     # 0x1b3fb0
cmpq (%rcx), %rax
je 0xcbd97
movq 0x30(%rsp), %rdi
callq 0xb670
movq $0x0, 0x1400(%rsp)
jmp 0xcbdb2
movq 0x28(%rsp), %rax
movq %rax, 0x1400(%rsp)
movq 0x1400(%rsp), %rax
addq $0x1408, %rsp           # imm = 0x1408
retq
nopw %cs:(%rax,%rax)