// File: /workspace/github_c_makefile_star2_O1/lh3[P]fermi-lite/bfc.c
// Function: bfc_ec1
ecstat_t bfc_ec1(bfc_ec1buf_t *e, char *seq, char *qual)
{
	int i, start = 0, end = 0, n_n = 0, rv[2], max_heap[2];
	uint64_t r;
	ecstat_t s;

	s.ec_code = ECCODE_MISC, s.brute = 0, s.n_ec = s.n_ec_high = 0, s.n_absent = s.max_heap = 0;
	bfc_seq_conv(seq, qual, e->opt->q, &e->seq);
	for (i = 0; i < e->seq.n; ++i)
		if (e->seq.a[i].ob > 3) ++n_n;
	if (n_n > e->seq.n * .05) {
		s.ec_code = ECCODE_MANY_N;
		return s;
	}
	bfc_ec_kcov(e->opt->k, e->opt->min_cov, &e->seq, e->ch);
	r = bfc_ec_best_island(e->opt->k, &e->seq);
	if (r == 0) { // no solid k-mer
		bfc_kmer_t x;
		int ec = -1;
		while ((end = bfc_ec_first_kmer(e->opt->k, &e->seq, start, &x)) < e->seq.n) {
			ec = bfc_ec_greedy_k(e->opt->k, e->mode, &x, e->ch);
			if (ec >= 0) break;
			if (end + (e->opt->k>>1) >= e->seq.n) break;
			start = end - (e->opt->k>>1);
		}
		if (ec >= 0) {
			e->seq.a[end - (ec>>2)].b = ec&3;
			++end; start = end - e->opt->k;
			s.brute = 1;
		} else {
			s.ec_code = ECCODE_NO_SOLID;
			return s;
		}
	} else start = r>>32, end = (uint32_t)r;
	if ((rv[0] = bfc_ec1dir(e, &e->seq, &e->ec[0], start, e->seq.n, &max_heap[0])) < 0) {
		s.ec_code = rv[0] == -2? ECCODE_UNCORR_N : rv[0] == -3? ECCODE_MANY_FAIL : ECCODE_MISC;
		return s;
	}
	bfc_seq_revcomp(&e->seq);
	if ((rv[1] = bfc_ec1dir(e, &e->seq, &e->ec[1], e->seq.n - end, e->seq.n, &max_heap[1])) < 0) {
		s.ec_code = rv[1] == -2? ECCODE_UNCORR_N : rv[1] == -3? ECCODE_MANY_FAIL : ECCODE_MISC;
		return s;
	}
	s.max_heap = max_heap[0] > max_heap[1]? max_heap[0] : max_heap[1];
	s.ec_code = 0, s.n_absent = rv[0] + rv[1];
	bfc_seq_revcomp(&e->ec[1]);
	bfc_seq_revcomp(&e->seq);
	for (i = 0; i < e->seq.n; ++i) {
		ecbase_t *c = &e->seq.a[i];
		if (e->ec[0].a[i].b == e->ec[1].a[i].b)
			c->b = e->ec[0].a[i].b > 3? e->seq.a[i].b : e->ec[0].a[i].b;
		else if (e->ec[1].a[i].b > 3) c->b = e->ec[0].a[i].b;
		else if (e->ec[0].a[i].b > 3) c->b = e->ec[1].a[i].b;
		else c->b = e->seq.a[i].ob;
	}
	for (i = 0; i < e->seq.n; ++i) {
		int is_diff = !(e->seq.a[i].b == e->seq.a[i].ob);
		if (is_diff) {
			++s.n_ec;
			if (e->seq.a[i].q) ++s.n_ec_high;
		}
		seq[i] = (is_diff? "acgtn" : "ACGTN")[e->seq.a[i].b];
		if (qual) qual[i] = is_diff? 34 + e->seq.a[i].ob : "+?"[e->seq.a[i].q];
	}
	return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq (%rdi), %rax
movl 0x4(%rax), %ebp
leaq 0x40(%rdi), %rax
movq %rax, 0x8(%rsp)
movq %rsi, %rdi
callq 0x20a0
movq %rax, %r12
movslq %r12d, %r13
cmpq %r13, 0x48(%r15)
jae 0x5ad1
leaq -0x1(%r13), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x48(%r15)
movq 0x50(%r15), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x21d0
movq %rax, 0x50(%r15)
movq 0x8(%rsp), %rax
movq %r13, (%rax)
testl %r13d, %r13d
jle 0x5b68
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %eax, %eax
leaq 0x1767e(%rip), %rcx     # 0x1d170
xorl %edx, %edx
movq 0x50(%r15), %rsi
movsbq (%r14,%rdx), %rdi
movb (%rcx,%rdi), %r8b
addb $0x7, %r8b
movb (%rsi,%rdx,8), %dil
movl %r8d, %r9d
andb $0x7, %r9b
movl %r9d, %r10d
shlb $0x4, %r10b
andb $-0x78, %dil
orb %r10b, %dil
orb %r9b, %dil
movb %dil, (%rsi,%rdx,8)
testq %rbx, %rbx
je 0x5b42
movsbl (%rbx,%rdx), %r9d
addl $-0x21, %r9d
cmpl %ebp, %r9d
movl $0x88, %r9d
cmovll %eax, %r9d
jmp 0x5b45
movb $-0x78, %r9b
andb $0x77, %dil
testb $0x4, %r8b
movzbl %r9b, %r8d
cmovnel %eax, %r8d
orb %dil, %r8b
movb %r8b, (%rsi,%rdx,8)
movl %edx, 0x4(%rsi,%rdx,8)
incq %rdx
cmpq %rdx, %r12
jne 0x5af4
movq 0x8(%rsp), %r12
movq (%r12), %rax
testq %rax, %rax
je 0x5b94
movq 0x50(%r15), %rcx
xorl %edi, %edi
xorl %esi, %esi
btl $0x6, (%rcx,%rdi,8)
adcl $0x0, %esi
incq %rdi
cmpq %rdi, %rax
jne 0x5b7e
cvtsi2sd %esi, %xmm0
jmp 0x5b98
xorpd %xmm0, %xmm0
movq %rax, %xmm1
punpckldq 0x117db(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x117e3(%rip), %xmm1    # 0x17390
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
mulsd 0x118d7(%rip), %xmm2    # 0x17498
movl $0x2, %r13d
ucomisd %xmm2, %xmm0
ja 0x5eea
movq (%r15), %rax
movq 0x8(%r15), %rcx
movl 0x8(%rax), %edi
movl 0x10(%rax), %esi
movq %r12, %rdx
callq 0x4b65
movq (%r15), %rax
movl 0x8(%rax), %edi
movq %r12, %rsi
callq 0x4d38
testq %rax, %rax
je 0x5c13
movq %rax, 0x10(%rsp)
movq %rax, %rbp
shrq $0x20, %rbp
movl $0x1, %r13d
movq %r12, %rsi
jmp 0x5cc7
movq (%r15), %rax
movl 0x8(%rax), %edi
xorl %ebp, %ebp
leaq 0x18(%rsp), %rcx
movq %r12, %rsi
xorl %edx, %edx
callq 0x4a85
movl %eax, %r9d
movslq %eax, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rcx, 0x40(%r15)
jbe 0x5c6b
movq %r9, %r13
movq (%r15), %rax
movq 0x8(%r15), %rcx
movl 0x8(%rax), %edi
movl 0xa0(%r15), %esi
leaq 0x18(%rsp), %rdx
callq 0x4899
testl %eax, %eax
js 0x5efc
movq 0x8(%rsp), %rsi
movq %r13, %r9
jmp 0x5c70
movq 0x8(%rsp), %rsi
testl %eax, %eax
js 0x5cb4
movl %eax, %r8d
andb $0x3, %r8b
movq 0x50(%r15), %rcx
movl %eax, %edx
shrl $0x2, %edx
movl %r9d, %edi
subl %edx, %edi
movslq %edi, %rdx
movb (%rcx,%rdx,8), %dil
andb $-0x8, %dil
orb %r8b, %dil
movb %dil, (%rcx,%rdx,8)
incl %r9d
movq (%r15), %rcx
movq %r9, 0x10(%rsp)
movl %r9d, %ebp
subl 0x8(%rcx), %ebp
movl $0x9, %r13d
jmp 0x5cbf
movq %r9, 0x10(%rsp)
movl $0x3, %r13d
testl %eax, %eax
js 0x5eea
leaq 0x70(%r15), %rdx
movl 0x40(%r15), %r8d
leaq 0x18(%rsp), %r9
movq %r15, %rdi
movl %ebp, %ecx
movq %rsi, %r12
callq 0x5f81
movl %eax, %ebp
testl %eax, %eax
js 0x5eb8
movq %r12, %rdi
callq 0x6b2f
leaq 0x88(%r15), %rdx
movl 0x40(%r15), %r8d
movl %r8d, %ecx
subl 0x10(%rsp), %ecx
leaq 0x1c(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %rdx, 0x10(%rsp)
callq 0x5f81
movl %eax, %r12d
testl %eax, %eax
js 0x5ec5
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
shlq $0x38, %rcx
andl $-0x8, %r13d
orq %rcx, %r13
addl %ebp, %r12d
andl $0xffffff, %r12d        # imm = 0xFFFFFF
shlq $0x20, %r12
movq 0x10(%rsp), %rdi
callq 0x6b2f
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
callq 0x6b2f
cmpq $0x0, (%rbp)
je 0x5dd9
xorl %eax, %eax
movq 0x50(%r15), %rcx
movq 0x80(%r15), %rdx
movb (%rdx,%rax,8), %dl
andb $0x7, %dl
movq 0x98(%r15), %rsi
movb (%rsi,%rax,8), %dil
andb $0x7, %dil
cmpb %dil, %dl
jne 0x5d9d
cmpb $0x4, %dl
jb 0x5da3
movb (%rcx,%rax,8), %dl
andb $0x7, %dl
jmp 0x5da3
cmpb $0x4, %dil
jb 0x5dbd
movb (%rcx,%rax,8), %sil
andb $-0x8, %sil
orb %dl, %sil
movb %sil, (%rcx,%rax,8)
incq %rax
cmpq %rax, (%rbp)
ja 0x5d6b
jmp 0x5dd9
movb (%rcx,%rax,8), %sil
cmpb $0x4, %dl
jb 0x5dcf
andb $-0x8, %sil
orb %dil, %sil
jmp 0x5dae
movl %esi, %edx
shrb $0x4, %dl
andb $0x7, %dl
jmp 0x5da7
orq %r12, %r13
cmpq $0x0, (%rbp)
je 0x5eea
xorl %eax, %eax
leaq 0x115c9(%rip), %rcx     # 0x173b9
leaq 0x116bb(%rip), %rdx     # 0x174b2
leaq 0x116ae(%rip), %rsi     # 0x174ac
movabsq $-0xfffc0001, %rdi      # imm = 0xFFFFFFFF0003FFFF
movq 0x50(%r15), %r8
movzbl (%r8,%rax,8), %r9d
movl %r9d, %r8d
shrb $0x4, %r8b
xorb %r9b, %r8b
testb $0x7, %r8b
je 0x5e47
leal 0x10(%r13), %r11d
andl $0x3fff0, %r11d         # imm = 0x3FFF0
movq %r13, %r10
andq $-0x3fff1, %r10         # imm = 0xFFFC000F
orq %r11, %r10
testb $0x8, %r9b
jne 0x5e4c
movq %rsi, %r11
movq %r10, %r13
jmp 0x5e63
movq %rcx, %r11
jmp 0x5e68
addl $0x40000, %r13d         # imm = 0x40000
andl $0xfffc0000, %r13d      # imm = 0xFFFC0000
andq %rdi, %r10
orq %r10, %r13
movq %rsi, %r11
movq 0x8(%rsp), %rbp
andl $0x7, %r9d
movb (%r11,%r9), %r9b
movb %r9b, (%r14,%rax)
testq %rbx, %rbx
je 0x5ea9
movq 0x50(%r15), %r9
movzbl (%r9,%rax,8), %r9d
testb $0x7, %r8b
je 0x5e96
shrb $0x4, %r9b
andb $0x7, %r9b
addb $0x22, %r9b
jmp 0x5ea5
btl $0x3, %r9d
movq %rdx, %r8
adcq $0x0, %r8
movb (%r8), %r9b
movb %r9b, (%rbx,%rax)
incq %rax
cmpq %rax, (%rbp)
ja 0x5e08
jmp 0x5eea
xorl %eax, %eax
cmpl $-0x3, %ebp
sete %al
cmpl $-0x2, %ebp
jmp 0x5ed2
xorl %eax, %eax
cmpl $-0x3, %r12d
sete %al
cmpl $-0x2, %r12d
leaq 0x1(,%rax,4), %rax
movl $0x4, %ecx
cmovneq %rax, %rcx
andl $-0x8, %r13d
orq %rcx, %r13
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
leaq 0x18(%rsp), %r12
movq 0x8(%rsp), %rsi
movq %r13, %r9
movq (%r15), %rcx
movl 0x8(%rcx), %edx
sarl %edx
leal (%rdx,%r9), %ecx
movslq %ecx, %rcx
cmpq %rcx, 0x40(%r15)
jbe 0x5c70
movl %eax, %r13d
movl %r9d, %ebp
subl %edx, %ebp
movq (%r15), %rax
movl 0x8(%rax), %edi
movl %ebp, %edx
movq %r12, %rcx
callq 0x4a85
movl %eax, %r9d
cltq
cmpq %rax, 0x40(%r15)
jbe 0x5f74
movq (%r15), %rax
movq 0x8(%r15), %rcx
movl 0x8(%rax), %edi
movl 0xa0(%r15), %esi
movq %r12, %rdx
movq %r9, %r13
callq 0x4899
movq %r13, %r9
testl %eax, %eax
movq 0x8(%rsp), %rsi
js 0x5f0b
jmp 0x5c70
movq 0x8(%rsp), %rsi
movl %r13d, %eax
jmp 0x5c70