// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bwamem.c
// Function: filterCompetingAln
void filterCompetingAln(worker_t * passWorker, int passCount, int passDisable) {
	int seqIdx, alnIdx, bestIdx;
	int currentSeq, readSeq;
	int seqTotal, bestTotal;

	currentSeq = 0;
	bestIdx = 0;
	bestTotal = 0;

	// Iterate through each sequence and alignment
	for (seqIdx = 0 ; seqIdx < passCount - 1 ; seqIdx++) {
        // If filtering disabled, simply mark sequence as best
        if (passDisable) {
            passWorker->regs[seqIdx].active = 1;
            continue;
        }

		// Check if we're in a new sequence or in an alternate frame
		sscanf(passWorker->seqs[seqIdx].name, "%d:", &readSeq);
		if (readSeq != currentSeq) {
			// New sequence - mark best as active in previous sequence
			passWorker->regs[bestIdx].active = 1;

			// Reset search to current sequence
			currentSeq = readSeq;
			bestTotal = 0;
			bestIdx = seqIdx;
		}

        // Aggregate all score totals for this sequence
        seqTotal = 0;
        for (alnIdx = 0 ; alnIdx < passWorker->regs[seqIdx].n ; alnIdx++) {
            seqTotal += passWorker->regs[seqIdx].a[alnIdx].score;
        }

		// Check if current alignment is best so far
		if (seqTotal > bestTotal) {
			bestTotal = seqTotal;
			bestIdx = seqIdx;
		}
	}

	// Filter final sequence
    if (!passDisable) passWorker->regs[bestIdx].active = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1b1f6
cmpl $0x0, -0x10(%rbp)
je 0x1b114
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x1, 0x10(%rax)
jmp 0x1b1e8
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
leaq 0x1f59c(%rip), %rsi     # 0x3a6ce
leaq -0x24(%rbp), %rdx
movb $0x0, %al
callq 0x32d0
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x1b172
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x1, 0x10(%rax)
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x18(%rbp)
movslq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x38(%rcx), %rcx
movslq -0x14(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1b1d2
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1b180
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jle 0x1b1e6
movl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x1b1e8
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1b0de
cmpl $0x0, -0x10(%rbp)
jne 0x1b216
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x1, 0x10(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)