// File: karel-brinda[P]ococo/ext/htslib/hts.c
// Function: hts_open_format
htsFile *hts_open_format(const char *fn, const char *mode, const htsFormat *fmt)
{
    char smode[102], *cp, *cp2, *mode_c;
    htsFile *fp = NULL;
    hFILE *hfile;
    char fmt_code = '\0';

    strncpy(smode, mode, 100);
    smode[100]=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;
    }
    mode_c = cp2;
    *cp2++ = fmt_code;
    *cp2++ = 0;
    *cp2++ = 0;

    // Set or reset the format code if opts->format is used
    if (fmt && fmt->format != unknown_format)
        *mode_c = "\0g\0\0b\0c\0\0b\0g\0\0"[fmt->format];

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

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

    if (fmt && fmt->specific)
        if (hts_opt_apply(fp, fmt->specific) != 0)
            goto error;

    return fp;

error:
    if (hts_verbose >= 2)
        fprintf(stderr, "[E::%s] fail to open file '%s'\n", __func__, fn);

    if (hfile)
        hclose_abruptly(hfile);

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0xb0(%rbp)
movb $0x0, -0xb9(%rbp)
leaq -0x90(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x64, %edx
callq 0x42c0
movb $0x0, -0x2c(%rbp)
leaq -0x90(%rbp), %rdi
movl $0x2c, %esi
callq 0x41e0
movq %rax, -0x98(%rbp)
cmpq $0x0, %rax
je 0x12a6a
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 0x12af3
movq -0x98(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x62, %eax
jne 0x12aa3
movb $0x62, -0xb9(%rbp)
jmp 0x12add
movq -0x98(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x63, %eax
jne 0x12abb
movb $0x63, -0xb9(%rbp)
jmp 0x12adb
movq -0x98(%rbp), %rax
movb (%rax), %cl
movq -0xa0(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0xa0(%rbp)
movb %cl, (%rax)
jmp 0x12add
jmp 0x12adf
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x12a7f
movq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movb -0xb9(%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)
movq -0xa0(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0xa0(%rbp)
movb $0x0, (%rax)
cmpq $0x0, -0x20(%rbp)
je 0x12b7b
movq -0x20(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x12b7b
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %ecx
leaq 0x68176(%rip), %rax     # 0x7ace5
movb (%rax,%rcx), %cl
movq -0xa8(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x6b3f0
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
jne 0x12b9e
jmp 0x12c04
movq -0xb8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x12c60
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jne 0x12bc8
jmp 0x12c04
cmpq $0x0, -0x20(%rbp)
je 0x12bf7
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x12bf7
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x131f0
cmpl $0x0, %eax
je 0x12bf5
jmp 0x12c04
jmp 0x12bf7
movq -0xb0(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x12c4e
cmpl $0x2, 0x779d5(%rip)     # 0x8a5e0
jl 0x12c30
movq 0x773bc(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movq -0x10(%rbp), %rcx
leaq 0x681d1(%rip), %rsi     # 0x7adf3
leaq 0x681ea(%rip), %rdx     # 0x7ae13
movb $0x0, %al
callq 0x4830
cmpq $0x0, -0xb8(%rbp)
je 0x12c46
movq -0xb8(%rbp), %rdi
callq 0x6ae00
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)