// File: /workspace/github_c_makefile_star2_O3/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, %r13
movslq %r13d, %r12
cmpq %r12, 0x48(%r15)
jae 0x5fa5
leaq -0x1(%r12), %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)
movq 0x8(%rsp), %rax
movq %r12, (%rax)
testl %r12d, %r12d
jle 0x6044
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %eax, %eax
leaq 0x171aa(%rip), %rcx     # 0x1d170
xorl %edx, %edx
movq 0x8(%rsp), %r11
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 0x601b
movsbl (%rbx,%rdx), %r9d
addl $-0x21, %r9d
cmpl %ebp, %r9d
movl $0x88, %r9d
cmovll %eax, %r9d
jmp 0x601e
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, %r13
jne 0x5fcd
movq (%r11), %r12
testq %r12, %r12
je 0x6067
movq 0x50(%r15), %rax
xorl %ecx, %ecx
xorl %edx, %edx
btl $0x6, (%rax,%rcx,8)
adcl $0x0, %edx
incq %rcx
cmpq %rcx, %r12
jne 0x6051
cvtsi2sd %edx, %xmm0
jmp 0x606b
xorpd %xmm0, %xmm0
cvtsi2sd %r12, %xmm1
mulsd 0x11420(%rip), %xmm1    # 0x17498
movl $0x2, %r13d
ucomisd %xmm1, %xmm0
movq 0x8(%rsp), %r12
ja 0x637c
movq (%r15), %rax
movq 0x8(%r15), %rcx
movl 0x8(%rax), %edi
movl 0x10(%rax), %esi
movq %r12, %rdx
callq 0x503e
movq (%r15), %rax
movl 0x8(%rax), %ebp
movl %ebp, %edi
movq %r12, %rsi
callq 0x5211
testq %rax, %rax
je 0x62d3
movq %rax, %r13
movq %rax, %rcx
shrq $0x20, %rcx
movq $0x0, (%rsp)
leaq 0x70(%r15), %rdx
movl 0x40(%r15), %r8d
leaq 0x18(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
callq 0x63cb
movl %eax, %ebp
testl %eax, %eax
js 0x634c
movq %r12, %rdi
callq 0x6eff
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 0x63cb
movl %eax, %r13d
testl %eax, %eax
js 0x6359
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
addq (%rsp), %r13
movq 0x10(%rsp), %rdi
callq 0x6eff
movq %r12, %rdi
callq 0x6eff
cmpq $0x0, (%r12)
je 0x637c
xorl %eax, %eax
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 0x61b4
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 0x61e0
cmpb $0x4, %dil
jb 0x61bf
movb (%rcx,%rax,8), %dl
jmp 0x61da
movb (%rcx,%rax,8), %dl
cmpb $0x4, %sil
jb 0x61d0
andb $-0x8, %dl
orb %dil, %dl
jmp 0x61e0
movl %edx, %esi
shrb $0x4, %sil
andb $0x7, %sil
andb $-0x8, %dl
orb %sil, %dl
movb %dl, (%rcx,%rax,8)
incq %rax
movq (%r12), %rcx
cmpq %rax, %rcx
ja 0x616d
testq %rcx, %rcx
je 0x637c
xorl %eax, %eax
leaq 0x111b4(%rip), %rcx     # 0x173b9
leaq 0x112a6(%rip), %rdx     # 0x174b2
movabsq $-0xfffc0001, %rsi      # imm = 0xFFFFFFFF0003FFFF
leaq 0x1128f(%rip), %rdi     # 0x174ac
movq 0x50(%r15), %r8
movzbl (%r8,%rax,8), %r8d
movl %r8d, %r9d
shrb $0x4, %r9b
xorb %r8b, %r9b
testb $0x7, %r9b
je 0x6294
leal 0x10(%r13), %r9d
andl $0x3fff0, %r9d          # imm = 0x3FFF0
movq %r13, %r10
andq $-0x3fff1, %r10         # imm = 0xFFFC000F
orq %r9, %r10
leal 0x40000(%r13), %r9d
andl $0xfffc0000, %r9d       # imm = 0xFFFC0000
movq %r10, %r13
andq %rsi, %r13
orq %r9, %r13
testb $0x8, %r8b
cmoveq %r10, %r13
andl $0x7, %r8d
movb (%r8,%rdi), %r8b
movb %r8b, (%r14,%rax)
testq %rbx, %rbx
je 0x62c1
movq 0x50(%r15), %r8
movb (%r8,%rax,8), %r8b
shrb $0x4, %r8b
andb $0x7, %r8b
addb $0x22, %r8b
jmp 0x62bd
andl $0x7, %r8d
movb (%r8,%rcx), %r8b
movb %r8b, (%r14,%rax)
testq %rbx, %rbx
je 0x62c1
movq 0x50(%r15), %r8
movzbl (%r8,%rax,8), %r8d
btl $0x3, %r8d
movq %rdx, %r8
adcq $0x0, %r8
movb (%r8), %r8b
movb %r8b, (%rbx,%rax)
incq %rax
cmpq %rax, (%r12)
ja 0x621d
jmp 0x637c
leaq 0x18(%rsp), %rcx
movl %ebp, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x4f68
movl %eax, %r13d
cltq
cmpq %rax, (%r12)
jbe 0x6344
leaq 0x18(%rsp), %rbp
movq (%r15), %rax
movq 0x8(%r15), %rcx
movl 0x8(%rax), %edi
movl 0xa0(%r15), %esi
movq %rbp, %rdx
callq 0x4d7c
testl %eax, %eax
jns 0x638e
movq (%r15), %rax
movl 0x8(%rax), %edi
movl %edi, %eax
sarl %eax
leal (%rax,%r13), %ecx
movslq %ecx, %rcx
cmpq %rcx, 0x40(%r15)
jbe 0x6344
subl %eax, %r13d
movq %r12, %rsi
movl %r13d, %edx
movq %rbp, %rcx
callq 0x4f68
movl %eax, %r13d
cltq
cmpq %rax, (%r12)
ja 0x62f4
movl $0x3, %r13d
jmp 0x637c
xorl %eax, %eax
cmpl $-0x3, %ebp
sete %al
cmpl $-0x2, %ebp
jmp 0x6366
xorl %eax, %eax
cmpl $-0x3, %r13d
sete %al
cmpl $-0x2, %r13d
leaq 0x1(,%rax,4), %rax
movl $0x4, %r13d
cmovneq %rax, %r13
orq (%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
movl $0x8, %eax
movq %rax, (%rsp)
jmp 0x60cd