// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: write_hc_pt_index(ha_ug_index*, char*)
int write_hc_pt_index(ha_ug_index* idx, char* file_name)
{
    char* gfa_name = (char*)malloc(strlen(file_name)+25);
    sprintf(gfa_name, "%s.hic.tlb.bin", file_name);
    FILE* fp = fopen(gfa_name, "w");
    if (!fp) {
        free(gfa_name);
        return 0;
    }
    uint64_t i = HC_PT_MA;

    fwrite(&i, sizeof(i), 1, fp);
    fwrite(&idx->uID_bits, sizeof(idx->uID_bits), 1, fp);
    fwrite(&idx->uID_mode, sizeof(idx->uID_mode), 1, fp);
    fwrite(&idx->pos_bits, sizeof(idx->pos_bits), 1, fp);
    fwrite(&idx->pos_mode, sizeof(idx->pos_mode), 1, fp);
    fwrite(&idx->rev_mode, sizeof(idx->rev_mode), 1, fp);
    fwrite(&idx->k, sizeof(idx->k), 1, fp);
    fwrite(&idx->pre, sizeof(idx->pre), 1, fp);
    fwrite(&idx->tot, sizeof(idx->tot), 1, fp);
    fwrite(&idx->tot_pos, sizeof(idx->tot_pos), 1, fp);

    for (i = 0; i < idx->tot; i++)
    {
        fwrite(&idx->idx_buf[i].n, sizeof(idx->idx_buf[i].n), 1, fp);
        fwrite(&idx->idx_buf[i].end, sizeof(idx->idx_buf[i].end), 1, fp);
        fwrite(idx->idx_buf[i].a, sizeof(uint64_t), idx->idx_buf[i].n, fp);
        hc_pt_save(idx->idx_buf[i].h, fp);
    }

    write_dbug(idx->ug, fp);

    fprintf(stderr, "[M::%s] Index has been written.\n", __func__);
    free(gfa_name);
    fclose(fp);
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, %rdi
callq 0x2090
leaq 0x19(%rax), %rdi
callq 0x2280
movq %rax, %rbx
leaq 0x10098d(%rip), %rsi    # 0x23b304
xorl %ebp, %ebp
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x10dd55(%rip), %rsi    # 0x2486e2
movq %rbx, %rdi
callq 0x2210
testq %rax, %rax
jne 0x13a9b3
movq %rbx, %rdi
callq 0x2220
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq %rsp, %rdi
movq $0x41, (%rdi)
movl $0x8, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x2410
leaq 0x18(%r14), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2410
leaq 0x20(%r14), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2410
leaq 0x28(%r14), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2410
leaq 0x30(%r14), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2410
leaq 0x38(%r14), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2410
leaq 0x40(%r14), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2410
leaq 0x50(%r14), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2410
leaq 0x58(%r14), %r12
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x2410
leaq 0x60(%r14), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2410
cmpq $0x0, 0x58(%r14)
jne 0x13aae6
movq (%r14), %rdi
movq %r15, %rsi
callq 0xc3874
movq 0x15a52c(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0xff7c4(%rip), %rsi     # 0x23a282
leaq 0x10084e(%rip), %rdx    # 0x23b313
xorl %eax, %eax
callq 0x22b0
movq %rbx, %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2190
movl $0x1, %ebp
jmp 0x13a9a2
movl $0x18, %r13d
xorl %ebp, %ebp
movq 0x78(%r14), %rax
leaq (%rax,%r13), %rdi
addq $-0x10, %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2410
movq 0x78(%r14), %rdi
addq %r13, %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2410
movq 0x78(%r14), %rax
movq -0x10(%rax,%r13), %rdx
movq -0x8(%rax,%r13), %rdi
movl $0x8, %esi
movq %r15, %rcx
callq 0x2410
movq 0x78(%r14), %rax
movq -0x18(%rax,%r13), %rdi
testq %rdi, %rdi
jne 0x13ab60
incq %rbp
addq $0x20, %r13
cmpq (%r12), %rbp
jb 0x13aaee
jmp 0x13aaa2
movq %r15, %rsi
callq 0x1c11a
jmp 0x13ab4e