// File: /workspace/github_c_makefile_star2_O2/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, %r11d
movq %rdi, %r15
movl $0x14, 0x3c(%rsp)
movaps 0xe752(%rip), %xmm0     # 0x14460
movups %xmm0, 0x48(%rsp)
movapd 0xe755(%rip), %xmm0     # 0x14470
movupd %xmm0, 0x58(%rsp)
movabsq $0x640000000f, %rax     # imm = 0x640000000F
movq %rax, 0x68(%rsp)
movl (%rdi), %r9d
movl %r9d, 0x38(%rsp)
leaq 0x10(%rdi), %rax
leaq 0x4(%rdi), %rdx
testl %esi, %esi
cmoveq %rdx, %rax
movl (%rax), %edx
movl %edx, 0x40(%rsp)
xorl %eax, %eax
testl %r11d, %r11d
movl $0x0, %edi
cmovgl %r11d, %edi
imulq $0x18, %rdi, %r8
xorl %edi, %edi
cmpq %rax, %r8
je 0x5d72
movslq (%rcx,%rax), %r10
addq %r10, %rdi
addq $0x18, %rax
jmp 0x5d60
addq $-0x8, %rdi
cmpq $0x14, %rdi
pushq $0x14
popq %r8
cmovbq %rdi, %r8
leaq 0x38(%rsp), %rax
movl %r8d, 0xc(%rax)
andq $0x0, 0x20(%rsp)
movq %rax, 0x8(%rsp)
movl %r11d, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
pushq $0x14
popq %rax
movl %r11d, 0x4(%rsp)
movl %r11d, %edi
movq %rcx, %rsi
movl %eax, %ecx
callq 0x3b27
movq %rax, %r14
movq %rax, 0x10(%rsp)
leaq 0x270(%rsp), %rsi
leaq 0x70(%rsp), %rdx
movq %rax, %rdi
callq 0x1224d
movl %eax, %ebp
movslq 0x8(%r15), %rax
xorl %ecx, %ecx
movq %rax, %rsi
xorl %edx, %edx
cmpq $0xff, %rsi
jg 0x5e03
movq 0x270(%rsp,%rsi,8), %rdi
addq %rdi, %rcx
imulq %rsi, %rdi
addq %rdi, %rdx
incq %rsi
jmp 0x5de3
testq %rdx, %rdx
js 0x5e0f
cvtsi2ss %rdx, %xmm1
jmp 0x5e24
movq %rdx, %rsi
shrq %rsi
andl $0x1, %edx
orq %rsi, %rdx
cvtsi2ss %rdx, %xmm1
addss %xmm1, %xmm1
testq %rcx, %rcx
js 0x5e30
cvtsi2ss %rcx, %xmm0
jmp 0x5e45
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
divss %xmm0, %xmm1
movss %xmm1, (%rsp)
cvtss2sd %xmm1, %xmm0
mulsd 0xe556(%rip), %xmm0     # 0x143b0
addsd 0xe546(%rip), %xmm0     # 0x143a8
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
pushq $0x8
popq %rsi
movq %r15, %rdi
callq 0x2130
movq %rax, %r12
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
pushq $0x1
popq %r13
cmpq %r15, %rbx
jge 0x5ec3
movl $0xb0, %esi
movq %r13, %rdi
callq 0x2130
leaq 0x38(%rsp), %rcx
movq %rcx, (%rax)
movq %r14, 0x8(%rax)
movq %rax, (%r12,%rbx,8)
movl %ebp, 0xa0(%rax)
incq %rbx
jmp 0x5e96
movslq 0x4(%rsp), %rcx
leaq 0x93(%rip), %rsi        # 0x5f62
leaq 0x8(%rsp), %rdx
movl %r15d, %edi
callq 0x11b74
xorl %r15d, %r15d
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rdi
movslq (%rax), %rax
cmpq %rax, %r15
jge 0x5f3e
movq (%rdi,%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
jmp 0x5edf
callq 0x2040
movq %r14, %rdi
callq 0x11df7
movss (%rsp), %xmm0
addq $0xa78, %rsp            # imm = 0xA78
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq