// File: chhylp123[P]hifiasm/htab.cpp
// Function: ha_count(hifiasm_opt_t const*, int, int, int, int, ha_pt_s*, void const*, All_reads*, ma_utg_v*, int, int*, int)
ha_ct_t *ha_count(const hifiasm_opt_t *asm_o, int flag, int HPC, int k, int w, ha_pt_t *p0, const void *flt_tab, All_reads *rs, ma_utg_v *us, int keep_adapter, int *low_freq, int unique_only)
{
	int i;
	int64_t n_seq = 0;
	uint64_t n_bs = 0;
	yak_copt_t opt;
	ha_ct_t *h = 0;
	assert(!(flag & HAF_RS_WRITE_LEN) || !(flag & HAF_RS_WRITE_SEQ)); // not both
	///for 0-th counting, flag = HAF_COUNT_ALL|HAF_RS_WRITE_LEN
	if (rs) {
		if (flag & HAF_RS_WRITE_LEN)
			init_All_reads(rs);
		else if (flag & HAF_RS_WRITE_SEQ)
			malloc_All_reads(rs);
	}
	yak_copt_init(&opt);
	opt.k = k;
	opt.is_HPC = HPC;
	///for ft-counting, shoud be 1
	opt.w = flag & HAF_COUNT_ALL? 1 : w;
	///for ft-counting, shoud be 37
	///for ha_pt_gen, shoud be 0
	opt.bf_shift = flag & HAF_COUNT_EXACT? 0 : asm_o->bf_shift;
	opt.n_thread = asm_o->thread_num;
	opt.adaLen = (keep_adapter? asm_o->adapterLen : 0);
	opt.min_rcnt = (low_freq?*low_freq:-1);
	opt.uq = (unique_only?1:0);
	
	n_bs = 0;
	///pending for integration
	/**
	if(rs && asm_o->ar && asm_o->ul_mod) {
		for (i = 0; i < asm_o->ar->n; ++i){
			h = yak_count(&opt, asm_o->ar->a[i], flag|HAF_CREATE_NEW, p0, h, flt_tab, rs, us, &n_seq);
			if(h) n_bs += h->bs;
		}
	}**/
	///asm_opt->num_reads is the number of fastq files
	for (i = 0; i < (us?1:asm_o->num_reads); ++i){
		h = yak_count(&opt, asm_o->read_file_names[i], flag|HAF_CREATE_NEW, p0, h, flt_tab, rs, us, &n_seq);
		if(h) n_bs += h->bs;
	}
	if(h) h->bs = n_bs;	
	if (h && opt.bf_shift > 0)
		ha_ct_destroy_bf(h);
	return h;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq %r9, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x70(%rbp)
movl -0xc(%rbp), %ecx
andl $0x4, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x71(%rbp)
je 0x18875f
movl -0xc(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x188768
jmp 0x18876a
jmp 0x188789
leaq 0x202320(%rip), %rdi    # 0x38aa91
leaq 0x202187(%rip), %rsi    # 0x38a8ff
movl $0x3de, %edx            # imm = 0x3DE
leaq 0x202346(%rip), %rcx    # 0x38aaca
callq 0x2130
cmpq $0x0, 0x18(%rbp)
je 0x1887be
movl -0xc(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1887a6
movq 0x18(%rbp), %rdi
callq 0x7360
jmp 0x1887bc
movl -0xc(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1887ba
movq 0x18(%rbp), %rdi
callq 0x92c0
jmp 0x1887bc
jmp 0x1887be
leaq -0x68(%rbp), %rdi
callq 0x186400
movl -0x14(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0xc(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1887e8
movl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x1887ee
movl -0x18(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x188806
xorl %eax, %eax
movl %eax, -0x7c(%rbp)
jmp 0x188813
movq -0x8(%rbp), %rax
movl 0xac(%rax), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, 0x28(%rbp)
je 0x188838
movq -0x8(%rbp), %rax
movl 0x100(%rax), %eax
movl %eax, -0x80(%rbp)
jmp 0x18883f
xorl %eax, %eax
movl %eax, -0x80(%rbp)
jmp 0x18883f
movl -0x80(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x18885a
movq 0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x84(%rbp)
jmp 0x188867
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x84(%rbp)
jmp 0x188867
movl -0x84(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl 0x38(%rbp), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x54(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x88(%rbp)
cmpq $0x0, 0x20(%rbp)
je 0x1888af
movl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x1888bc
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x8c(%rbp)
movl -0x88(%rbp), %eax
movl -0x8c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x18893c
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl -0xc(%rbp), %edx
orl $0x20, %edx
movq -0x20(%rbp), %rcx
movq -0x70(%rbp), %r8
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %r11
movq 0x20(%rbp), %r10
leaq -0x68(%rbp), %rdi
leaq -0x30(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x188980
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x18892c
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x18892e
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x188892
cmpq $0x0, -0x70(%rbp)
je 0x18894f
movq -0x38(%rbp), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x18(%rax)
cmpq $0x0, -0x70(%rbp)
je 0x188965
cmpl $0x0, -0x68(%rbp)
jle 0x188965
movq -0x70(%rbp), %rdi
callq 0x186c60
movq -0x70(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)