// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/htab.cpp
// Function: ha_ft_gen(hifiasm_opt_t const*, All_reads*, int*, int, int)
void *ha_ft_gen(const hifiasm_opt_t *asm_opt, All_reads *rs, int *hom_cov, int is_hp_mode, int read_from_store)
{
	yak_ft_t *flt_tab;
	int64_t cnt[YAK_N_COUNTS];
	int peak_hom, peak_het, cutoff = YAK_MAX_COUNT - 1, ex_flag = 0;
	if(is_hp_mode) ex_flag = HAF_RS_READ|HAF_SKIP_READ;
	ha_ct_t *h; 
	h = ha_count(asm_opt, HAF_COUNT_ALL|ex_flag|((read_from_store)?(HAF_RS_READ):(HAF_RS_WRITE_LEN)), !(asm_opt->flag&HA_F_NO_HPC), asm_opt->k_mer_length, asm_opt->mz_win, NULL, NULL, rs, NULL, 1, NULL, 0);
	if((asm_opt->flag & HA_F_VERBOSE_GFA))
	{
		write_ct_index((void*)h, asm_opt->output_file_name);
		// load_ct_index(&ha_ct_table, asm_opt->output_file_name);
		// debug_ct_index((void*)h, ha_ct_table);
		// debug_ct_index(ha_ct_table, (void*)h);
		// ha_ct_destroy((ha_ct_t *)ha_ct_table);
	}
	
	if(!(ex_flag & HAF_SKIP_READ))
	{
		ha_ct_hist(h, cnt, asm_opt->thread_num);
		peak_hom = ha_analyze_count(YAK_N_COUNTS, asm_opt->min_hist_kmer_cnt, asm_opt->hg_size>0?(h->bs/asm_opt->hg_size):(-1), cnt, &peak_het);
		if (hom_cov) *hom_cov = peak_hom;
		if (peak_hom > 0) fprintf(stderr, "[M::%s] peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het);
		///in default, asm_opt->high_factor = 5.0
		cutoff = (int)(peak_hom * asm_opt->high_factor);
		if (cutoff > YAK_MAX_COUNT - 1) cutoff = YAK_MAX_COUNT - 1;
	}
	ha_ct_shrink(h, cutoff, YAK_MAX_COUNT, asm_opt->thread_num);
	flt_tab = gen_hh(h, asm_opt->max_kmer_cnt);
	ha_ct_destroy(h);
	fprintf(stderr, "[M::%s::%.3f*%.2f@%.3fGB] ==> filtered out %ld k-mers occurring %d or more times\n", __func__,
			yak_realtime(), yak_cpu_usage(), yak_peakrss_in_gb(), (long)kh_size(flt_tab), cutoff);
	return (void*)flt_tab;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x8050, %rsp           # imm = 0x8050
movl %ecx, %ebp
movq %rdx, %r15
testl %r8d, %r8d
pushq $0x4
popq %rax
pushq $0x10
popq %rcx
cmovel %eax, %ecx
movq %rdi, %rbx
testl %ebp, %ebp
pushq $0x2
popq %rdx
pushq $0x52
popq %rax
cmovel %edx, %eax
orl %ecx, %eax
movl (%rdi), %edx
movl 0x80(%rdi), %ecx
notl %edx
andl $0x1, %edx
movl 0x94(%rdi), %r8d
andl $0x0, 0x28(%rsp)
andq $0x0, 0x20(%rsp)
andq $0x0, 0x10(%rsp)
andq $0x0, (%rsp)
movq %rsi, 0x8(%rsp)
movl $0x1, 0x18(%rsp)
movl %eax, %esi
xorl %r9d, %r9d
callq 0x119f0d
movq %rax, %r14
testb $0x4, (%rbx)
je 0x13994
movq 0x10(%rbx), %rsi
movq %r14, %rdi
callq 0x11a87d
movl $0xffe, %r12d           # imm = 0xFFE
testl %ebp, %ebp
jne 0x13a3a
movl 0x7c(%rbx), %edx
leaq 0x50(%rsp), %rsi
movq %r14, %rdi
callq 0x11aaa9
movl 0xec(%rbx), %esi
movq 0x200(%rbx), %rcx
testq %rcx, %rcx
jle 0x139d2
movq 0x18(%r14), %rax
xorl %edx, %edx
divq %rcx
movq %rax, %rdx
jmp 0x139d5
pushq $-0x1
popq %rdx
leaq 0x50(%rsp), %rcx
leaq 0x3c(%rsp), %r8
movl $0x1000, %edi           # imm = 0x1000
callq 0x11eb5b
movl %eax, %ebp
testq %r15, %r15
je 0x139f3
movl %ebp, (%r15)
testl %ebp, %ebp
jle 0x13a1d
movq 0x2815e2(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movl 0x3c(%rsp), %r8d
leaq 0x2265f0(%rip), %rsi    # 0x239ffd
leaq 0x22660d(%rip), %rdx    # 0x23a021
movl %ebp, %ecx
xorl %eax, %eax
callq 0x22b0
cvtsi2sd %ebp, %xmm0
mulsd 0xb8(%rbx), %xmm0
cvttsd2si %xmm0, %eax
movl $0xffe, %r12d           # imm = 0xFFE
cmpl %r12d, %eax
cmovll %eax, %r12d
movl 0x7c(%rbx), %ecx
movq %r14, %rdi
movl %r12d, %esi
movl $0xfff, %edx            # imm = 0xFFF
callq 0x137e4
movl 0xb0(%rbx), %esi
movq %r14, %rdi
callq 0x11a641
movq %rax, %rbx
movq %r14, %rdi
callq 0x11a823
movq 0x281573(%rip), %rax    # 0x294fe0
movq (%rax), %r14
callq 0x1365ef
movsd %xmm0, 0x48(%rsp)
callq 0x1366b8
movsd %xmm0, 0x40(%rsp)
callq 0x136685
movapd %xmm0, %xmm2
movl 0x4(%rbx), %ecx
leaq 0x226505(%rip), %rsi    # 0x239f9e
leaq 0x226581(%rip), %rdx    # 0x23a021
movq %r14, %rdi
movsd 0x48(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movl %r12d, %r8d
movb $0x3, %al
callq 0x22b0
movq %rbx, %rax
addq $0x8050, %rsp           # imm = 0x8050
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq