// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: sam_open_mode_opts
char *sam_open_mode_opts(const char *fn,
                         const char *mode,
                         const char *format)
{
    char *mode_opts = malloc((format ? strlen(format) : 1) +
                             (mode   ? strlen(mode)   : 1) + 12);
    char *opts, *cp;
    int format_len;

    if (!mode_opts)
        return NULL;

    strcpy(mode_opts, mode ? mode : "r");
    cp = mode_opts + strlen(mode_opts);

    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) {
            free(mode_opts);
            return NULL;
        }
        if (sam_open_mode(cp, fn, extension) == 0) {
            return mode_opts;
        } else {
            free(mode_opts);
            return NULL;
        }
    }

    if ((opts = strchr(format, ','))) {
        format_len = opts-format;
    } else {
        opts="";
        format_len = strlen(format);
    }

    if (strncmp(format, "bam", format_len) == 0) {
        *cp++ = 'b';
    } else if (strncmp(format, "cram", format_len) == 0) {
        *cp++ = 'c';
    } else if (strncmp(format, "cram2", format_len) == 0) {
        *cp++ = 'c';
        strcpy(cp, ",VERSION=2.1");
        cp += 12;
    } else if (strncmp(format, "cram3", format_len) == 0) {
        *cp++ = 'c';
        strcpy(cp, ",VERSION=3.0");
        cp += 12;
    } else if (strncmp(format, "sam", format_len) == 0) {
        ; // format mode=""
    } else if (strncmp(format, "sam.gz", format_len) == 0) {
        *cp++ = 'z';
    } else if (strncmp(format, "fastq", format_len) == 0 ||
               strncmp(format, "fq", format_len) == 0) {
        *cp++ = 'f';
    } else if (strncmp(format, "fastq.gz", format_len) == 0 ||
               strncmp(format, "fq.gz", format_len) == 0) {
        *cp++ = 'f';
        *cp++ = 'z';
    } else if (strncmp(format, "fasta", format_len) == 0 ||
               strncmp(format, "fa", format_len) == 0) {
        *cp++ = 'F';
    } else if (strncmp(format, "fasta.gz", format_len) == 0 ||
               strncmp(format, "fa", format_len) == 0) {
        *cp++ = 'F';
        *cp++ = 'z';
    } else {
        free(mode_opts);
        return NULL;
    }

    strcpy(cp, opts);

    return mode_opts;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x4223d
movq -0x20(%rbp), %rdi
callq 0x41b0
movq %rax, -0x50(%rbp)
jmp 0x42248
movl $0x1, %eax
movq %rax, -0x50(%rbp)
jmp 0x42248
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x42266
movq -0x18(%rbp), %rdi
callq 0x41b0
movq %rax, -0x60(%rbp)
jmp 0x42271
movl $0x1, %eax
movq %rax, -0x60(%rbp)
jmp 0x42271
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rax
addq %rax, %rdi
addq $0xc, %rdi
callq 0x4650
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x4229d
movq $0x0, -0x8(%rbp)
jmp 0x42658
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x422b6
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x422c3
leaq 0xb0834(%rip), %rax     # 0xf2af1
movq %rax, -0x70(%rbp)
jmp 0x422c3
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x4450
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rdi
callq 0x41b0
movq %rax, %rcx
movq -0x78(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x42357
movq -0x10(%rbp), %rdi
leaq -0x45(%rbp), %rsi
callq 0x41ff0
cmpl $0x0, %eax
jge 0x4231e
movq -0x28(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x42658
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x45(%rbp), %rdx
callq 0x41dd0
cmpl $0x0, %eax
jne 0x42341
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x42658
movq -0x28(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x42658
movq -0x20(%rbp), %rdi
movl $0x2c, %esi
callq 0x4170
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x4237f
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x3c(%rbp)
jmp 0x42396
leaq 0xadbef(%rip), %rax     # 0xeff75
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
callq 0x41b0
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xae0d8(%rip), %rsi     # 0xf047d
callq 0x4200
cmpl $0x0, %eax
jne 0x423c6
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x62, (%rax)
jmp 0x42643
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xae435(%rip), %rsi     # 0xf080a
callq 0x4200
cmpl $0x0, %eax
jne 0x423f6
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x63, (%rax)
jmp 0x42641
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xaff6c(%rip), %rsi     # 0xf2371
callq 0x4200
cmpl $0x0, %eax
jne 0x42442
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x63, (%rax)
movq -0x38(%rbp), %rdi
leaq 0xaff4b(%rip), %rsi     # 0xf2377
callq 0x4450
movq -0x38(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x38(%rbp)
jmp 0x4263f
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xaff33(%rip), %rsi     # 0xf2384
callq 0x4200
cmpl $0x0, %eax
jne 0x4248e
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x63, (%rax)
movq -0x38(%rbp), %rdi
leaq 0xaff12(%rip), %rsi     # 0xf238a
callq 0x4450
movq -0x38(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x38(%rbp)
jmp 0x4263d
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xb078c(%rip), %rsi     # 0xf2c29
callq 0x4200
cmpl $0x0, %eax
jne 0x424ac
jmp 0x4263b
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xadfbb(%rip), %rsi     # 0xf0476
callq 0x4200
cmpl $0x0, %eax
jne 0x424dc
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x7a, (%rax)
jmp 0x42639
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xadf96(%rip), %rsi     # 0xf0481
callq 0x4200
cmpl $0x0, %eax
je 0x4250e
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xadf83(%rip), %rsi     # 0xf0487
callq 0x4200
cmpl $0x0, %eax
jne 0x42525
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x66, (%rax)
jmp 0x42637
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xadf56(%rip), %rsi     # 0xf048a
callq 0x4200
cmpl $0x0, %eax
je 0x42557
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xadf46(%rip), %rsi     # 0xf0493
callq 0x4200
cmpl $0x0, %eax
jne 0x42580
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x66, (%rax)
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x7a, (%rax)
jmp 0x42635
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xadf0a(%rip), %rsi     # 0xf0499
callq 0x4200
cmpl $0x0, %eax
je 0x425b2
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xadef7(%rip), %rsi     # 0xf049f
callq 0x4200
cmpl $0x0, %eax
jne 0x425c6
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x46, (%rax)
jmp 0x42633
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xadecd(%rip), %rsi     # 0xf04a2
callq 0x4200
cmpl $0x0, %eax
je 0x425f8
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0xadeb1(%rip), %rsi     # 0xf049f
callq 0x4200
cmpl $0x0, %eax
jne 0x4261e
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x46, (%rax)
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x7a, (%rax)
jmp 0x42631
movq -0x28(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x42658
jmp 0x42633
jmp 0x42635
jmp 0x42637
jmp 0x42639
jmp 0x4263b
jmp 0x4263d
jmp 0x4263f
jmp 0x42641
jmp 0x42643
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x4450
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)