// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/sam.c
// Function: sam_open_mode
int sam_open_mode(char *mode, const char *fn, const char *format)
{
    // TODO Parse "bam5" etc for compression level
    if (format == NULL) {
        // Try to pick a format based on the filename extension
        char extension[HTS_MAX_EXT_LEN];
        if (find_file_extension(fn, extension) < 0) return -1;
        return sam_open_mode(mode, fn, extension);
    }
    else if (strcasecmp(format, "bam") == 0) strcpy(mode, "b");
    else if (strcasecmp(format, "cram") == 0) strcpy(mode, "c");
    else if (strcasecmp(format, "sam") == 0) strcpy(mode, "");
    else if (strcasecmp(format, "sam.gz") == 0) strcpy(mode, "z");
    else if (strcasecmp(format, "fastq") == 0 ||
             strcasecmp(format, "fq") == 0) strcpy(mode, "f");
    else if (strcasecmp(format, "fastq.gz") == 0 ||
             strcasecmp(format, "fq.gz") == 0) strcpy(mode, "fz");
    else if (strcasecmp(format, "fasta") == 0 ||
             strcasecmp(format, "fa") == 0) strcpy(mode, "F");
    else if (strcasecmp(format, "fasta.gz") == 0 ||
             strcasecmp(format, "fa.gz") == 0) strcpy(mode, "Fz");
    else return -1;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
testq %rdx, %rdx
je 0x2ec79
movq %rdx, %r15
leaq 0x676e8(%rip), %rsi     # 0x96245
movq %rdx, %rdi
callq 0x4520
testl %eax, %eax
je 0x2ed20
leaq 0x67a5e(%rip), %rsi     # 0x965d2
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2ed2a
leaq 0x69b78(%rip), %rsi     # 0x98703
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2ed34
leaq 0x6769c(%rip), %rsi     # 0x9623e
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2ed69
leaq 0x67690(%rip), %rsi     # 0x96249
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2ed62
leaq 0x6767f(%rip), %rsi     # 0x9624f
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2ed62
leaq 0x6766b(%rip), %rsi     # 0x96252
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2ed70
leaq 0x6765d(%rip), %rsi     # 0x9625b
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2ed70
leaq 0x6764c(%rip), %rsi     # 0x96261
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2edb2
leaq 0x6763b(%rip), %rsi     # 0x96267
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2edb2
leaq 0x67627(%rip), %rsi     # 0x9626a
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2ec6b
leaq 0x6761d(%rip), %rsi     # 0x96273
movq %r15, %rdi
callq 0x4520
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x2edb9
movb $0x0, 0x2(%rbx)
movw $0x7a46, (%rbx)         # imm = 0x7A46
jmp 0x2edb7
movq %rsi, %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rsi, %rsi
je 0x2edb9
leaq 0x6724f(%rip), %rsi     # 0x95ee0
movq %r14, %rdi
callq 0x40e0
movq %rax, %r15
testq %rax, %rax
jne 0x2ecaf
movq %r14, %rdi
callq 0x41d0
movq %rax, %r15
addq %r14, %r15
movq %r15, %rsi
cmpq %r14, %r15
jbe 0x2ecd6
xorl %eax, %eax
movq %r15, %rsi
movb (%rsi), %cl
movl %ecx, %edx
andb $-0x2, %dl
cmpb $0x2e, %dl
je 0x2ed39
decq %rsi
incq %rax
cmpq %r14, %rsi
ja 0x2ecbc
movq %r14, %rsi
movb (%rsi), %al
cmpb $0x2e, %al
jne 0x2edb9
subq %rsi, %r15
leaq -0xa(%r15), %rax
cmpq $-0x7, %rax
jb 0x2edb9
incq %rsi
leaq -0x1(%r15), %rdx
leaq 0x7(%rsp), %r12
movq %r12, %rdi
callq 0x43c0
movb $0x0, 0x6(%rsp,%r15)
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2eb3b
movl %eax, %ebp
jmp 0x2edb9
movw $0x62, (%rbx)
jmp 0x2edb7
movw $0x63, (%rbx)
jmp 0x2edb7
movb $0x0, (%rbx)
jmp 0x2edb7
cmpb $0x2e, %cl
jne 0x2edb9
cmpq $0x3, %rax
je 0x2ed7b
cmpq $0x4, %rax
jne 0x2ecd6
cmpb $0x62, 0x1(%rsi)
jne 0x2ecd6
cmpb $0x67, 0x2(%rsi)
jne 0x2ecd6
cmpb $0x7a, 0x3(%rsi)
jne 0x2ecd6
jmp 0x2ed8f
movw $0x66, (%rbx)
jmp 0x2edb7
movw $0x7a, (%rbx)
jmp 0x2edb7
movb $0x0, 0x2(%rbx)
movw $0x7a66, (%rbx)         # imm = 0x7A66
jmp 0x2edb7
cmpb $0x67, 0x1(%rsi)
jne 0x2ecd6
cmpb $0x7a, 0x2(%rsi)
jne 0x2ecd6
decq %rsi
cmpq %r14, %rsi
jbe 0x2ecd6
movb (%rsi), %al
movl %eax, %ecx
andb $-0x2, %cl
decq %rsi
cmpb $0x2e, %cl
jne 0x2ed92
incq %rsi
jmp 0x2ecd8
movw $0x46, (%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq