// File: /workspace/github_c_makefile_star2_O0/zhou-lab[P]tbmate/htslib/hts.c
// Function: hts_idx_save_core
static int hts_idx_save_core(const hts_idx_t *idx, BGZF *fp, int fmt)
{
    int32_t i, j;

    #define check(ret) if ((ret) < 0) return -1

    check(idx_write_int32(fp, idx->n));
    if (fmt == HTS_FMT_TBI && idx->l_meta)
        check(bgzf_write(fp, idx->meta, idx->l_meta));

    for (i = 0; i < idx->n; ++i) {
        khint_t k;
        bidx_t *bidx = idx->bidx[i];
        lidx_t *lidx = &idx->lidx[i];
        // write binning index
        check(idx_write_int32(fp, bidx? kh_size(bidx) : 0));
        if (bidx)
            for (k = kh_begin(bidx); k != kh_end(bidx); ++k)
                if (kh_exist(bidx, k)) {
                    bins_t *p = &kh_value(bidx, k);
                    check(idx_write_uint32(fp, kh_key(bidx, k)));
                    if (fmt == HTS_FMT_CSI) check(idx_write_uint64(fp, p->loff));
                    //int j;for(j=0;j<p->n;++j)fprintf(stderr,"%d,%llx,%d,%llx:%llx\n",kh_key(bidx,k),kh_val(bidx, k).loff,j,p->list[j].u,p->list[j].v);
                    check(idx_write_int32(fp, p->n));
                    for (j = 0; j < p->n; ++j) {
                        check(idx_write_uint64(fp, p->list[j].u));
                        check(idx_write_uint64(fp, p->list[j].v));
                    }
                }

        // write linear index
        if (fmt != HTS_FMT_CSI) {
            check(idx_write_int32(fp, lidx->n));
            for (j = 0; j < lidx->n; ++j)
                check(idx_write_uint64(fp, lidx->offset[j]));
        }
    }

    check(idx_write_uint64(fp, idx->n_no_coor));
    return 0;
    #undef check
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %esi
callq 0x12e20
cmpq $0x0, %rax
jge 0x12ed5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
cmpl $0x2, -0x1c(%rbp)
jne 0x12f13
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x12f13
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
callq 0x3bef0
cmpq $0x0, %rax
jge 0x12f11
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
jmp 0x12f13
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x13182
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x12f70
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x4c(%rbp)
jmp 0x12f77
xorl %eax, %eax
movl %eax, -0x4c(%rbp)
jmp 0x12f77
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x12e20
cmpq $0x0, %rax
jge 0x12f95
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
cmpq $0x0, -0x30(%rbp)
je 0x13102
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
je 0x13100
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x28(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x28(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x130f0
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x28(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x28(%rbp), %ecx
movl (%rax,%rcx,4), %esi
callq 0x12e60
cmpq $0x0, %rax
jge 0x1301e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
cmpl $0x0, -0x1c(%rbp)
jne 0x13049
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x15bc0
cmpq $0x0, %rax
jge 0x13047
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
jmp 0x13049
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x12e20
cmpq $0x0, %rax
jge 0x1306b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x130ee
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x15bc0
cmpq $0x0, %rax
jge 0x130af
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x15bc0
cmpq $0x0, %rax
jge 0x130e1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
jmp 0x130e3
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x13072
jmp 0x130f0
jmp 0x130f2
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x12fa7
jmp 0x13102
cmpl $0x0, -0x1c(%rbp)
je 0x13172
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
movl (%rax), %esi
callq 0x12e20
cmpq $0x0, %rax
jge 0x13129
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x13170
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x15bc0
cmpq $0x0, %rax
jge 0x13163
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
jmp 0x13165
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x13130
jmp 0x13172
jmp 0x13174
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x12f1a
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x15bc0
cmpq $0x0, %rax
jge 0x131a2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x131a9
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)