// File: /workspace/github_c_makefile_star2_O0/annoroad[P]fqtools_plus/cutadapt.c
// Function: alignread
static void alignread(adapter_* adapter)
{

	int m = adapter->m;
	int n = adapter->n;
	Entry_* column = adapter->columns;

	int i, j, best_i, best_j, best_cost, best_matches, best_origin;

	for (i = 0; i <= m; i++) {
		column[i].matches = 0;
		column[i].cost = i * DELETION_COST;
		column[i].origin = 0;
	}

	best_i = m;
	best_j = 0;
	best_cost = column[m].cost;
	best_matches = 0;
	best_origin = column[m].origin;

	// maximum no. of errors
	int k = error_rate * m;
	int last = k + 1;
	int match;
	int cost_diag;
	int cost_deletion;
	int cost_insertion;
	int origin, cost, matches;
	for (j = 1; j <= n; j++) {
		Entry_ tmp_entry = column[0];
		column[0].cost = 0;
		column[0].origin = j;
		column[0].matches = 0;
		for (i = 1; i <= last; ++i) {

			match = (((adapter->s1)[i-1] == (adapter->s2)[j-1]) || ((adapter->s1)[i-1] == 'N'));
			cost_diag = tmp_entry.cost + (match?MATCH_COST : MISMATCH_COST);
			cost_deletion = column[i].cost + DELETION_COST;
			cost_insertion = column[i-1].cost + INSERTION_COST;

			if (cost_diag <= cost_deletion && cost_diag <= cost_insertion) {
				// MATCH or MISMATCH
				cost = cost_diag;
				origin = tmp_entry.origin;
				matches = tmp_entry.matches + match;
			} else if (cost_insertion <= cost_deletion) {
				// INSERTION
				cost = cost_insertion;
				origin = column[i-1].origin;
				matches = column[i-1].matches;
			} else {
				// DELETION
				cost = cost_deletion;
				origin = column[i].origin;
				matches = column[i].matches;
			}
			//memcpy(&tmp_entry,column[i],l);
			tmp_entry = column[i];
			// remember current cell for next iteration
			column[i].cost = cost;
			column[i].origin = origin;
			column[i].matches = matches;

		}

		while (column[last].cost > k) {
			last--;
		}
		if (last < m) {
			last++;
		} else {
		
			int length = m + min(column[m].origin, 0);
			cost = column[m].cost;
			matches = column[m].matches;
			if (cost <= length * error_rate && (matches > best_matches || (matches == best_matches && cost < best_cost))) {
				// update
				best_matches = matches;
				best_cost = cost;
				best_origin = column[m].origin;
				best_i = m;
				best_j = j;
			}

		}
		// column finished
	}


	for (i = 0; i <= m; ++i) {
		int length = i + min(column[i].origin, 0);
		int cost = column[i].cost;
		int matches = column[i].matches;
		if (cost <= length * error_rate && (matches > best_matches || (matches == best_matches && cost < best_cost))) {
			best_matches = matches;
			best_cost = cost;
			best_origin = column[i].origin;
			best_i = i;
			best_j = n;
		}
	}


	if (best_origin >= 0) {
		adapter->result->start1 = 0;
		adapter->result->start2 = best_origin;
	} else {
		adapter->result->start1 = -best_origin;
		adapter->result->start2 = 0;
	}
	adapter->result->stop1 = best_i;
	adapter->result->stop2 = best_j;
	adapter->result->matches = best_matches;
	adapter->result->errors = best_cost;
	// return (start1, stop1, start2, stop2, matches, errors)
}

// Assembly:
pushq %rax
movq %rdi, (%rsp)
movq (%rsp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x4(%rsp)
movq (%rsp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x8(%rsp)
movq (%rsp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rsp)
movl $0x0, -0x14(%rsp)
movl -0x14(%rsp), %eax
cmpl -0x4(%rsp), %eax
jg 0x8c00
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x4(%rax)
movl -0x14(%rsp), %ecx
shll $0x0, %ecx
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x8(%rax)
movl -0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rsp)
jmp 0x8b9f
movl -0x4(%rsp), %eax
movl %eax, -0x1c(%rsp)
movl $0x0, -0x20(%rsp)
movq -0x10(%rsp), %rax
movslq -0x4(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x24(%rsp)
movl $0x0, -0x28(%rsp)
movq -0x10(%rsp), %rax
movslq -0x4(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rsp)
cvtsi2sdl -0x4(%rsp), %xmm1
movsd 0x25eb(%rip), %xmm0     # 0xb240
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x30(%rsp)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rsp)
movl $0x1, -0x18(%rsp)
movl -0x18(%rsp), %eax
cmpl -0x8(%rsp), %eax
jg 0x8fff
movq -0x10(%rsp), %rax
movq (%rax), %rcx
movq %rcx, -0x5c(%rsp)
movl 0x8(%rax), %eax
movl %eax, -0x54(%rsp)
movq -0x10(%rsp), %rax
movl $0x0, (%rax)
movl -0x18(%rsp), %ecx
movq -0x10(%rsp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rsp), %rax
movl $0x0, 0x4(%rax)
movl $0x1, -0x14(%rsp)
movl -0x14(%rsp), %eax
cmpl -0x34(%rsp), %eax
jg 0x8eb7
movq (%rsp), %rax
movl -0x14(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl 0x1c(%rax,%rcx), %ecx
movq (%rsp), %rax
movq 0x220(%rax), %rax
movl -0x18(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movsbl (%rax,%rdx), %edx
movb $0x1, %al
cmpl %edx, %ecx
movb %al, -0x6d(%rsp)
je 0x8d22
movq (%rsp), %rax
movl -0x14(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl 0x1c(%rax,%rcx), %eax
cmpl $0x4e, %eax
sete %al
movb %al, -0x6d(%rsp)
movb -0x6d(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x38(%rsp)
movl -0x5c(%rsp), %eax
movl -0x38(%rsp), %esi
movl $0x1, %ecx
xorl %edx, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rsp)
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x40(%rsp)
movq -0x10(%rsp), %rax
movl -0x14(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x44(%rsp)
movl -0x3c(%rsp), %eax
cmpl -0x40(%rsp), %eax
jg 0x8db8
movl -0x3c(%rsp), %eax
cmpl -0x44(%rsp), %eax
jg 0x8db8
movl -0x3c(%rsp), %eax
movl %eax, -0x4c(%rsp)
movl -0x54(%rsp), %eax
movl %eax, -0x48(%rsp)
movl -0x58(%rsp), %eax
addl -0x38(%rsp), %eax
movl %eax, -0x50(%rsp)
jmp 0x8e40
movl -0x44(%rsp), %eax
cmpl -0x40(%rsp), %eax
jg 0x8e06
movl -0x44(%rsp), %eax
movl %eax, -0x4c(%rsp)
movq -0x10(%rsp), %rax
movl -0x14(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x48(%rsp)
movq -0x10(%rsp), %rax
movl -0x14(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x50(%rsp)
jmp 0x8e3e
movl -0x40(%rsp), %eax
movl %eax, -0x4c(%rsp)
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x48(%rsp)
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x50(%rsp)
jmp 0x8e40
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x5c(%rsp)
movl 0x8(%rax), %eax
movl %eax, -0x54(%rsp)
movl -0x4c(%rsp), %ecx
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x48(%rsp), %ecx
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl -0x50(%rsp), %ecx
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl -0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rsp)
jmp 0x8cc1
jmp 0x8eb9
movq -0x10(%rsp), %rax
movslq -0x34(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x30(%rsp), %eax
jle 0x8edf
movl -0x34(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rsp)
jmp 0x8eb9
movl -0x34(%rsp), %eax
cmpl -0x4(%rsp), %eax
jge 0x8ef9
movl -0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rsp)
jmp 0x8fed
movl -0x4(%rsp), %eax
movl %eax, -0x74(%rsp)
movq -0x10(%rsp), %rax
movslq -0x4(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jge 0x8f32
movq -0x10(%rsp), %rax
movslq -0x4(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x78(%rsp)
jmp 0x8f3a
xorl %eax, %eax
movl %eax, -0x78(%rsp)
jmp 0x8f3a
movl -0x74(%rsp), %eax
movl -0x78(%rsp), %ecx
addl %ecx, %eax
movl %eax, -0x60(%rsp)
movq -0x10(%rsp), %rax
movslq -0x4(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x4c(%rsp)
movq -0x10(%rsp), %rax
movslq -0x4(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x50(%rsp)
cvtsi2sdl -0x4c(%rsp), %xmm1
cvtsi2sdl -0x60(%rsp), %xmm0
movsd 0x22b5(%rip), %xmm2     # 0xb240
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jb 0x8feb
movl -0x50(%rsp), %eax
cmpl -0x28(%rsp), %eax
jg 0x8fb3
movl -0x50(%rsp), %eax
cmpl -0x28(%rsp), %eax
jne 0x8feb
movl -0x4c(%rsp), %eax
cmpl -0x24(%rsp), %eax
jge 0x8feb
movl -0x50(%rsp), %eax
movl %eax, -0x28(%rsp)
movl -0x4c(%rsp), %eax
movl %eax, -0x24(%rsp)
movq -0x10(%rsp), %rax
movslq -0x4(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rsp)
movl -0x4(%rsp), %eax
movl %eax, -0x1c(%rsp)
movl -0x18(%rsp), %eax
movl %eax, -0x20(%rsp)
jmp 0x8fed
jmp 0x8fef
movl -0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rsp)
jmp 0x8c74
movl $0x0, -0x14(%rsp)
movl -0x14(%rsp), %eax
cmpl -0x4(%rsp), %eax
jg 0x9119
movl -0x14(%rsp), %eax
movl %eax, -0x7c(%rsp)
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jge 0x904e
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x80(%rsp)
jmp 0x9056
xorl %eax, %eax
movl %eax, -0x80(%rsp)
jmp 0x9056
movl -0x7c(%rsp), %eax
movl -0x80(%rsp), %ecx
addl %ecx, %eax
movl %eax, -0x64(%rsp)
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x68(%rsp)
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x6c(%rsp)
cvtsi2sdl -0x68(%rsp), %xmm1
cvtsi2sdl -0x64(%rsp), %xmm0
movsd 0x2199(%rip), %xmm2     # 0xb240
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jb 0x9107
movl -0x6c(%rsp), %eax
cmpl -0x28(%rsp), %eax
jg 0x90cf
movl -0x6c(%rsp), %eax
cmpl -0x28(%rsp), %eax
jne 0x9107
movl -0x68(%rsp), %eax
cmpl -0x24(%rsp), %eax
jge 0x9107
movl -0x6c(%rsp), %eax
movl %eax, -0x28(%rsp)
movl -0x68(%rsp), %eax
movl %eax, -0x24(%rsp)
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rsp)
movl -0x14(%rsp), %eax
movl %eax, -0x1c(%rsp)
movl -0x8(%rsp), %eax
movl %eax, -0x20(%rsp)
jmp 0x9109
movl -0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rsp)
jmp 0x9007
cmpl $0x0, -0x2c(%rsp)
jl 0x913f
movq (%rsp), %rax
movq 0x8(%rax), %rax
movl $0x0, (%rax)
movl -0x2c(%rsp), %ecx
movq (%rsp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0x8(%rax)
jmp 0x915e
xorl %ecx, %ecx
subl -0x2c(%rsp), %ecx
movq (%rsp), %rax
movq 0x8(%rax), %rax
movl %ecx, (%rax)
movq (%rsp), %rax
movq 0x8(%rax), %rax
movl $0x0, 0x8(%rax)
movl -0x1c(%rsp), %ecx
movq (%rsp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0x4(%rax)
movl -0x20(%rsp), %ecx
movq (%rsp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0xc(%rax)
movl -0x28(%rsp), %ecx
movq (%rsp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0x10(%rax)
movl -0x24(%rsp), %ecx
movq (%rsp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0x14(%rax)
popq %rax
retq
nopl (%rax)