// File: /workspace/github_c_makefile_star2_O3/lh3[P]fermi-lite/bfc.c
// Function: fml_correct_core
float fml_correct_core(const fml_opt_t *opt, int flt_uniq, int n, bseq1_t *seq)
{
	bfc_ch_t *ch;
	int i, mode;
	uint64_t hist[256], hist_high[64], tot_len = 0, sum_k = 0, tot_k = 0;
	ec_step_t es;
	bfc_opt_t bfc_opt;
	float kcov;

	// initialize BFC options
	bfc_opt_init(&bfc_opt);
	bfc_opt.n_threads = opt->n_threads; // copy from FML options
	bfc_opt.k = flt_uniq? opt->min_asm_ovlp : opt->ec_k;
	for (i = 0; i < n; ++i) tot_len += seq[i].l_seq; // compute total length
	bfc_opt.l_pre = tot_len - 8 < 20? tot_len - 8 : 20;

	memset(&es, 0, sizeof(ec_step_t));
	es.opt = &bfc_opt, es.n_seqs = n, es.seqs = seq, es.flt_uniq = flt_uniq;

	es.ch = ch = fml_count(n, seq, bfc_opt.k, bfc_opt.q, bfc_opt.l_pre, bfc_opt.n_threads);
	mode = bfc_ch_hist(ch, hist, hist_high);
	for (i = opt->min_cnt; i < 256; ++i)
		sum_k += hist[i], tot_k += i * hist[i];
	kcov = (float)tot_k / sum_k;
	bfc_opt.min_cov = (int)(BFC_EC_MIN_COV_COEF * kcov + .499);
	bfc_opt.min_cov = bfc_opt.min_cov < opt->max_cnt? bfc_opt.min_cov : opt->max_cnt;
	bfc_opt.min_cov = bfc_opt.min_cov > opt->min_cnt? bfc_opt.min_cov : opt->min_cnt;

	es.e = calloc(es.opt->n_threads, sizeof(void*));
	for (i = 0; i < es.opt->n_threads; ++i)
		es.e[i] = ec1buf_init(es.opt, ch), es.e[i]->mode = mode;
	kt_for(es.opt->n_threads, worker_ec, &es, es.n_seqs);
	for (i = 0; i < es.opt->n_threads; ++i)
		ec1buf_destroy(es.e[i]);
	free(es.e);
	bfc_ch_destroy(ch);
	return kcov;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa78, %rsp            # imm = 0xA78
movl %edx, %ebx
movq %rdi, %r15
movl $0x14, 0x3c(%rsp)
movaps 0x10366(%rip), %xmm0    # 0x17460
movups %xmm0, 0x48(%rsp)
movaps 0x1036a(%rip), %xmm0    # 0x17470
movups %xmm0, 0x58(%rsp)
movabsq $0x640000000f, %rax     # imm = 0x640000000F
movq %rax, 0x68(%rsp)
movl (%rdi), %r9d
leaq 0x10(%rdi), %rax
leaq 0x4(%rdi), %rdx
testl %esi, %esi
cmoveq %rdx, %rax
movl %r9d, 0x38(%rsp)
movl (%rax), %edx
movl %edx, 0x40(%rsp)
testl %ebx, %ebx
jle 0x715f
movl %ebx, %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
xorl %r8d, %r8d
xorl %eax, %eax
movslq (%rcx,%r8), %r10
addq %r10, %rax
addq $0x18, %r8
cmpq %r8, %rdi
jne 0x7149
addq $-0x8, %rax
jmp 0x7166
movq $-0x8, %rax
cmpq $0x14, %rax
movl $0x14, %r8d
cmovbq %rax, %r8
leaq 0x38(%rsp), %r13
movl %r8d, 0xc(%r13)
movq $0x0, 0x20(%rsp)
movq %r13, 0x8(%rsp)
movl %ebx, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
movl %ebx, %edi
movq %rcx, %rsi
movl $0x14, %ecx
callq 0x49bb
movq %rax, %r14
movq %rax, 0x10(%rsp)
leaq 0x270(%rsp), %rsi
leaq 0x70(%rsp), %rdx
movq %rax, %rdi
callq 0x14e70
movl %eax, %ebp
movslq 0x8(%r15), %rax
cmpq $0xff, %rax
movl %ebx, 0x4(%rsp)
jg 0x7206
xorl %edx, %edx
movq %rax, %rsi
xorl %ecx, %ecx
movq 0x270(%rsp,%rsi,8), %rdi
addq %rdi, %rcx
imulq %rsi, %rdi
addq %rdi, %rdx
incq %rsi
cmpl $0x100, %esi            # imm = 0x100
jne 0x71dd
testq %rdx, %rdx
js 0x7210
cvtsi2ss %rdx, %xmm1
jmp 0x7225
movss 0x1029a(%rip), %xmm1    # 0x174a8
jmp 0x7250
movq %rdx, %rsi
shrq %rsi
andl $0x1, %edx
orq %rsi, %rdx
cvtsi2ss %rdx, %xmm1
addss %xmm1, %xmm1
testq %rcx, %rcx
js 0x7234
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
jmp 0x724c
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
divss %xmm0, %xmm1
movss %xmm1, (%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
mulsd 0x1014c(%rip), %xmm0    # 0x173b0
addsd 0x1013c(%rip), %xmm0    # 0x173a8
cvttsd2si %xmm0, %ecx
movl 0xc(%r15), %edx
cmpl %ecx, %edx
cmovll %edx, %ecx
cmpl %eax, %ecx
cmovlel %eax, %ecx
movl %ecx, 0x48(%rsp)
movslq 0x38(%rsp), %r15
movl $0x8, %esi
movq %r15, %rdi
callq 0x2130
movq %rax, 0x18(%rsp)
testq %r15, %r15
jle 0x72cb
movq %rax, %r12
xorl %ebx, %ebx
movl $0x1, %edi
movl $0xb0, %esi
callq 0x2130
movq %r13, (%rax)
movq %r14, 0x8(%rax)
movq %rax, (%r12,%rbx,8)
movl %ebp, 0xa0(%rax)
incq %rbx
cmpq %r15, %rbx
jl 0x72a3
movslq 0x4(%rsp), %rcx
leaq 0xa1(%rip), %rsi        # 0x7378
leaq 0x8(%rsp), %rbx
movl %r15d, %edi
movq %rbx, %rdx
callq 0x14684
movq (%rbx), %rax
cmpl $0x0, (%rax)
jle 0x734f
xorl %r15d, %r15d
movq 0x18(%rsp), %rax
movq (%rax,%r15,8), %rbx
movq 0x20(%rbx), %rdi
callq 0x2040
movq 0x38(%rbx), %rdi
callq 0x2040
movq 0x50(%rbx), %rdi
callq 0x2040
movq 0x68(%rbx), %rdi
callq 0x2040
movq 0x80(%rbx), %rdi
callq 0x2040
movq 0x98(%rbx), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x2040
incq %r15
movq 0x8(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r15
jl 0x72f2
movq 0x18(%rsp), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x1491c
movss (%rsp), %xmm0
addq $0xa78, %rsp            # imm = 0xA78
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq