// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/hts.c
// Function: hts_open_format
htsFile *hts_open_format(const char *fn, const char *mode, const htsFormat *fmt)
{
    char smode[101], *cp, *cp2, *mode_c, *uncomp = NULL;
    htsFile *fp = NULL;
    hFILE *hfile = NULL;
    char fmt_code = '\0';
    // see enum htsExactFormat in htslib/hts.h
    const char format_to_mode[] = "\0g\0\0b\0c\0\0b\0g\0\0\0\0\0Ff\0\0";

    strncpy(smode, mode, 99);
    smode[99]=0;
    if ((cp = strchr(smode, ',')))
        *cp = '\0';

    // Migrate format code (b or c) to the end of the smode buffer.
    for (cp2 = cp = smode; *cp; cp++) {
        if (*cp == 'b')
            fmt_code = 'b';
        else if (*cp == 'c')
            fmt_code = 'c';
        else {
            *cp2++ = *cp;
            // Cache the uncompress flag 'u' pos if present
            if (!uncomp && (*cp == 'u')) {
                uncomp = cp2 - 1;
            }
        }
    }
    mode_c = cp2;
    *cp2++ = fmt_code;
    *cp2++ = 0;

    // Set or reset the format code if opts->format is used
    if (fmt && fmt->format > unknown_format
        && fmt->format < sizeof(format_to_mode)) {
        *mode_c = format_to_mode[fmt->format];
    }

    // Uncompressed bam/bcf is not supported, change 'u' to '0' on write
    if (uncomp && *mode_c == 'b' && (strchr(smode, 'w') || strchr(smode, 'a'))) {
        *uncomp = '0';
    }

    // If we really asked for a compressed text format then mode_c above will
    // point to nul.  We set to 'z' to enable bgzf.
    if (strchr(mode, 'w') && fmt && fmt->compression == bgzf) {
        if (fmt->format == sam || fmt->format == vcf || fmt->format == text_format)
            *mode_c = 'z';
    }

    char *rmme = NULL, *fnidx = strstr(fn, HTS_IDX_DELIM);
    if ( fnidx ) {
        rmme = strdup(fn);
        if ( !rmme ) goto error;
        rmme[fnidx-fn] = 0;
        fn = rmme;
    }

    hfile = hopen(fn, smode);
    if (hfile == NULL) goto error;

    fp = hts_hopen(hfile, fn, smode);
    if (fp == NULL) goto error;

    // Compensate for the loss of exactness in htsExactFormat.
    // hts_hopen returns generics such as binary or text, but we
    // have been given something explicit here so use that instead.
    if (fp->is_write && fmt &&
        (fmt->format == bam || fmt->format == sam ||
         fmt->format == vcf || fmt->format == bcf ||
         fmt->format == bed || fmt->format == fasta_format ||
         fmt->format == fastq_format))
        fp->format.format = fmt->format;

    if (fmt && fmt->specific) {
        if (hts_opt_apply(fp, fmt->specific) != 0) {
            if (((hts_opt*)fmt->specific)->opt == CRAM_OPT_REFERENCE &&
                (errno == ENOENT || errno == EIO || errno == EBADF ||
                  errno == EACCES || errno == EISDIR)) {
                /* error during reference file operation
                 for these specific errors, set the error as EINVAL */
                errno = EINVAL;
            }
            goto error;
        }
    }
    if ( rmme ) free(rmme);
    return fp;

error:
    hts_log_error("Failed to open file \"%s\"%s%s", fn,
                  errno ? " : " : "", errno ? strerror(errno) : "");
    if ( rmme ) free(rmme);

    if (hfile)
        hclose_abruptly(hfile);

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0xb0(%rbp)
movq $0x0, -0xb8(%rbp)
movq $0x0, -0xc0(%rbp)
movb $0x0, -0xc1(%rbp)
movq 0xd5a3a(%rip), %rax     # 0xefca0
movq %rax, -0xe0(%rbp)
movq 0xd5a34(%rip), %rax     # 0xefca8
movq %rax, -0xd8(%rbp)
movl 0xd5a2f(%rip), %eax     # 0xefcb0
movl %eax, -0xd0(%rbp)
movw 0xd5a26(%rip), %ax      # 0xefcb4
movw %ax, -0xcc(%rbp)
leaq -0x90(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x63, %edx
callq 0x4240
movb $0x0, -0x2d(%rbp)
leaq -0x90(%rbp), %rdi
movl $0x2c, %esi
callq 0x4170
movq %rax, -0x98(%rbp)
cmpq $0x0, %rax
je 0x1a2d6
movq -0x98(%rbp), %rax
movb $0x0, (%rax)
leaq -0x90(%rbp), %rax
movq %rax, -0x98(%rbp)
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
cmpb $0x0, (%rax)
je 0x1a393
movq -0x98(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x62, %eax
jne 0x1a313
movb $0x62, -0xc1(%rbp)
jmp 0x1a37a
movq -0x98(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x63, %eax
jne 0x1a32b
movb $0x63, -0xc1(%rbp)
jmp 0x1a378
movq -0x98(%rbp), %rax
movb (%rax), %cl
movq -0xa0(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0xa0(%rbp)
movb %cl, (%rax)
cmpq $0x0, -0xb0(%rbp)
jne 0x1a376
movq -0x98(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x75, %eax
jne 0x1a376
movq -0xa0(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xb0(%rbp)
jmp 0x1a378
jmp 0x1a37a
jmp 0x1a37c
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x1a2eb
movq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movb -0xc1(%rbp), %cl
movq -0xa0(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0xa0(%rbp)
movb %cl, (%rax)
movq -0xa0(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0xa0(%rbp)
movb $0x0, (%rax)
cmpq $0x0, -0x20(%rbp)
je 0x1a40b
movq -0x20(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jbe 0x1a40b
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
cmpq $0x16, %rax
jae 0x1a40b
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movb -0xe0(%rbp,%rax), %cl
movq -0xa8(%rbp), %rax
movb %cl, (%rax)
cmpq $0x0, -0xb0(%rbp)
je 0x1a45c
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x62, %eax
jne 0x1a45c
leaq -0x90(%rbp), %rdi
movl $0x77, %esi
callq 0x4170
cmpq $0x0, %rax
jne 0x1a452
leaq -0x90(%rbp), %rdi
movl $0x61, %esi
callq 0x4170
cmpq $0x0, %rax
je 0x1a45c
movq -0xb0(%rbp), %rax
movb $0x30, (%rax)
movq -0x18(%rbp), %rdi
movl $0x77, %esi
callq 0x4170
cmpq $0x0, %rax
je 0x1a4ab
cmpq $0x0, -0x20(%rbp)
je 0x1a4ab
movq -0x20(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x1a4ab
movq -0x20(%rbp), %rax
cmpl $0x3, 0x4(%rax)
je 0x1a49f
movq -0x20(%rbp), %rax
cmpl $0x8, 0x4(%rax)
je 0x1a49f
movq -0x20(%rbp), %rax
cmpl $0x2, 0x4(%rax)
jne 0x1a4a9
movq -0xa8(%rbp), %rax
movb $0x7a, (%rax)
jmp 0x1a4ab
movq $0x0, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xd5c57(%rip), %rsi     # 0xf0118
callq 0x40c0
movq %rax, -0xf0(%rbp)
cmpq $0x0, -0xf0(%rbp)
je 0x1a51a
movq -0x10(%rbp), %rdi
callq 0x4920
movq %rax, -0xe8(%rbp)
cmpq $0x0, -0xe8(%rbp)
jne 0x1a4f6
jmp 0x1a680
movq -0xe8(%rbp), %rax
movq -0xf0(%rbp), %rcx
movq -0x10(%rbp), %rdx
subq %rdx, %rcx
movb $0x0, (%rax,%rcx)
movq -0xe8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movb $0x0, %al
callq 0x158b0
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
jne 0x1a542
jmp 0x1a680
movq -0xc0(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x1a750
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
jne 0x1a56f
jmp 0x1a680
movq -0xb8(%rbp), %rax
movl (%rax), %eax
shrl %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1a5e0
cmpq $0x0, -0x20(%rbp)
je 0x1a5e0
movq -0x20(%rbp), %rax
cmpl $0x4, 0x4(%rax)
je 0x1a5cf
movq -0x20(%rbp), %rax
cmpl $0x3, 0x4(%rax)
je 0x1a5cf
movq -0x20(%rbp), %rax
cmpl $0x8, 0x4(%rax)
je 0x1a5cf
movq -0x20(%rbp), %rax
cmpl $0x9, 0x4(%rax)
je 0x1a5cf
movq -0x20(%rbp), %rax
cmpl $0xd, 0x4(%rax)
je 0x1a5cf
movq -0x20(%rbp), %rax
cmpl $0x10, 0x4(%rax)
je 0x1a5cf
movq -0x20(%rbp), %rax
cmpl $0x11, 0x4(%rax)
jne 0x1a5e0
movq -0x20(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x4c(%rax)
cmpq $0x0, -0x20(%rbp)
je 0x1a65a
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x1a65a
movq -0xb8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x1af20
cmpl $0x0, %eax
je 0x1a658
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
cmpl $0x9, 0x8(%rax)
jne 0x1a656
callq 0x4050
cmpl $0x2, (%rax)
je 0x1a64b
callq 0x4050
cmpl $0x5, (%rax)
je 0x1a64b
callq 0x4050
cmpl $0x9, (%rax)
je 0x1a64b
callq 0x4050
cmpl $0xd, (%rax)
je 0x1a64b
callq 0x4050
cmpl $0x15, (%rax)
jne 0x1a656
callq 0x4050
movl $0x16, (%rax)
jmp 0x1a680
jmp 0x1a65a
cmpq $0x0, -0xe8(%rbp)
je 0x1a670
movq -0xe8(%rbp), %rdi
callq 0x45a0
movq -0xb8(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1a740
movq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
callq 0x4050
movl (%rax), %edx
leaq 0xd58dc(%rip), %rax     # 0xeff75
leaq 0xd5aad(%rip), %rcx     # 0xf014d
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0xf8(%rbp)
callq 0x4050
cmpl $0x0, (%rax)
je 0x1a6cd
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq %rax, -0x108(%rbp)
jmp 0x1a6dd
leaq 0xd58a1(%rip), %rax     # 0xeff75
movq %rax, -0x108(%rbp)
jmp 0x1a6dd
movq -0xf8(%rbp), %r8
movq -0x100(%rbp), %rcx
movq -0x108(%rbp), %r9
movl $0x1, %edi
leaq 0xd5a22(%rip), %rsi     # 0xf0120
leaq 0xd5a2b(%rip), %rdx     # 0xf0130
movb $0x0, %al
callq 0x1b030
cmpq $0x0, -0xe8(%rbp)
je 0x1a722
movq -0xe8(%rbp), %rdi
callq 0x45a0
cmpq $0x0, -0xc0(%rbp)
je 0x1a738
movq -0xc0(%rbp), %rdi
callq 0x149d0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax)