// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/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
        const char *ext = fn? strrchr(fn, '.') : NULL;
        if (ext == NULL || strchr(ext, '/')) {
            free(mode_opts);
            return NULL;
        }
        return sam_open_mode(cp, fn, ext+1)
            ? (free(mode_opts), NULL)
            : mode_opts;
    }

    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 {
        free(mode_opts);
        return NULL;
    }

    strcpy(cp, opts);

    return mode_opts;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xab43d
movq -0x20(%rbp), %rdi
callq 0x62c0
movq %rax, -0x50(%rbp)
jmp 0xab448
movl $0x1, %eax
movq %rax, -0x50(%rbp)
jmp 0xab448
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xab466
movq -0x18(%rbp), %rdi
callq 0x62c0
movq %rax, -0x60(%rbp)
jmp 0xab471
movl $0x1, %eax
movq %rax, -0x60(%rbp)
jmp 0xab471
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rax
addq %rax, %rdi
addq $0xc, %rdi
callq 0x69c0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xab49d
movq $0x0, -0x8(%rbp)
jmp 0xab71b
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xab4b6
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0xab4c3
leaq 0x348d9(%rip), %rax     # 0xdfd96
movq %rax, -0x70(%rbp)
jmp 0xab4c3
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x6680
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rdi
callq 0x62c0
movq %rax, %rcx
movq -0x78(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xab59f
cmpq $0x0, -0x10(%rbp)
je 0xab515
movq -0x10(%rbp), %rdi
movl $0x2e, %esi
callq 0x67b0
movq %rax, -0x80(%rbp)
jmp 0xab51d
xorl %eax, %eax
movq %rax, -0x80(%rbp)
jmp 0xab51d
movq -0x80(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xab540
movq -0x48(%rbp), %rdi
movl $0x2f, %esi
callq 0x6260
cmpq $0x0, %rax
je 0xab556
movq -0x28(%rbp), %rdi
callq 0x6880
movq $0x0, -0x8(%rbp)
jmp 0xab71b
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq $0x1, %rdx
callq 0xab2f0
cmpl $0x0, %eax
je 0xab584
movq -0x28(%rbp), %rdi
callq 0x6880
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0xab58f
movq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xab71b
movq -0x20(%rbp), %rdi
movl $0x2c, %esi
callq 0x6260
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0xab5c7
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x3c(%rbp)
jmp 0xab5de
leaq 0x39e38(%rip), %rax     # 0xe5406
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
callq 0x62c0
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0x36efb(%rip), %rsi     # 0xe24e8
callq 0x6320
cmpl $0x0, %eax
jne 0xab60e
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x62, (%rax)
jmp 0xab706
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0x36ecf(%rip), %rsi     # 0xe24ec
callq 0x6320
cmpl $0x0, %eax
jne 0xab63e
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x63, (%rax)
jmp 0xab704
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0x390e0(%rip), %rsi     # 0xe472d
callq 0x6320
cmpl $0x0, %eax
jne 0xab687
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x63, (%rax)
movq -0x38(%rbp), %rdi
leaq 0x390bf(%rip), %rsi     # 0xe4733
callq 0x6680
movq -0x38(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x38(%rbp)
jmp 0xab702
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0x390aa(%rip), %rsi     # 0xe4740
callq 0x6320
cmpl $0x0, %eax
jne 0xab6d0
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x63, (%rax)
movq -0x38(%rbp), %rdi
leaq 0x39089(%rip), %rsi     # 0xe4746
callq 0x6680
movq -0x38(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x38(%rbp)
jmp 0xab700
movq -0x20(%rbp), %rdi
movslq -0x3c(%rbp), %rdx
leaq 0x36e05(%rip), %rsi     # 0xe24e4
callq 0x6320
cmpl $0x0, %eax
jne 0xab6eb
jmp 0xab6fe
movq -0x28(%rbp), %rdi
callq 0x6880
movq $0x0, -0x8(%rbp)
jmp 0xab71b
jmp 0xab700
jmp 0xab702
jmp 0xab704
jmp 0xab706
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6680
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)