// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
movl $0x1, -0x7c(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0xa0(%rbp)
movl 0x10(%rbp), %edx
leaq 0x21525(%rip), %rax     # 0x33f40
leaq 0x2164e(%rip), %rcx     # 0x34070
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0xa8(%rbp)
cmpl $0x0, 0x18(%rbp)
je 0x12a4c
movl $0x2, -0xac(%rbp)
movl $0x14, -0xb0(%rbp)
jmp 0x12a60
movl $0xa, -0xac(%rbp)
movl $0x0, -0xb0(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x12a81
leaq 0xc50ff(%rip), %rdi     # 0xd7b6d
leaq 0xc52a3(%rip), %rsi     # 0xd7d18
movl $0x2e9, %edx            # imm = 0x2E9
movb $0x0, %al
callq 0x35d40
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x12aaf
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x74(%rbp)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x30(%rbp), %rcx
subl 0x18(%rcx), %eax
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x7c(%rbp)
jne 0x12d0d
cmpq $0x0, -0x60(%rbp)
je 0x12ad4
movl -0x74(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jne 0x12ad4
movl -0x78(%rbp), %eax
cmpl -0x70(%rbp), %eax
je 0x12d0b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x64(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x68(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x6c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x70(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edi
subl -0x6c(%rbp), %edi
movq -0x38(%rbp), %rax
movl 0x18(%rax), %esi
subl -0x70(%rbp), %esi
movq -0xa8(%rbp), %r8
movl -0xac(%rbp), %r9d
leaq -0x50(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x15430
movl -0x64(%rbp), %edi
movl -0x68(%rbp), %esi
movq -0xa8(%rbp), %r8
movl -0xac(%rbp), %r9d
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x15540
movq -0x40(%rbp), %rax
cmpq -0x90(%rbp), %rax
jne 0x12ba8
movq -0x48(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jne 0x12ba8
movq -0x50(%rbp), %rax
cmpq -0x98(%rbp), %rax
jne 0x12ba8
movq -0x40(%rbp), %rax
cmpq -0x90(%rbp), %rax
je 0x12d04
movq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movslq -0xb0(%rbp), %rcx
cmpq %rcx, %rax
jl 0x12d02
movl $0x48, %edi
callq 0x40c50
movq %rax, -0x88(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2a450
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x30(%rax)
movl -0x18(%rbp), %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x20(%rbp), %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x88(%rbp), %rax
movl 0x24(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jg 0x12cd3
jmp 0x12cf2
leaq 0xc50e6(%rip), %rdi     # 0xd7dc0
leaq 0xc5037(%rip), %rsi     # 0xd7d18
movl $0x319, %edx            # imm = 0x319
leaq 0xc50ed(%rip), %rcx     # 0xd7dda
callq 0x6450
movq -0x28(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x119b0
jmp 0x12d04
movl $0x1, -0x7c(%rbp)
jmp 0x12d0d
cmpq $0x0, -0x60(%rbp)
jne 0x12d16
jmp 0x12d67
cmpl $0x0, -0x7c(%rbp)
je 0x12d43
movl -0x74(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x70(%rbp)
movl $0x0, -0x7c(%rbp)
jmp 0x12d55
movl -0x74(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x78(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x70(%rbp)
jmp 0x12d57
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x12a8d
addq $0xb0, %rsp
popq %rbp
retq