// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/htab.cpp
// Function: write_pt_index(void*, ha_pt_s*, All_reads*, hifiasm_opt_t*, char*)
int write_pt_index(void *flt_tab, ha_pt_t *ha_idx, All_reads* r, hifiasm_opt_t* opt, char* file_name)
{
    char* gfa_name = (char*)malloc(strlen(file_name)+64);
    sprintf(gfa_name, "%s.pt_flt", file_name);
    FILE* fp = fopen(gfa_name, "w");
	if (!fp) {
		free(gfa_name);
        return 0;
    }
	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->a, sizeof(ha_idxpos_t), g->n, fp);
		}
	}

	fwrite(&opt->number_of_round, sizeof(opt->number_of_round), 1, fp);
	fwrite(&opt->hom_cov, sizeof(opt->hom_cov), 1, fp);
	fwrite(&opt->het_cov, sizeof(opt->het_cov), 1, fp);
	fwrite(&opt->max_n_chain, sizeof(opt->max_n_chain), 1, fp);


	write_All_reads(r, gfa_name);

	sprintf(gfa_name, "%s.pt_flt.paf.bin", file_name); 
	fclose(fp); fp = fopen(gfa_name, "w"); uint64_t k;
	if (!fp) {
		free(gfa_name);
        return 0;
    }
	fwrite(&(r->total_reads), sizeof(r->total_reads), 1, fp);
	for (k = 0; k < r->total_reads; k++) {
		fwrite(&(r->paf[k].is_fully_corrected), sizeof(r->paf[k].is_fully_corrected), 1, fp);
        fwrite(&(r->paf[k].is_abnormal), sizeof(r->paf[k].is_abnormal), 1, fp);
        fwrite(&(r->paf[k].length), sizeof(r->paf[k].length), 1, fp);
        fwrite(r->paf[k].buffer, sizeof((*(r->paf[k].buffer))), r->paf[k].length, 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 %r8, %r13
movq %rcx, 0x18(%rsp)
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %r15
movq %r8, %rdi
callq 0x2090
leaq 0x40(%rax), %rdi
callq 0x2280
movq %rax, %r12
leaq 0x11f502(%rip), %rsi    # 0x23a306
xorl %ebx, %ebx
movq %rax, %rdi
movq %r13, 0x20(%rsp)
movq %r13, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x12d8c3(%rip), %rsi    # 0x2486e2
movq %r12, %rdi
callq 0x2210
testq %rax, %rax
je 0x11afe8
movq %rax, %r13
movq %r12, 0x8(%rsp)
movq %r14, 0x10(%rsp)
testq %r15, %r15
je 0x11ae5a
movl $0x66, %edi
movq %r13, %rsi
callq 0x2270
movq %r15, %rdi
movq %r13, %rsi
callq 0x11b016
testq %rbp, %rbp
je 0x11af2e
movl $0x68, %edi
movq %r13, %rsi
callq 0x2270
movl $0x4, %esi
movl $0x1, %edx
movq %rbp, %rdi
movq %r13, %rcx
callq 0x2410
leaq 0x4(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x2410
leaq 0x8(%rbp), %rdi
movl $0x8, %r15d
movl $0x8, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x2410
leaq 0x10(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x2410
cmpl $0x1f, 0x4(%rbp)
je 0x11af2e
xorl %r12d, %r12d
movq 0x18(%rbp), %r14
leaq (%r14,%r15), %rbx
movq -0x8(%r14,%r15), %rdi
movq %r13, %rsi
callq 0x11b0ff
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rcx
callq 0x2410
movq (%r14,%r15), %rdx
movq 0x8(%r14,%r15), %rdi
movl $0x8, %esi
movq %r13, %rcx
callq 0x2410
movb 0x4(%rbp), %cl
movl $0x1, %eax
shll %cl, %eax
incq %r12
cltq
addq $0x20, %r15
cmpq %rax, %r12
jl 0x11aed6
movq 0x18(%rsp), %rbx
leaq 0xf8(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x2410
leaq 0xd0(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x2410
leaq 0xd4(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x2410
addq $0xe8, %rbx
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rcx
callq 0x2410
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x3546
leaq 0x11f35a(%rip), %rsi    # 0x23a310
xorl %ebx, %ebx
movq %r15, %rdi
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
movq %r13, %rdi
callq 0x2190
leaq 0x12d70c(%rip), %rsi    # 0x2486e2
movq %r15, %rdi
callq 0x2210
testq %rax, %rax
jne 0x11b001
movq %r15, %rdi
jmp 0x11afeb
movq %r12, %rdi
callq 0x2220
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x1434d
movl $0x1, %ebx
jmp 0x11aff0