// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/jkOwnLib/gfBlatLib.c
// Function: clumpToHspRange
static void clumpToHspRange(struct gfClump *clump, bioSeq *qSeq, int tileSize,
	int frame, struct trans3 *t3, struct gfRange **pRangeList, 
	boolean isProt, boolean fastMap)
/* Covert clump->hitList to HSPs (high scoring local sequence pair,
 * that is longest alignment without gaps) and add resulting HSPs to
 * rangeList. */
{
struct gfSeqSource *target = clump->target;
aaSeq *tSeq = target->seq;
BIOPOL *qs, *ts, *qe, *te;
struct gfHit *hit;
int qStart = 0, tStart = 0, qEnd = 0, tEnd = 0, newQ = 0, newT = 0;
boolean outOfIt = TRUE;		/* Logically outside of a clump. */
struct gfRange *range;
BIOPOL *lastQs = NULL, *lastQe = NULL, *lastTs = NULL;
int (*scoreMatch)(char a, char b) = (isProt ? aaScore2 : dnaScore2);
int maxDown, minSpan;

if (fastMap)
    {
    maxDown = 2;
    minSpan = 20;
    }
else
    {
    maxDown = 10;
    minSpan = 0;
    }


if (tSeq == NULL)
    internalErr();

/* The termination condition of this loop is a little complicated.
 * We want to output something either when the next hit can't be
 * merged into the previous, or at the end of the list.  To avoid
 * duplicating the output code we're forced to complicate the loop
 * termination logic.  Hence the check for hit == NULL to break
 * the loop is not until near the end of the loop. */
for (hit = clump->hitList; ; hit = hit->next)
    {
    if (hit != NULL)
        {
	newQ = hit->qStart;
	newT = hit->tStart - target->start;
	}

    /* See if it's time to output merged (diagonally adjacent) hits. */
    if (!outOfIt)	/* Not first time through. */
        {
	/* As a micro-optimization handle strings of adjacent hits
	 * specially.  Don't do the extensions until we've merged
	 * all adjacent hits. */
	if (hit == NULL || newQ != qEnd || newT != tEnd)
	    {
	    qs = qSeq->dna + qStart;
	    ts = tSeq->dna + tStart;
	    qe = qSeq->dna + qEnd;
	    te = tSeq->dna + tEnd;
	    extendHitRight(qSeq->size - qEnd, tSeq->size - tEnd,
		&qe, &te, scoreMatch, maxDown);
	    extendHitLeft(qStart, tStart, &qs, &ts, scoreMatch, maxDown);
	    if (qs != lastQs || ts != lastTs || qe != lastQe || qs !=  lastQs)
		{
		lastQs = qs;
		lastTs = ts;
		lastQe = qe;
		if (qe - qs >= minSpan)
		    {
		    AllocVar(range);
		    range->qStart = qs - qSeq->dna;
		    range->qEnd = qe - qSeq->dna;
		    range->tName = cloneString(tSeq->name);
		    range->tSeq = tSeq;
		    range->tStart = ts - tSeq->dna;
		    range->tEnd = te - tSeq->dna;
		    range->hitCount = qe - qs;
		    range->frame = frame;
		    range->t3 = t3;
		    assert(range->tEnd <= tSeq->size);
		    slAddHead(pRangeList, range);
		    }
		}
	    outOfIt = TRUE;
	    }
	}
    if (hit == NULL)
        break;

    if (outOfIt)
        {
	qStart = newQ;
	qEnd = qStart + tileSize;
	tStart = newT;
	tEnd = tStart + tileSize;
	outOfIt = FALSE;
	}
    else
        {
	qEnd = newQ + tileSize;
	tEnd = newT + tileSize;
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r9, 0xa0(%rsp)
movq %r8, 0xa8(%rsp)
movl %ecx, 0x64(%rsp)
movl %edx, %r12d
movq %rsi, 0x70(%rsp)
movq %rdi, %r14
movq 0x10(%rdi), %r15
movq 0x10(%r15), %rax
movq %rax, 0x40(%rsp)
cmpl $0x0, 0x110(%rsp)
jne 0x108dd
leaq 0x14f36(%rip), %rax     # 0x25811
jmp 0x108e4
leaq 0x14fbc(%rip), %rax     # 0x258a0
movq %rax, 0x58(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
cmpl $0x0, 0x118(%rsp)
sete %bl
movl $0x14, %eax
cmoveq %r13, %rax
movq %rax, 0xb0(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x1092c
leaq 0x7d2a2(%rip), %rdi     # 0x8dbbb
leaq 0x7d498(%rip), %rsi     # 0x8ddb8
movl $0x2e9, %edx            # imm = 0x2E9
xorl %eax, %eax
callq 0x26b6f
leal 0x2(,%rbx,8), %eax
movq %rax, 0x88(%rsp)
addq $0x28, %r14
xorl %ecx, %ecx
xorl %eax, %eax
xorl %esi, %esi
xorl %ebp, %ebp
xorl %edx, %edx
xorl %edi, %edi
movq $0x0, 0x48(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movq %r12, 0x68(%rsp)
movq %r15, 0x28(%rsp)
movq (%r14), %r14
testq %r14, %r14
je 0x10984
movl 0x8(%r14), %esi
movl 0xc(%r14), %ebp
subl 0x18(%r15), %ebp
testb $0x1, %dl
je 0x10a84
testq %r14, %r14
je 0x109a0
cmpl %ecx, %esi
jne 0x109a0
movb $0x1, %dl
cmpl %eax, %ebp
je 0x10c9c
movq %rsi, 0x78(%rsp)
movq %r14, 0x50(%rsp)
movq 0x70(%rsp), %rdx
movq 0x10(%rdx), %r9
movq 0x40(%rsp), %rsi
movq 0x10(%rsi), %r8
movslq %ecx, %r10
addq %r9, %r10
movq %r10, 0x98(%rsp)
movslq %eax, %r10
addq %r8, %r10
movq %r10, 0x90(%rsp)
movl 0x18(%rdx), %edx
subl %ecx, %edx
movl 0x18(%rsi), %ecx
subl %eax, %ecx
cmpl %ecx, %edx
cmovll %edx, %ecx
testl %ecx, %ecx
movq %r13, 0x10(%rsp)
movl %edi, 0xc(%rsp)
movq %rbp, 0x80(%rsp)
movq %r8, 0x20(%rsp)
movq %r9, 0x18(%rsp)
jle 0x10a8b
movl %ecx, %ebx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %eax, %eax
movl %eax, %r15d
movq 0x98(%rsp), %rax
movsbl (%rax,%r13), %edi
movq 0x90(%rsp), %rax
movsbl (%rax,%r13), %esi
callq *0x58(%rsp)
addl %r15d, %eax
cmpl %r14d, %eax
jle 0x10a4a
movl %r13d, %ebp
movl %eax, %r14d
jmp 0x10a5c
movq 0x88(%rsp), %rcx
addl %ebp, %ecx
movslq %ecx, %rcx
cmpq %rcx, %r13
jg 0x10a64
incq %r13
cmpq %r13, %rbx
jne 0x10a19
movslq %ebp, %rdx
movq 0x10(%rsp), %r13
movl 0xc(%rsp), %edi
movq 0x80(%rsp), %rbp
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
jmp 0x10a92
xorl %edx, %edx
jmp 0x10c9c
movq $-0x1, %rdx
movslq %edi, %rsi
movslq %r13d, %rcx
cmpl %ecx, %esi
movl %r13d, %eax
cmovll %edi, %eax
testl %eax, %eax
jle 0x10b59
movq %rdx, 0xc8(%rsp)
negl %eax
cltq
movq %rax, 0xd0(%rsp)
movq %rcx, 0xc0(%rsp)
leaq (%r8,%rcx), %rbp
decq %rbp
movq %rsi, 0xb8(%rsp)
leaq (%r9,%rsi), %r13
decq %r13
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %eax, %eax
xorl %r14d, %r14d
movl %eax, %ebx
movsbl (%r13,%r12), %edi
movsbl (%rbp,%r12), %esi
decq %r12
callq *0x58(%rsp)
addl %ebx, %eax
cmpl %r15d, %eax
jle 0x10b09
movl %r12d, %r14d
movl %eax, %r15d
jmp 0x10b1b
movl %r14d, %ecx
subl 0x88(%rsp), %ecx
movslq %ecx, %rcx
cmpq %rcx, %r12
jl 0x10b25
cmpq 0xd0(%rsp), %r12
jg 0x10ae5
movslq %r14d, %rax
movq 0x68(%rsp), %r12
movq 0x80(%rsp), %rbp
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
movq 0xc8(%rsp), %rdx
movq 0xc0(%rsp), %rcx
movq 0xb8(%rsp), %rsi
jmp 0x10b5b
xorl %eax, %eax
addq %rsi, %r9
addq %rcx, %r8
movq 0x98(%rsp), %rcx
leaq (%rcx,%rdx), %r15
incq %r15
addq %rax, %r9
addq %rax, %r8
cmpq 0x48(%rsp), %r9
movq 0x78(%rsp), %rsi
jne 0x10b94
cmpq 0x38(%rsp), %r8
jne 0x10b94
cmpq 0x30(%rsp), %r15
jne 0x10b94
xorl %edx, %edx
jmp 0x10bb5
movq %r15, %rbx
subq %r9, %rbx
cmpq 0xb0(%rsp), %rbx
jge 0x10bc9
xorl %edx, %edx
movq %r9, 0x48(%rsp)
movq %r15, 0x30(%rsp)
movq %r8, 0x38(%rsp)
movq 0x50(%rsp), %r14
movq 0x28(%rsp), %r15
movq 0x10(%rsp), %r13
jmp 0x10c98
movq 0x90(%rsp), %rax
leaq (%rax,%rdx), %r12
incq %r12
movl $0x48, %edi
movq %r8, 0x20(%rsp)
movq %r9, %r13
callq 0x2dc95
movq %rax, %r14
movq 0x70(%rsp), %rax
movl 0x10(%rax), %eax
movq %r13, 0x18(%rsp)
movl %r13d, %ecx
subl %eax, %ecx
movl %ecx, 0x8(%r14)
movl %r15d, %ecx
subl %eax, %ecx
movl %ecx, 0xc(%r14)
movq 0x40(%rsp), %r13
movq 0x8(%r13), %rdi
callq 0x1f9f6
movq 0x20(%rsp), %rsi
movq %rax, 0x10(%r14)
movq %r13, 0x18(%r14)
movl 0x10(%r13), %eax
movl %esi, %ecx
subl %eax, %ecx
movl %ecx, 0x20(%r14)
subl %eax, %r12d
movl %r12d, 0x24(%r14)
movl %ebx, 0x30(%r14)
movl 0x64(%rsp), %eax
movl %eax, 0x34(%r14)
movq 0xa8(%rsp), %rax
movq %rax, 0x38(%r14)
cmpl %r12d, 0x18(%r13)
jl 0x10ccb
movq 0xa0(%rsp), %rcx
movq (%rcx), %rax
movq %rax, (%r14)
movq %r14, (%rcx)
xorl %edx, %edx
movq 0x18(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %r15, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
movq 0x68(%rsp), %r12
movq 0x50(%rsp), %r14
movq 0x28(%rsp), %r15
movq 0x10(%rsp), %r13
movq 0x78(%rsp), %rsi
movl 0xc(%rsp), %edi
testq %r14, %r14
je 0x10cb9
testb %dl, %dl
cmovel %ebp, %r13d
cmovel %esi, %edi
leal (%r12,%rbp), %eax
leal (%rsi,%r12), %ecx
movb $0x1, %dl
jmp 0x10970
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7d18e(%rip), %rdi     # 0x8de60
leaq 0x7d0df(%rip), %rsi     # 0x8ddb8
leaq 0x7d19a(%rip), %rcx     # 0x8de7a
movl $0x319, %edx            # imm = 0x319
callq 0x6460