// File: 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
movq %rsp, %rbp
subq $0x80a0, %rsp           # imm = 0x80A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl $0xffe, -0x803c(%rbp)   # imm = 0xFFE
movl $0x0, -0x8040(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x189642
movl $0x50, -0x8040(%rbp)
movq -0x8(%rbp), %rdi
movl -0x8040(%rbp), %esi
orl $0x2, %esi
movl -0x20(%rbp), %edx
movl $0x4, %eax
movl $0x10, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
orl %eax, %esi
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edx
movq -0x8(%rbp), %rax
movl 0x80(%rax), %ecx
movq -0x8(%rbp), %rax
movl 0x94(%rax), %r8d
movq -0x10(%rbp), %rax
xorl %r9d, %r9d
xorl %r10d, %r10d
movq $0x0, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x1, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x0, 0x28(%rsp)
callq 0x1886f0
movq %rax, -0x8048(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1896f6
movq -0x8048(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x1898e0
movl -0x8040(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x18981c
movq -0x8048(%rbp), %rdi
leaq -0x8030(%rbp), %rsi
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %edx
callq 0x189a70
movq -0x8(%rbp), %rax
movl 0xec(%rax), %eax
movl %eax, -0x804c(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x200(%rax)
jle 0x189761
movq -0x8048(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
xorl %edx, %edx
divq 0x200(%rcx)
movq %rax, -0x8058(%rbp)
jmp 0x189771
movq $-0x1, %rax
movq %rax, -0x8058(%rbp)
jmp 0x189771
movl -0x804c(%rbp), %esi
movq -0x8058(%rbp), %rax
movl %eax, %edx
leaq -0x8030(%rbp), %rcx
movl $0x1000, %edi           # imm = 0x1000
leaq -0x8038(%rbp), %r8
callq 0x1925c0
movl %eax, -0x8034(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1897b1
movl -0x8034(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x8034(%rbp)
jle 0x1897e6
movq 0x23a81f(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x8034(%rbp), %ecx
movl -0x8038(%rbp), %r8d
leaq 0x2013e5(%rip), %rsi    # 0x38abbd
leaq 0x201402(%rip), %rdx    # 0x38abe1
movb $0x0, %al
callq 0x22a0
cvtsi2sdl -0x8034(%rbp), %xmm0
movq -0x8(%rbp), %rax
mulsd 0xb8(%rax), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x803c(%rbp)
cmpl $0xffe, -0x803c(%rbp)   # imm = 0xFFE
jle 0x18981a
movl $0xffe, -0x803c(%rbp)   # imm = 0xFFE
jmp 0x18981c
movq -0x8048(%rbp), %rdi
movl -0x803c(%rbp), %esi
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %ecx
movl $0xfff, %edx            # imm = 0xFFF
callq 0x1891f0
movq -0x8048(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0xb0(%rax), %esi
callq 0x1892f0
movq %rax, -0x28(%rbp)
movq -0x8048(%rbp), %rdi
callq 0x1894a0
movq 0x23a779(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x8070(%rbp)
callq 0x1b7ca0
movsd %xmm0, -0x8060(%rbp)
callq 0x1b7d20
movsd %xmm0, -0x8068(%rbp)
callq 0x1b7d00
movq -0x8070(%rbp), %rdi
movsd -0x8068(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0x8060(%rbp), %xmm0
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %ecx
movl -0x803c(%rbp), %r8d
leaq 0x20129d(%rip), %rsi    # 0x38ab5e
leaq 0x201319(%rip), %rdx    # 0x38abe1
movb $0x3, %al
callq 0x22a0
movq -0x28(%rbp), %rax
addq $0x80a0, %rsp           # imm = 0x80A0
popq %rbp
retq
nopl (%rax)