// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/htab.cpp
// Function: uidx_write(void*, ha_pt_s*, char*, ma_ug_t*)
int uidx_write(void *flt_tab, ha_pt_t *ha_idx, char* file_name, ma_ug_t *ug)
{
	char* gfa_name = (char*)malloc(strlen(file_name)+25);
    sprintf(gfa_name, "%s.uidx.bin", file_name);
    FILE* fp = fopen(gfa_name, "w");
    if (!fp) {
        free(gfa_name);
        return 0;
    }

	if(ug) write_dbug(ug, fp);

	yak_ft_t *ha_flt_tab = (yak_ft_t*)flt_tab;

    if(ha_flt_tab)
    {
        fwrite("f", 1, 1, fp);
        yak_ft_save(ha_flt_tab, fp);
    }

	if(ha_idx)
    {
        int i;
        ha_pt1_t *g;
        fwrite("h", 1, 1, fp);
        fwrite(&ha_idx->k, sizeof(ha_idx->k), 1, fp);
        fwrite(&ha_idx->pre, sizeof(ha_idx->pre), 1, fp);
        fwrite(&ha_idx->tot, sizeof(ha_idx->tot), 1, fp);
        fwrite(&ha_idx->tot_pos, sizeof(ha_idx->tot_pos), 1, fp);

        for (i = 0; i < 1<<ha_idx->pre; ++i) 
        {
            g = &(ha_idx->h[i]);
            yak_pt_save(g->h, fp);
            fwrite(&g->n, sizeof(g->n), 1, fp);
            fwrite(g->al, sizeof(ha_idxposl_t), g->n, 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 $0x18, %rsp
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %rbx
movq %rdx, %rdi
callq 0x2090
leaq 0x19(%rax), %rdi
callq 0x2280
movq %rax, %r14
leaq 0x1145df(%rip), %rsi    # 0x1ec29c
movl $0x0, 0xc(%rsp)
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x1229c8(%rip), %rsi    # 0x1fa6a1
movq %r14, %rdi
callq 0x2210
testq %rax, %rax
jne 0xd7d01
movq %r14, %rdi
callq 0x2220
movl 0xc(%rsp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
testq %r12, %r12
je 0xd7d14
movq %r12, %rdi
movq %r15, %rsi
callq 0x873f8
movq %r14, 0x10(%rsp)
testq %rbx, %rbx
je 0xd7d34
pushq $0x66
popq %rdi
movq %r15, %rsi
callq 0x2270
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd7398
pushq $0x1
popq %rax
movl %eax, 0xc(%rsp)
testq %r13, %r13
jne 0xd7d76
movq 0x17b299(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x114411(%rip), %rsi    # 0x1ec162
leaq 0x114550(%rip), %rdx    # 0x1ec2a8
xorl %eax, %eax
callq 0x22b0
movq 0x10(%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2190
jmp 0xd7cee
movq %r13, %r12
pushq $0x68
popq %rdi
movq %r15, %rsi
callq 0x2270
pushq $0x4
popq %rbx
pushq $0x1
popq %rbp
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x4(%r12), %r13
movq %r13, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x8(%r12), %rdi
pushq $0x8
popq %rbx
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
leaq 0x10(%r12), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2410
xorl %r14d, %r14d
xorl %ebp, %ebp
movb (%r13), %cl
pushq $0x1
popq %rax
shll %cl, %eax
cltq
cmpq %rax, %rbp
jge 0xd7d40
movq 0x18(%r12), %rax
leaq (%rax,%r14), %rbx
addq $0x8, %rbx
movq -0x8(%rbx), %rdi
movq %r15, %rsi
callq 0xd747d
movq %rbx, %rdi
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x2410
movq (%rbx), %rdx
movq 0x10(%rbx), %rdi
pushq $0x10
popq %rsi
movq %r15, %rcx
callq 0x2410
incq %rbp
addq $0x20, %r14
jmp 0xd7ddf