// File: /workspace/github_c_makefile_star2_O1/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 0x2f9bc
movq %rdx, %r15
leaq 0x69905(%rip), %rsi     # 0x991a5
movq %rdx, %rdi
callq 0x4520
testl %eax, %eax
je 0x2f9d8
leaq 0x69c7b(%rip), %rsi     # 0x99532
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2f9e2
leaq 0x6be2e(%rip), %rsi     # 0x9b6fc
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2fa2b
leaq 0x698b9(%rip), %rsi     # 0x9919e
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2fa5b
leaq 0x698ad(%rip), %rsi     # 0x991a9
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2fa51
leaq 0x6989c(%rip), %rsi     # 0x991af
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2fa51
leaq 0x69888(%rip), %rsi     # 0x991b2
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2fb01
leaq 0x6987a(%rip), %rsi     # 0x991bb
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2fb01
leaq 0x69869(%rip), %rsi     # 0x991c1
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2fb0c
leaq 0x69858(%rip), %rsi     # 0x991c7
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2fb0c
leaq 0x69844(%rip), %rsi     # 0x991ca
movq %r15, %rdi
callq 0x4520
testl %eax, %eax
je 0x2f9ae
leaq 0x6983a(%rip), %rsi     # 0x991d3
movq %r15, %rdi
callq 0x4520
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x2fb13
movb $0x0, 0x2(%rbx)
movw $0x7a46, (%rbx)         # imm = 0x7A46
jmp 0x2fb11
movq %rsi, %r14
testq %rsi, %rsi
je 0x2f9ec
leaq 0x69475(%rip), %rsi     # 0x98e40
movq %r14, %rdi
callq 0x40e0
movq %rax, %r15
jmp 0x2f9ef
movw $0x62, (%rbx)
jmp 0x2fb11
movw $0x63, (%rbx)
jmp 0x2fb11
xorl %r15d, %r15d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x2fb13
testq %r15, %r15
jne 0x2fa10
movq %r14, %rdi
callq 0x41d0
movq %rax, %r15
addq %r14, %r15
movq %r15, %rsi
cmpq %r14, %r15
setbe %al
jbe 0x2fa68
movb (%r15), %al
andb $-0x2, %al
cmpb $0x2e, %al
jne 0x2fa33
xorl %eax, %eax
movq %r15, %rsi
jmp 0x2fa68
movb $0x0, (%rbx)
jmp 0x2fb11
leaq -0x1(%r15), %rsi
cmpq %r14, %rsi
setbe %al
jbe 0x2fa65
movb (%rsi), %cl
andb $-0x2, %cl
decq %rsi
cmpb $0x2e, %cl
jne 0x2fa37
incq %rsi
jmp 0x2fa68
movw $0x66, (%rbx)
jmp 0x2fb11
movw $0x7a, (%rbx)
jmp 0x2fb11
movq %r14, %rsi
testb %al, %al
jne 0x2fac3
cmpb $0x2e, (%rsi)
jne 0x2fac3
movq %r15, %rax
subq %rsi, %rax
cmpq $0x4, %rax
je 0x2fa95
cmpq $0x3, %rax
jne 0x2fac3
cmpb $0x67, 0x1(%rsi)
jne 0x2fa8f
cmpb $0x7a, 0x2(%rsi)
je 0x2faa7
cmpq $0x4, %rax
jne 0x2fac3
cmpb $0x62, 0x1(%rsi)
jne 0x2fac3
cmpb $0x67, 0x2(%rsi)
jne 0x2fac3
cmpb $0x7a, 0x3(%rsi)
jne 0x2fac3
decq %rsi
movq %rsi, %rax
movq %rax, %rsi
cmpq %r14, %rax
jbe 0x2fac3
movb (%rsi), %cl
andb $-0x2, %cl
leaq -0x1(%rsi), %rax
cmpb $0x2e, %cl
jne 0x2faad
cmpb $0x2e, (%rsi)
jne 0x2fb13
subq %rsi, %r15
leaq -0xa(%r15), %rax
cmpq $-0x7, %rax
jb 0x2fb13
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 0x2f87e
movl %eax, %ebp
jmp 0x2fb13
movb $0x0, 0x2(%rbx)
movw $0x7a66, (%rbx)         # imm = 0x7A66
jmp 0x2fb11
movw $0x46, (%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq