// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, %rdi
callq 0x20a0
movslq %eax, %r13
cmpq %r13, 0x48(%r15)
jae 0x4ee1
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 0x21c0
movq %rax, 0x50(%r15)
leaq 0x40(%r15), %r12
movq %r13, 0x40(%r15)
xorl %eax, %eax
testl %r13d, %r13d
cmovlel %eax, %r13d
leaq 0x16277(%rip), %rcx     # 0x1b170
xorl %edx, %edx
cmpq %rdx, %r13
je 0x4f71
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 0x4f4e
movsbl (%rbx,%rdx), %r9d
addl $-0x21, %r9d
cmpl %ebp, %r9d
movl $0x88, %r9d
cmovll %eax, %r9d
jmp 0x4f51
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
jmp 0x4efb
movq (%r12), %rax
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rcx, %rax
je 0x4f8f
movq 0x50(%r15), %rsi
btl $0x6, (%rsi,%rcx,8)
adcl $0x0, %edx
incq %rcx
jmp 0x4f79
cvtsi2sd %edx, %xmm0
cvtsi2sd %rax, %xmm1
mulsd 0xf4f8(%rip), %xmm1     # 0x14498
ucomisd %xmm1, %xmm0
jbe 0x4fad
pushq $0x2
jmp 0x5257
movq (%r15), %rax
movq 0x8(%r15), %rcx
movl 0x8(%rax), %edi
movl 0x10(%rax), %esi
movq %r12, %rdx
callq 0x40d7
movq (%r15), %rax
movl 0x8(%rax), %ebp
movl %ebp, %edi
movq %r12, %rsi
callq 0x4234
testq %rax, %rax
je 0x510a
movq %rax, %r13
movq %rax, %rcx
shrq $0x20, %rcx
movq $0x0, 0x8(%rsp)
leaq 0x70(%r15), %rdx
movl 0x40(%r15), %r8d
leaq 0x18(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
callq 0x52cb
movl %eax, %ebp
testl %eax, %eax
js 0x5248
movq %r12, %rdi
callq 0x5c5a
leaq 0x88(%r15), %rdx
movl 0x40(%r15), %r8d
movl %r8d, %ecx
subl %r13d, %ecx
leaq 0x1c(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %rdx, 0x10(%rsp)
callq 0x52cb
movl %eax, %r13d
testl %eax, %eax
js 0x525b
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
shlq $0x38, %rcx
addl %ebp, %r13d
andl $0xffffff, %r13d        # imm = 0xFFFFFF
shlq $0x20, %r13
orq %rcx, %r13
movq 0x10(%rsp), %rdi
callq 0x5c5a
movq %r12, %rdi
callq 0x5c5a
xorl %eax, %eax
movq (%r12), %r8
cmpq %rax, %r8
jbe 0x5171
movq 0x50(%r15), %rcx
movq 0x80(%r15), %rdx
movb (%rdx,%rax,8), %sil
andb $0x7, %sil
movq 0x98(%r15), %rdx
movb (%rdx,%rax,8), %dil
andb $0x7, %dil
cmpb %dil, %sil
jne 0x50d3
movb (%rcx,%rax,8), %dl
movl %edx, %edi
andb $0x7, %dil
cmpb $0x4, %sil
movzbl %dil, %edi
movzbl %sil, %esi
cmovael %edi, %esi
andb $-0x8, %dl
orb %sil, %dl
jmp 0x50ff
cmpb $0x4, %dil
jb 0x50de
movb (%rcx,%rax,8), %dl
jmp 0x50f9
movb (%rcx,%rax,8), %dl
cmpb $0x4, %sil
jb 0x50ef
andb $-0x8, %dl
orb %dil, %dl
jmp 0x50ff
movl %edx, %esi
shrb $0x4, %sil
andb $0x7, %sil
andb $-0x8, %dl
orb %sil, %dl
movb %dl, (%rcx,%rax,8)
incq %rax
jmp 0x507f
xorl %r13d, %r13d
movl %ebp, %edi
movq %r12, %rsi
movl %r13d, %edx
leaq 0x18(%rsp), %rcx
callq 0x3ff9
movl %eax, %r13d
cltq
cmpq %rax, (%r12)
jbe 0x5255
movq (%r15), %rax
movq 0x8(%r15), %rcx
movl 0x8(%rax), %edi
movl 0xa0(%r15), %esi
leaq 0x18(%rsp), %rdx
callq 0x3e16
testl %eax, %eax
jns 0x528f
movq (%r15), %rax
movl 0x8(%rax), %ebp
movl %ebp, %eax
sarl %eax
leal (%rax,%r13), %ecx
movslq %ecx, %rcx
cmpq %rcx, 0x40(%r15)
jbe 0x5255
subl %eax, %r13d
jmp 0x510d
orq 0x8(%rsp), %r13
xorl %eax, %eax
leaq 0xf23a(%rip), %rcx      # 0x143b9
leaq 0xf328(%rip), %rdx      # 0x144ae
leaq 0xf31b(%rip), %rsi      # 0x144a8
movabsq $-0xfffc0001, %rdi      # imm = 0xFFFFFFFF0003FFFF
cmpq %rax, %r8
jbe 0x527d
movq 0x50(%r15), %r8
movzbl (%r8,%rax,8), %r9d
movl %r9d, %r8d
shrb $0x4, %r8b
xorb %r9b, %r8b
testb $0x7, %r8b
je 0x51df
leal 0x10(%r13), %r11d
andl $0x3fff0, %r11d         # imm = 0x3FFF0
movq %r13, %r10
andq $-0x3fff1, %r10         # imm = 0xFFFC000F
orq %r11, %r10
testb $0x8, %r9b
jne 0x51e4
movq %rsi, %r11
movq %r10, %r13
jmp 0x51fb
movq %rcx, %r11
jmp 0x51fb
addl $0x40000, %r13d         # imm = 0x40000
andl $0xfffc0000, %r13d      # imm = 0xFFFC0000
andq %rdi, %r10
orq %r10, %r13
movq %rsi, %r11
andl $0x7, %r9d
movb (%r11,%r9), %r9b
movb %r9b, (%r14,%rax)
testq %rbx, %rbx
je 0x523c
movq 0x50(%r15), %r9
movzbl (%r9,%rax,8), %r9d
testb $0x7, %r8b
je 0x5229
shrb $0x4, %r9b
andb $0x7, %r9b
addb $0x22, %r9b
jmp 0x5238
btl $0x3, %r9d
movq %rdx, %r8
adcq $0x0, %r8
movb (%r8), %r9b
movb %r9b, (%rbx,%rax)
incq %rax
movq (%r12), %r8
jmp 0x5197
xorl %eax, %eax
cmpl $-0x3, %ebp
sete %al
cmpl $-0x2, %ebp
jmp 0x5268
pushq $0x3
popq %r13
jmp 0x527d
xorl %eax, %eax
cmpl $-0x3, %r13d
sete %al
cmpl $-0x2, %r13d
leaq 0x1(,%rax,4), %rax
pushq $0x4
popq %r13
cmovneq %rax, %r13
orq 0x8(%rsp), %r13
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %ecx
andb $0x3, %cl
movq 0x50(%r15), %rdx
shrl $0x2, %eax
movl %r13d, %esi
subl %eax, %esi
movslq %esi, %rax
movb (%rdx,%rax,8), %sil
andb $-0x8, %sil
orb %cl, %sil
movb %sil, (%rdx,%rax,8)
incl %r13d
movq (%r15), %rax
movl %r13d, %ecx
subl 0x8(%rax), %ecx
pushq $0x8
popq %rax
movq %rax, 0x8(%rsp)
jmp 0x4fee