// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/hts.c
// Function: hts_close
int hts_close(htsFile *fp)
{
    int ret = 0, save;
    if (!fp) {
        errno = EINVAL;
        return -1;
    }

    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:
                hts_log_warning("EOF marker is absent. The input is probably truncated");
                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 empty_format:
    case text_format:
    case bed:
    case fasta_format:
    case fastq_format:
    case sam:
    case vcf:
        if (fp->format.format == sam)
            ret = sam_state_destroy(fp);
        else if (fp->format.format == fastq_format ||
                 fp->format.format == fasta_format)
            fastq_state_destroy(fp);

        if (fp->format.compression != no_compression)
            ret |= bgzf_close(fp->fp.bgzf);
        else
            ret |= hclose(fp->fp.hfile);
        break;

    default:
        ret = -1;
        break;
    }

    if (fp->idx) {
        // Close deferred index file handle, if present.
        // Unfortunately this means errors on the index will get mixed with
        // those on the main file, but as we only have the EOF block left to
        // write it hopefully won't happen that often.
        ret |= hts_idx_close_otf_fp(fp->idx);
    }

    save = errno;
    sam_hdr_destroy(fp->bam_header);
    hts_idx_destroy(fp->idx);
    hts_filter_free(fp->filter);
    free(fp->fn);
    free(fp->fn_aux);
    free(fp->line.s);
    free(fp);
    errno = save;
    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x1518a
movq %rdi, %rbx
movl 0x4c(%rdi), %eax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
decl %eax
cmpl $0x10, %eax
ja 0x15209
xorl %r14d, %r14d
leaq 0x80716(%rip), %rcx     # 0x9588c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x38(%rbx), %rdi
callq 0xd3cd
jmp 0x15207
callq 0x4050
movl $0x16, (%rax)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x152b6
movq %rbx, %rdi
callq 0x29374
jmp 0x151b4
movq %rbx, %rdi
callq 0x24298
movl %eax, %r14d
cmpl $0x0, 0x54(%rbx)
movq 0x38(%rbx), %rdi
je 0x151c5
callq 0xd3cd
jmp 0x151ca
callq 0xf4df
movl %eax, %ebp
orl %r14d, %ebp
jmp 0x15209
testb $0x2, (%rbx)
jne 0x151fe
movq 0x38(%rbx), %rdi
callq 0x53485
cmpl $0x2, %eax
jne 0x151fe
leaq 0x810af(%rip), %rsi     # 0x9629a
leaq 0x810b2(%rip), %rdx     # 0x962a4
movl $0x3, %edi
xorl %eax, %eax
callq 0x13de5
movq 0x38(%rbx), %rdi
callq 0x531dd
movl %eax, %ebp
movq 0x68(%rbx), %r15
testq %r15, %r15
je 0x15267
movq 0x98(%r15), %rdi
testq %rdi, %rdi
je 0x15263
xorl %r14d, %r14d
testb $0x40, 0x3(%rdi)
jne 0x15249
movq 0x20(%r15), %rax
movq %rsp, %rsi
movq %rax, (%rsi)
movl $0x8, %edx
callq 0xd005
movq %rax, %r14
shrq $0x3f, %r14
movq 0x98(%r15), %rdi
callq 0xd3cd
shrl $0x1f, %eax
orl %r14d, %eax
movq $0x0, 0x98(%r15)
negl %eax
jmp 0x15265
xorl %eax, %eax
orl %eax, %ebp
callq 0x4050
movq %rax, %r14
movl (%rax), %r15d
movq 0x78(%rbx), %rdi
callq 0x22102
movq 0x68(%rbx), %rdi
callq 0x152c3
movq 0x80(%rbx), %rdi
callq 0x1cb69
movq 0x28(%rbx), %rdi
callq 0x45c0
movq 0x30(%rbx), %rdi
callq 0x45c0
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x45c0
movl %r15d, (%r14)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq