// File: /workspace/github_c_makefile_star2_O2/lh3[P]fermi2/correct.c
// Function: fmc_correct1
void fmc_correct1(const fmc_opt_t *opt, fmc_hash_t **h, char **s, char **q, fmc_aux_t *a, fmc_ecstat_t *ecs)
{
	fmc_aux_t *_a = 0;
	int i;
	correct1_stat_t st[2];

	memset(ecs, 0, sizeof(fmc_ecstat_t));
	if (a == 0) a = _a = fmc_aux_init();
	kh_clear(kache, a->cache);
	fmc_seq_conv(*s, *q, opt->defQ, &a->ori);
	// forward strand
	fmc_seq_cpy_no_del(&a->seq, &a->ori);
	st[0] = fmc_correct1_aux(opt, h, a);
	fmc_seq_cpy_no_del(&a->ec_for, &a->seq);
	// reverse strand
	fmc_seq_cpy_no_del(&a->seq, &a->ori);
	fmc_seq_revcomp(&a->seq);
	st[1] = fmc_correct1_aux(opt, h, a);
	fmc_seq_revcomp(&a->seq);
	ecs->n_conflict = fmc_cns_ungap(&a->ec_for, &a->seq);
	fmc_seq_cpy_no_del(&a->seq, &a->ec_for);
	// generate final stats
	ecs->n_paths[0] = st[0].n_paths; ecs->n_failures[0] = st[0].n_failures;
	ecs->n_paths[1] = st[1].n_paths; ecs->n_failures[1] = st[1].n_failures;
	ecs->penalty = st[0].penalty + st[1].penalty;
	if (a->seq.n > a->ori.n) {
		*s = realloc(*s, a->seq.n + 1);
		*q = realloc(*q, a->seq.n + 1);
	} else if (!*q) *q = calloc(a->seq.n + 1, 1);
	ecs->n_si = kmer_cov(opt, &a->seq, h, a->cache);
	ecs->to_drop = (ecs->n_si == 0 || ecs->n_failures[0] > a->seq.n || ecs->n_failures[1] > a->seq.n);
	// write the sequence
	for (i = 0; i < a->seq.n; ++i) {
		ecbase_t *b = &a->seq.a[i];
		int qual;
		if (b->f || a->ori.a[b->i].b < 4) { // FIXME: this block is not quite right in the presence of gaps.
			if (b->b != a->ori.a[b->i].b)
				++ecs->n_diff, ecs->q_diff += a->ori.a[b->i].q;
			(*s)[i] = b->b == a->ori.a[b->i].b? "ACGTN"[b->b] : "acgtn"[b->b];
			qual = b->f? b->min_diff : b->q;
			(*q)[i] = (qual < FMC_Q_MAX_OUT? qual : FMC_Q_MAX_OUT) + 33;
		} else (*s)[i] = 'N', (*q)[i] = 33;
	}
	(*s)[i] = (*q)[i] = 0;
	if (_a) fmc_aux_destroy(_a);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x8(%rsp)
movq %rdx, %r14
movq %rsi, 0x38(%rsp)
movq %rdi, %r12
pxor %xmm0, %xmm0
movdqu %xmm0, 0x10(%r9)
movdqu %xmm0, (%r9)
movq %r9, 0x30(%rsp)
andq $0x0, 0x20(%r9)
testq %r8, %r8
je 0x794e
movq %r8, %r13
movq $0x0, 0x28(%rsp)
jmp 0x795b
callq 0x7752
movq %rax, %r13
movq %rax, 0x28(%rsp)
movq 0xa8(%r13), %rbx
testq %rbx, %rbx
je 0x7992
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x7992
movl (%rbx), %eax
movl %eax, %ecx
shrl $0x2, %ecx
andl $-0x4, %ecx
cmpl $0x10, %eax
pushq $0x4
popq %rdx
cmovael %ecx, %edx
movl $0xaa, %esi
callq 0x2140
andq $0x0, 0x4(%rbx)
movq (%r14), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movl 0x38(%r12), %edx
movq %r13, %rcx
callq 0x667f
leaq 0x48(%r13), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x67ba
movq %r12, %rdi
movq 0x38(%rsp), %rbp
movq %rbp, %rsi
movq %r13, %rdx
callq 0x7dec
movq %rax, 0x18(%rsp)
movl %edx, (%rsp)
movq %r14, 0x10(%rsp)
leaq 0x60(%r13), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x67ba
movq %r15, %rdi
movq %r13, %rsi
callq 0x67ba
movq %r15, %rdi
callq 0x6886
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x7dec
movq %rax, %r14
movl %edx, 0x24(%rsp)
movq %r15, %rdi
callq 0x6886
movq %rbx, %rdi
movq %r15, %rsi
callq 0x7807
movq 0x30(%rsp), %rbp
movl %eax, 0x1c(%rbp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x67ba
movq 0x18(%rsp), %rcx
movq %rcx, %rax
shrq $0x20, %rax
movl %eax, 0x8(%rbp)
movl (%rsp), %eax
movl %eax, 0x10(%rbp)
movq %r14, %rax
shrq $0x20, %rax
movl %eax, 0xc(%rbp)
movl 0x24(%rsp), %eax
movl %eax, 0x14(%rbp)
addl %ecx, %r14d
movl %r14d, 0x18(%rbp)
movq 0x10(%rsp), %r14
movq 0x48(%r13), %rbx
cmpq (%r13), %rbx
movq %r15, (%rsp)
jbe 0x7aa2
movq (%r14), %rdi
incq %rbx
movq %rbx, %rsi
callq 0x2260
movq %rax, (%r14)
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
movq (%r15), %rsi
incq %rsi
callq 0x2260
movq %rax, (%rbx)
movq (%r15), %rbx
jmp 0x7abc
movq 0x8(%rsp), %r14
cmpq $0x0, (%r14)
jne 0x7abc
leaq 0x1(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x2190
movq %rax, (%r14)
movq 0xa8(%r13), %rax
movq %rax, 0x18(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x40(%rsp)
pushq $0x5
popq %rax
movq %rbx, %rcx
subq $0x1, %rcx
jb 0x7aec
movq 0x58(%r13), %rdx
movb $0x0, (%rdx,%rax)
addq $0xc, %rax
jmp 0x7ad8
xorl %r15d, %r15d
pushq $0x5
popq %rsi
xorl %ebp, %ebp
movq %r12, 0x50(%rsp)
cmpq %r15, %rbx
jbe 0x7bbe
movq 0x58(%r13), %rax
imulq $0xc, %r15, %rcx
movzwl (%rax,%rcx), %edx
andl $0xf, %edx
cmpw $0x4, %dx
jb 0x7b2d
pxor %xmm0, %xmm0
movdqa %xmm0, 0x40(%rsp)
movq (%r12), %rbx
movswl %bx, %r14d
xorl %ebp, %ebp
jmp 0x7b61
incl %ebp
movq (%r12), %rbx
movswl %bx, %r14d
movl %r14d, %edi
movq %r15, %r12
movq %r13, %r15
movl %ebp, %r13d
movq %rsi, %rbp
leaq 0x40(%rsp), %rsi
callq 0x9591
movq %rbp, %rsi
movl %r13d, %ebp
movq %r15, %r13
movq %r12, %r15
movq 0x50(%rsp), %r12
cmpl %r14d, %ebp
jl 0x7bab
sarl $0x10, %ebx
movl %r14d, %edi
movq %rsi, %r14
movl %ebx, %esi
leaq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x18(%rsp), %r8
callq 0x95ce
movq %r14, %rsi
testl %eax, %eax
js 0x7bab
movq %rsi, %rax
xorl %ecx, %ecx
movswq (%r12), %rdx
cmpq %rdx, %rcx
jge 0x7bab
movq 0x58(%r13), %rdx
incb (%rdx,%rax)
incq %rcx
addq $-0xc, %rax
jmp 0x7b91
incq %r15
movq (%rsp), %rax
movq (%rax), %rbx
addq $0xc, %rsi
jmp 0x7af9
movb $0x1, %cl
xorl %ebp, %ebp
pushq $0x5
popq %rax
movq 0x10(%rsp), %r14
subq $0x1, %rbx
jb 0x7bf9
movq 0x58(%r13), %rdx
movzbl (%rdx,%rax), %edx
movswl (%r12), %esi
addl $-0x3, %esi
cmpl %edx, %esi
setg %dl
setle %sil
andb %sil, %cl
movzbl %cl, %ecx
addl %ecx, %ebp
addq $0xc, %rax
movl %edx, %ecx
jmp 0x7bca
cmpl $0x6, 0x1a5d0(%rip)     # 0x221d0
jge 0x7d75
movq 0x30(%rsp), %r15
movl %ebp, 0x20(%r15)
pushq $0x1
popq %rax
testl %ebp, %ebp
movq 0x8(%rsp), %r12
je 0x7c3a
movslq 0x10(%r15), %rdx
movq (%rsp), %rbp
movq (%rbp), %rcx
cmpq %rdx, %rcx
jb 0x7c3e
movslq 0x14(%r15), %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
setb %al
jmp 0x7c3e
movq (%rsp), %rbp
movl %eax, 0x24(%r15)
xorl %eax, %eax
leaq 0x1178a(%rip), %rdx     # 0x193d5
pushq $0x21
popq %rsi
movdqa 0x118ba(%rip), %xmm0    # 0x19510
leaq 0x11b57(%rip), %rdi     # 0x197b4
xorl %ecx, %ecx
cmpq %rcx, (%rbp)
jbe 0x7d3e
movq 0x10(%r13), %r10
movq 0x58(%r13), %r8
movzwl (%r8,%rax), %r9d
movslq 0x8(%r8,%rax), %r11
imulq $0xc, %r11, %r11
movzwl (%r10,%r11), %ebx
cmpq $0xfff, %r9             # imm = 0xFFF
ja 0x7ca8
movl %ebx, %ebp
andl $0xc, %ebp
movq (%rsp), %rbp
je 0x7ca8
movq (%r14), %r8
movb $0x4e, (%r8,%rcx)
movb $0x21, %r8b
jmp 0x7d2a
xorl %r9d, %ebx
testb $0xf, %bl
je 0x7cf4
movzbl 0x2(%r10,%r11), %r9d
movq (%r15), %xmm1
movd %r9d, %xmm2
movdqa %xmm0, %xmm3
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
paddd %xmm1, %xmm3
movq %xmm3, (%r15)
movzwl (%r8,%rax), %r9d
movzwl (%r10,%r11), %r11d
xorw %r9w, %r11w
movq %rdx, %r10
testb $0xf, %r11b
je 0x7ceb
movq %rdi, %r10
andl $0xf, %r9d
addq %r10, %r9
jmp 0x7cfb
andl $0xf, %r9d
addq %rdx, %r9
movb (%r9), %r9b
movq (%r14), %r10
movb %r9b, (%r10,%rcx)
xorl %r9d, %r9d
cmpw $0x1000, (%r8,%rax)     # imm = 0x1000
leaq (%r8,%rax), %r8
setae %r9b
movzbl 0x2(%r8,%r9,2), %r8d
cmpb $0x21, %r8b
jb 0x7d26
movl %esi, %r8d
addb $0x21, %r8b
movq (%r12), %r9
movb %r8b, (%r9,%rcx)
incq %rcx
addq $0xc, %rax
jmp 0x7c5f
movq (%r12), %rax
xorl %edx, %edx
movb %dl, (%rax,%rcx)
movq (%r14), %rax
movb %dl, (%rax,%rcx)
movq 0x28(%rsp), %rdi
addq $0x58, %rsp
testq %rdi, %rdi
je 0x7d6a
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7786
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1a27c(%rip), %r15     # 0x21ff8
movq (%r15), %rcx
leaq 0x11f64(%rip), %rdi     # 0x19cea
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
callq 0x2310
leaq 0x11e96(%rip), %rbx     # 0x19c2e
xorl %r12d, %r12d
xorl %r14d, %r14d
movq (%rsp), %rax
cmpq %r14, (%rax)
jbe 0x7dd7
testq %r12, %r12
je 0x7db7
movq (%r15), %rsi
pushq $0x2c
popq %rdi
callq 0x2170
movq (%r15), %rdi
movq 0x58(%r13), %rax
movzbl 0x5(%rax,%r12), %edx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x21c0
incq %r14
addq $0xc, %r12
jmp 0x7d9e
movq (%r15), %rsi
pushq $0xa
popq %rdi
callq 0x2170
movq 0x10(%rsp), %r14
jmp 0x7c06