// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %r9, %rbp
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, 0x58(%rsp)
movq %rdi, %r12
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r9)
movups %xmm0, (%r9)
movq $0x0, 0x20(%r9)
testq %r8, %r8
je 0x8ec0
movq %r8, %rax
movq $0x0, 0x8(%rsp)
jmp 0x8ef0
movl $0x1, %edi
movl $0xb0, %esi
callq 0x2190
movq %rax, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x2190
movq %rax, 0xa8(%rbx)
movq %rbx, %rax
movq %rbx, 0x8(%rsp)
movq %rax, (%rsp)
movq 0xa8(%rax), %rbx
testq %rbx, %rbx
je 0x8f30
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x8f30
movl (%rbx), %eax
movl %eax, %ecx
shrl $0x2, %ecx
andl $-0x4, %ecx
cmpl $0x10, %eax
movl $0x4, %edx
cmovael %ecx, %edx
movl $0xaa, %esi
callq 0x2140
movq $0x0, 0x4(%rbx)
movq (%r14), %rdi
movq (%r15), %rsi
movl 0x38(%r12), %edx
movq %r15, 0x10(%rsp)
movq (%rsp), %r15
movq %r15, %rcx
callq 0x7a17
leaq 0x48(%r15), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x7b60
movq %r12, %rdi
movq %r14, 0x50(%rsp)
movq 0x58(%rsp), %r14
movq %r14, %rsi
movq %r15, %rdx
callq 0x9352
movq %rax, 0x60(%rsp)
movl %edx, 0x18(%rsp)
leaq 0x60(%r15), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x7b60
movq %r13, %rdi
movq %r15, %rsi
callq 0x7b60
movq %r13, %rdi
callq 0x7c3e
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x9352
movq %rax, %r14
movl %edx, 0x2c(%rsp)
movq %r13, %rdi
callq 0x7c3e
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8d77
movl %eax, 0x1c(%rbp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x7b60
movq 0x60(%rsp), %rcx
movq %rcx, %rax
shrq $0x20, %rax
movl %eax, 0x8(%rbp)
movl 0x18(%rsp), %eax
movl %eax, 0x10(%rbp)
movq %r14, %rax
shrq $0x20, %rax
movl %eax, 0xc(%rbp)
movl 0x2c(%rsp), %eax
movl %eax, 0x14(%rbp)
addl %ecx, %r14d
movl %r14d, 0x18(%rbp)
movq 0x48(%r15), %rax
cmpq (%r15), %rax
movq %r13, 0x20(%rsp)
jbe 0x903c
movq 0x50(%rsp), %rbx
movq (%rbx), %rdi
incq %rax
movq %rax, %rsi
callq 0x2260
movq %rax, (%rbx)
movq 0x10(%rsp), %r14
movq (%r14), %rdi
movq (%r13), %rsi
incq %rsi
callq 0x2260
jmp 0x9057
movq 0x10(%rsp), %r14
cmpq $0x0, (%r14)
jne 0x905a
incq %rax
movl $0x1, %esi
movq %rax, %rdi
callq 0x2190
movq %rax, (%r14)
movq (%rsp), %rcx
movq 0xa8(%rcx), %rax
movq %rax, 0x18(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x48(%rcx), %rax
testq %rax, %rax
movq %rbp, 0x48(%rsp)
je 0x9185
movq 0x58(%rcx), %rcx
addq $0x5, %rcx
movb $0x0, (%rcx)
addq $0xc, %rcx
decq %rax
jne 0x908c
leaq 0x30(%rsp), %rax
movq (%rax), %r13
movq 0x8(%rax), %rbx
xorl %r14d, %r14d
movl $0x5, %r15d
xorl %ebp, %ebp
movq (%rsp), %rax
movq 0x58(%rax), %rax
leaq (%r14,%r14,2), %rcx
movzwl (%rax,%rcx,4), %eax
andl $0xf, %eax
cmpw $0x4, %ax
jb 0x90d9
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %ebp, %ebp
jmp 0x911f
incl %ebp
movb (%r12), %cl
addb %cl, %cl
shlq $0x2, %r13
movq $-0x1, %rdx
shlq %cl, %rdx
notq %rdx
andq %r13, %rdx
orq %rax, %rdx
movq %rdx, 0x30(%rsp)
movzwl %ax, %eax
movl $0x3, %esi
subl %eax, %esi
movslq %esi, %rax
addb $-0x2, %cl
shlq %cl, %rax
shrq $0x2, %rbx
orq %rax, %rbx
movq %rbx, 0x38(%rsp)
movq %rdx, %r13
movq (%r12), %rsi
movswl %si, %edi
cmpl %edi, %ebp
jl 0x916d
sarl $0x10, %esi
leaq 0x30(%rsp), %rdx
movq 0x58(%rsp), %rcx
movq 0x18(%rsp), %r8
callq 0xa96d
testl %eax, %eax
js 0x916d
cmpw $0x0, (%r12)
jle 0x916d
movq (%rsp), %rax
movq 0x58(%rax), %rax
addq %r15, %rax
xorl %ecx, %ecx
incb (%rax)
incq %rcx
movswq (%r12), %rdx
addq $-0xc, %rax
cmpq %rdx, %rcx
jl 0x915a
incq %r14
movq 0x20(%rsp), %rax
movq (%rax), %rax
addq $0xc, %r15
cmpq %r14, %rax
ja 0x90af
testq %rax, %rax
je 0x91d0
movq (%rsp), %r13
movq 0x58(%r13), %rcx
movswl (%r12), %edx
addl $-0x3, %edx
addq $0x5, %rcx
xorl %ebx, %ebx
movb $0x1, %sil
movq 0x48(%rsp), %r15
movq 0x20(%rsp), %r12
movzbl (%rcx), %edi
cmpl %edi, %edx
setg %dil
setle %r8b
andb %sil, %r8b
movzbl %r8b, %esi
addl %esi, %ebx
addq $0xc, %rcx
movl %edi, %esi
decq %rax
jne 0x91ad
jmp 0x91e0
xorl %ebx, %ebx
movq 0x48(%rsp), %r15
movq (%rsp), %r13
movq 0x20(%rsp), %r12
cmpl $0x6, 0x1afe9(%rip)     # 0x241d0
movq 0x50(%rsp), %r14
jge 0x9342
movl %ebx, 0x20(%r15)
movl $0x1, %eax
testl %ebx, %ebx
movq 0x10(%rsp), %r11
je 0x9224
movslq 0x10(%r15), %rdx
movq (%r12), %rcx
cmpq %rdx, %rcx
movq 0x8(%rsp), %rdi
jb 0x9229
movslq 0x14(%r15), %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
setb %al
jmp 0x9229
movq 0x8(%rsp), %rdi
movl %eax, 0x24(%r15)
cmpq $0x0, (%r12)
je 0x930f
xorl %ecx, %ecx
leaq 0x13174(%rip), %rdx     # 0x1c3b5
leaq 0x134a4(%rip), %rsi     # 0x1c6ec
xorl %eax, %eax
movq 0x58(%r13), %rbx
movzwl (%rbx,%rcx), %r8d
cmpl $0xfff, %r8d            # imm = 0xFFF
ja 0x927d
movq 0x10(%r13), %r9
movslq 0x8(%rbx,%rcx), %r10
leaq (%r10,%r10,2), %r10
testb $0xc, (%r9,%r10,4)
je 0x927d
movq (%r14), %r8
movb $0x4e, (%r8,%rax)
movb $0x21, %r9b
jmp 0x92f5
movq 0x10(%r13), %r9
movslq 0x8(%rbx,%rcx), %r10
leaq (%r10,%r10,2), %r10
xorw (%r9,%r10,4), %r8w
testb $0xf, %r8b
je 0x92a2
incl (%r15)
movzbl 0x2(%r9,%r10,4), %r8d
addl %r8d, 0x4(%r15)
leaq (%r9,%r10,4), %r9
movzwl (%rbx,%rcx), %r8d
movzwl (%r9), %r10d
xorw %r8w, %r10w
movq %rdx, %r9
testb $0xf, %r10b
je 0x92bf
movq %rsi, %r9
andl $0xf, %r8d
movb (%r9,%r8), %r8b
movq (%r14), %r9
movb %r8b, (%r9,%rax)
xorl %r8d, %r8d
cmpw $0x1000, (%rbx,%rcx)    # imm = 0x1000
leaq (%rbx,%rcx), %r9
setae %r8b
movzbl 0x2(%r9,%r8,2), %r9d
cmpb $0x21, %r9b
jb 0x92f1
movl $0x21, %r9d
addb $0x21, %r9b
movq (%r11), %r8
movb %r9b, (%r8,%rax)
incq %rax
addq $0xc, %rcx
cmpq %rax, (%r12)
ja 0x924a
jmp 0x9311
xorl %eax, %eax
movq (%r11), %rcx
xorl %edx, %edx
movb %dl, (%rcx,%rax)
movq (%r14), %rcx
movb %dl, (%rcx,%rax)
addq $0x68, %rsp
testq %rdi, %rdi
je 0x9337
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8cf6
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
movq %r13, %rsi
callq 0x27a5
jmp 0x91f2