// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x1d2a1
callq 0x4050
movl $0x16, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1d496
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %eax
movl %eax, -0x1c(%rbp)
subl $0x1, %eax
je 0x1d311
jmp 0x1d2b2
movl -0x1c(%rbp), %eax
addl $-0x2, %eax
subl $0x2, %eax
jb 0x1d38c
jmp 0x1d2c3
movl -0x1c(%rbp), %eax
subl $0x4, %eax
je 0x1d311
jmp 0x1d2cd
movl -0x1c(%rbp), %eax
subl $0x6, %eax
je 0x1d326
jmp 0x1d2d7
movl -0x1c(%rbp), %eax
subl $0x8, %eax
je 0x1d38c
jmp 0x1d2e5
movl -0x1c(%rbp), %eax
subl $0x9, %eax
je 0x1d311
jmp 0x1d2ef
movl -0x1c(%rbp), %eax
subl $0xd, %eax
je 0x1d38c
jmp 0x1d2fd
movl -0x1c(%rbp), %eax
addl $-0xf, %eax
subl $0x3, %eax
jb 0x1d38c
jmp 0x1d3f7
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x103d0
movl %eax, -0x14(%rbp)
jmp 0x1d3fe
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1d37a
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x79f40
movl %eax, %ecx
movl %ecx, -0x20(%rbp)
testl %eax, %eax
je 0x1d374
jmp 0x1d34e
movl -0x20(%rbp), %eax
subl $0x2, %eax
jne 0x1d376
jmp 0x1d358
movl $0x3, %edi
leaq 0xd316e(%rip), %rsi     # 0xf04d2
leaq 0xd3171(%rip), %rdx     # 0xf04dc
movb $0x0, %al
callq 0x1b030
jmp 0x1d378
jmp 0x1d376
jmp 0x1d378
jmp 0x1d37a
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x79b00
movl %eax, -0x14(%rbp)
jmp 0x1d3fe
movq -0x10(%rbp), %rax
cmpl $0x3, 0x4c(%rax)
jne 0x1d3a4
movq -0x10(%rbp), %rdi
callq 0x35580
movl %eax, -0x14(%rbp)
jmp 0x1d3c3
movq -0x10(%rbp), %rax
cmpl $0x11, 0x4c(%rax)
je 0x1d3b8
movq -0x10(%rbp), %rax
cmpl $0x10, 0x4c(%rax)
jne 0x1d3c1
movq -0x10(%rbp), %rdi
callq 0x3c160
jmp 0x1d3c3
movq -0x10(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x1d3e2
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x103d0
orl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x1d3f5
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x14920
orl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x1d3fe
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x1d41c
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x1d4a0
orl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
callq 0x4050
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x31e70
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x1d560
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x29990
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x45a0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x45a0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x45a0
movq -0x10(%rbp), %rdi
callq 0x45a0
movl -0x18(%rbp), %eax
movl %eax, -0x24(%rbp)
callq 0x4050
movl -0x24(%rbp), %ecx
movl %ecx, (%rax)
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop