// File: karel-brinda[P]ococo/ext/htslib/hts.c
// Function: hts_close
int hts_close(htsFile *fp)
{
    int ret, save;

    switch (fp->format.format) {
    case binary_format:
    case bam:
    case bcf:
        ret = bgzf_close(fp->fp.bgzf);
        break;

    case cram:
        if (!fp->is_write) {
            switch (cram_eof(fp->fp.cram)) {
            case 2:
                fprintf(stderr, "[W::%s] EOF marker is absent. The input is probably truncated.\n", __func__);
                break;
            case 0:  /* not at EOF, but may not have wanted all seqs */
            default: /* case 1, expected EOF */
                break;
            }
        }
        ret = cram_close(fp->fp.cram);
        break;

    case text_format:
    case sam:
    case vcf:
        if (!fp->is_write) {
        #if KS_BGZF
            BGZF *gzfp = ((kstream_t*)fp->fp.voidp)->f;
            ret = bgzf_close(gzfp);
        #else
            gzFile gzfp = ((kstream_t*)fp->fp.voidp)->f;
            ret = gzclose(gzfp);
        #endif
            ks_destroy((kstream_t*)fp->fp.voidp);
        }
        else if (fp->format.compression != no_compression)
            ret = bgzf_close(fp->fp.bgzf);
        else
            ret = hclose(fp->fp.hfile);
        break;

    default:
        ret = -1;
        break;
    }

    save = errno;
    free(fp->fn);
    free(fp->fn_aux);
    free(fp->line.s);
    free(fp);
    errno = save;
    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, -0x1c(%rbp)
subl $0x1, %eax
je 0x1411e
jmp 0x140dd
movl -0x1c(%rbp), %eax
addl $-0x2, %eax
subl $0x2, %eax
jb 0x1419e
jmp 0x140ee
movl -0x1c(%rbp), %eax
subl $0x4, %eax
je 0x1411e
jmp 0x140f8
movl -0x1c(%rbp), %eax
subl $0x6, %eax
je 0x14133
jmp 0x14102
movl -0x1c(%rbp), %eax
subl $0x8, %eax
je 0x1419e
jmp 0x14110
movl -0x1c(%rbp), %eax
subl $0x9, %eax
jne 0x14209
jmp 0x1411e
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x65880
movl %eax, -0xc(%rbp)
jmp 0x14210
movq -0x8(%rbp), %rax
movl (%rax), %eax
shrl %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1418c
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x52a00
movl %eax, %ecx
movl %ecx, -0x20(%rbp)
testl %eax, %eax
je 0x14186
jmp 0x1415b
movl -0x20(%rbp), %eax
subl $0x2, %eax
jne 0x14188
jmp 0x14165
movq 0x75e64(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
leaq 0x66e5f(%rip), %rsi     # 0x7afd5
leaq 0x66e98(%rip), %rdx     # 0x7b015
movb $0x0, %al
callq 0x4830
jmp 0x1418a
jmp 0x14188
jmp 0x1418a
jmp 0x1418c
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x52680
movl %eax, -0xc(%rbp)
jmp 0x14210
movq -0x8(%rbp), %rax
movl (%rax), %eax
shrl %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x141d9
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x65880
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x10c90
jmp 0x14207
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
je 0x141f5
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x65880
movl %eax, -0xc(%rbp)
jmp 0x14205
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x6ad60
movl %eax, -0xc(%rbp)
jmp 0x14207
jmp 0x14210
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
callq 0x4070
movl (%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x46a0
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x46a0
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x46a0
movq -0x8(%rbp), %rdi
callq 0x46a0
movl -0x10(%rbp), %eax
movl %eax, -0x24(%rbp)
callq 0x4070
movl -0x24(%rbp), %ecx
movl %ecx, (%rax)
movl -0xc(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)