// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x2090
leaq 0x19(%rax), %rdi
callq 0x2280
movq %rax, %r12
leaq 0xf9321(%rip), %rsi     # 0x1ed1f4
movl $0x0, 0x4(%rsp)
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x1067b2(%rip), %rsi    # 0x1fa6a1
movq %r12, %rdi
callq 0x2210
testq %rax, %rax
jne 0xf3f17
movq %r12, %rdi
callq 0x2220
movl 0x4(%rsp), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq %r12, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
movq $0x41, (%rdi)
pushq $0x8
popq %rbx
pushq $0x1
popq %rbp
movq %rbx, %rsi
movq %rbp, %rdx
movq %rax, %rcx
callq 0x2410
leaq 0x18(%r14), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x20(%r14), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x28(%r14), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x30(%r14), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x38(%r14), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x40(%r14), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x50(%r14), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x58(%r14), %rdi
movq %rdi, 0x18(%rsp)
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x60(%r14), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
pushq $0x18
popq %rbx
xorl %r13d, %r13d
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
movq %r14, 0x10(%rsp)
jmp 0xf4125
movq 0x78(%r14), %rax
leaq (%rax,%rbx), %rdi
addq $-0x10, %rdi
pushq $0x8
popq %r12
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
movq 0x78(%r14), %rdi
addq %rbx, %rdi
pushq $0x4
popq %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
movq 0x78(%r14), %rax
movq -0x10(%rax,%rbx), %rdx
movq -0x8(%rax,%rbx), %rdi
movq %r12, %rsi
movq %r15, %rcx
callq 0x2410
movq 0x78(%r14), %rax
movq -0x18(%rax,%rbx), %r12
testq %r12, %r12
je 0xf411e
cmpq $0x0, 0x10(%r12)
je 0xf406e
movb (%r12), %cl
pushq $0x1
popq %rax
shll %cl, %eax
jmp 0xf4070
xorl %eax, %eax
pushq $0x4
popq %r14
movl %eax, (%rsp)
movq %rsp, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x4(%r12), %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
movq 0x8(%r12), %rbp
xorl %edi, %edi
testq %rbp, %rbp
setne %dil
movq %r15, %rsi
callq 0x2270
testq %rbp, %rbp
je 0xf40e8
movq 0x8(%r12), %rdi
movl (%rsp), %eax
movl %eax, %edx
shrl $0x5, %edx
cmpl $0x20, %eax
pushq $0x1
popq %rax
cmovbl %eax, %edx
movq %r14, %rsi
movq %r15, %rcx
callq 0x2410
movq 0x10(%r12), %rbp
xorl %edi, %edi
testq %rbp, %rbp
setne %dil
movq %r15, %rsi
callq 0x2270
testq %rbp, %rbp
je 0xf4116
movq 0x10(%r12), %rdi
movl (%rsp), %edx
pushq $0x10
popq %rsi
movq %r15, %rcx
callq 0x2410
pushq $0x1
popq %rbp
movq 0x10(%rsp), %r14
incq %r13
addq $0x20, %rbx
movq 0x18(%rsp), %rax
cmpq (%rax), %r13
jb 0xf3ffd
movq (%r14), %rdi
movq %r15, %rsi
callq 0x873f8
movq 0x15ee9b(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0xf8013(%rip), %rsi     # 0x1ec162
leaq 0xf90ad(%rip), %rdx     # 0x1ed203
xorl %eax, %eax
callq 0x22b0
movq 0x8(%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2190
jmp 0xf3f04