// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: bam_write_idx1
static int bam_write_idx1(htsFile *fp, const sam_hdr_t *h, const bam1_t *b) {
    BGZF *bfp = fp->fp.bgzf;

    if (!fp->idx)
        return bam_write1(bfp, b);

    uint32_t block_len = b->l_data - b->core.l_extranul + 32;
    if (bgzf_flush_try(bfp, 4 + block_len) < 0)
        return -1;
    if (!bfp->mt)
        hts_idx_amend_last(fp->idx, bgzf_tell(bfp));

    int ret = bam_write1(bfp, b);
    if (ret < 0)
        return -1;

    if (bgzf_idx_push(bfp, fp->idx, b->core.tid, b->core.pos, bam_endpos(b), bgzf_tell(bfp), !(b->core.flag&BAM_FUNMAP)) < 0) {
        hts_log_error("Read '%s' with ref_name='%s', ref_length=%"PRIhts_pos", flags=%d, pos=%"PRIhts_pos" cannot be indexed",
                bam_get_qname(b), sam_hdr_tid2name(h, b->core.tid), sam_hdr_tid2len(h, b->core.tid), b->core.flag, b->core.pos+1);
        ret = -1;
    }

    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x68(%rax)
jne 0x40070
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x34570
movl %eax, -0x4(%rbp)
jmp 0x40207
movq -0x20(%rbp), %rax
movl 0x40(%rax), %eax
movq -0x20(%rbp), %rcx
movzbl 0xf(%rcx), %ecx
subl %ecx, %eax
addl $0x20, %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %eax
addl $0x4, %eax
movl %eax, %eax
movl %eax, %esi
callq 0xff00
cmpl $0x0, %eax
jge 0x400ab
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x40207
movq -0x28(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x400e0
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rsi
shlq $0x10, %rsi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %rsi
callq 0x202c0
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x34570
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jge 0x40102
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x40207
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
callq 0x33a20
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x3c(%rbp), %edx
movq -0x38(%rbp), %rcx
movq %rax, %r8
movq -0x28(%rbp), %rax
movq 0x18(%rax), %r9
shlq $0x10, %r9
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %r9
movq -0x20(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, (%rsp)
callq 0xbec0
cmpl $0x0, %eax
jge 0x40201
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %esi
callq 0xdda00
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %esi
callq 0xdda90
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %r8
movq %rax, %r9
movq -0x20(%rbp), %rax
movzwl 0x10(%rax), %r10d
movq -0x20(%rbp), %rax
movq (%rax), %rax
addq $0x1, %rax
movl $0x1, %edi
leaq 0xb2b41(%rip), %rsi     # 0xf2d24
leaq 0xb1ff9(%rip), %rdx     # 0xf21e3
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq