// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/jkOwnLib/supStitch.c
// Function: ssStitch
void ssStitch(struct ssBundle *bundle, enum ffStringency stringency, 
	int minScore, int maxToReturn)
/* Glue together mrnas in bundle as much as possible. Returns number of
 * alignments after stitching. Updates bundle->ffList with stitched
 * together version. */
{
struct dnaSeq *qSeq =  bundle->qSeq;
struct dnaSeq *genoSeq = bundle->genoSeq;
struct ffAli *ffList = NULL;
struct ssFfItem *ffl;
struct ffAli *bestPath;
int score;
boolean firstTime = TRUE;

if (bundle->ffList == NULL)
    return;

/* The score may improve when we stitch together more alignments,
 * so don't let minScore be too harsh at this stage. */
if (minScore > 20)
    minScore = 20;

/* Create ffAlis for all in bundle and move to one big list. */
for (ffl = bundle->ffList; ffl != NULL; ffl = ffl->next)
    {
    ffCat(&ffList, &ffl->ff);
    }
slFreeList(&bundle->ffList);

ffAliSort(&ffList, ffCmpHitsNeedleFirst);
ffList = ffMergeClose(ffList, qSeq->dna, genoSeq->dna);

while (ffList != NULL)
    {

    ssFindBest(ffList, qSeq, genoSeq, stringency, 
    	bundle->isProt, bundle->t3List,
    	&bestPath, &score, &ffList);


    bestPath = ffMergeNeedleAlis(bestPath, TRUE);
    bestPath = ffRemoveEmptyAlis(bestPath, TRUE);
    if (!bestPath)
	{
	ffFreeAli(&ffList);
	break;
	}
    bestPath = ffMergeHayOverlaps(bestPath);
    bestPath = ffRemoveEmptyAlis(bestPath, TRUE);
    bestPath = forceMonotonic(bestPath, qSeq, genoSeq, stringency,
    	bundle->isProt, bundle->t3List);

    if (firstTime && stringency == ffCdna && bundle->avoidFuzzyFindKludge == FALSE)
	{
	/* Only look for middle exons the first time.  Next times
	 * this might regenerate most of the first alignment... */
	bestPath = smallMiddleExons(bestPath, bundle, stringency);
	}
    bestPath = ffMergeNeedleAlis(bestPath, TRUE);
    if (ffIntronMax != ffIntronMaxDefault)
	{
	bestPath = cutAtBigIntrons(bestPath, ffIntronMax, &score, stringency, 
		bundle->isProt, genoSeq, bundle->t3List,
		&ffList);
	}
    if (!bundle->isProt)
	ffSlideIntrons(bestPath);
    bestPath = ffRemoveEmptyAlis(bestPath, TRUE);
    if (score >= minScore)
	{
	AllocVar(ffl);
	ffl->ff = bestPath;
	slAddHead(&bundle->ffList, ffl);
	}
    else
	{
	ffFreeAli(&bestPath);
	ffFreeAli(&ffList);
	break;
	}
    firstTime = FALSE;
    if (--maxToReturn <= 0)
	{
	ffFreeAli(&ffList);
	break;
	}
    }
slReverse(&bundle->ffList);
return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq 0x10(%rdi), %rax
movq %rax, 0x38(%rsp)
movq 0x18(%rdi), %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x8(%rdi), %r14
testq %r14, %r14
je 0x1565e
movl %ecx, %r12d
movl %esi, %r13d
movl %edx, %r15d
movq %rdi, 0x48(%rsp)
leaq 0x8(%rdi), %rbp
leaq 0x10(%rsp), %rbx
leaq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x15fc0
movq (%r14), %r14
testq %r14, %r14
jne 0x14f1b
cmpl $0x14, %r15d
movl $0x14, %eax
cmovll %r15d, %eax
movl %eax, 0x70(%rsp)
movq %rbp, %rdi
callq 0x1fcd6
leaq 0x1104(%rip), %rsi      # 0x16053
movq %rbx, %rdi
callq 0x15fee
movq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdx
callq 0x160e6
movq %rax, 0x10(%rsp)
movb $0x1, %al
movl %eax, 0x30(%rsp)
movq 0x48(%rsp), %r14
movq %rbp, 0x50(%rsp)
movl %r13d, 0x74(%rsp)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x15656
movq %r12, 0x58(%rsp)
movl 0x30(%r14), %ebp
movq 0x38(%r14), %r15
movq %rdi, %r12
callq 0x27fda
cmpl $0xa, %eax
jl 0x14ff4
subq $0x8, %rsp
movq %r12, %rdi
movq 0x40(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl %r13d, %ecx
movl %ebp, %r8d
movq %r15, %r9
pushq %rbx
leaq 0x2c(%rsp), %rax
pushq %rax
leaq 0x18(%rsp), %rax
pushq %rax
callq 0x1587c
addq $0x20, %rsp
movq 0x50(%rsp), %rbp
movq 0x58(%rsp), %r12
jmp 0x154f0
movq %r15, 0x68(%rsp)
movq %r12, 0x60(%rsp)
movq %r12, %rdi
callq 0x27fda
movl %eax, %r15d
leal 0x1(%r15), %ebx
movl $0x20, %edi
callq 0x2dc95
movq %rax, %r14
movl %r15d, (%rax)
movl %ebx, 0x8(%rsp)
movslq %ebx, %rdi
shlq $0x5, %rdi
callq 0x2db04
movq %rax, %rbx
movq %r14, 0x90(%rsp)
movq %rax, 0x8(%r14)
movq %r15, 0x40(%rsp)
testl %r15d, %r15d
jle 0x1508b
movl 0x8(%rsp), %r14d
shlq $0x5, %r14
addq $-0x20, %r14
xorl %r15d, %r15d
movq 0x60(%rsp), %r12
movq %r12, 0x28(%rbx,%r15)
movq 0x10(%r12), %rsi
movq 0x20(%r12), %rdx
movl 0x28(%r12), %ecx
subl %edx, %ecx
movl %ebp, %edi
callq 0x15b3f
movl %eax, 0x3c(%rbx,%r15)
movq 0x8(%r12), %r12
addq $0x20, %r15
cmpq %r15, %r14
jne 0x1505b
movl %ebp, 0xc(%rsp)
movl 0x8(%rsp), %ecx
imull 0x40(%rsp), %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
movl %eax, 0x34(%rsp)
movslq %eax, %rdi
shlq $0x5, %rdi
callq 0x2db04
movq %rax, %rcx
movq 0x90(%rsp), %rax
movq %rcx, 0x98(%rsp)
movq %rcx, 0x18(%rax)
leaq 0x20(%rbx), %rax
movq %rax, 0xa8(%rsp)
xorl %ecx, %ecx
movl $0x1, %eax
movq 0x60(%rsp), %r12
movq 0x68(%rsp), %r15
movq %rbx, 0xb0(%rsp)
cmpl 0x34(%rsp), %ecx
jge 0x1568f
movq %rax, 0xb8(%rsp)
movq %rax, %rsi
shlq $0x5, %rsi
addq %rbx, %rsi
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x8(%rsp)
shlq $0x5, %rax
movq 0x98(%rsp), %rdx
leaq (%rdx,%rax), %rcx
movq %rbx, 0x8(%rdx,%rax)
movl 0x1c(%rsi), %edi
movl %edi, 0x78(%rsp)
movl %edi, 0x10(%rdx,%rax)
movq %rsi, 0xa0(%rsp)
movq %rcx, (%rsi)
movq 0x60(%rsp), %rbp
cmpq %rbp, %r12
je 0x15330
movq 0xa8(%rsp), %r14
movq %r12, 0x40(%rsp)
xorl %eax, %eax
movl %eax, 0x28(%rsp)
movl %eax, 0x8c(%rsp)
testq %r15, %r15
je 0x1519b
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rcx
callq 0x14ce1
movl %eax, %ebx
movq 0x20(%r12), %rsi
movq 0x28(%r12), %rdx
movq %r15, %rdi
leaq 0x28(%rsp), %rcx
leaq 0x8c(%rsp), %r8
callq 0x14d5b
jmp 0x151cc
movq 0x10(%rbp), %rax
xorl %ebx, %ebx
cmpq 0x10(%r12), %rax
jae 0x151cc
movq 0x18(%rbp), %rax
cmpq 0x18(%r12), %rax
jae 0x151cc
movq 0x20(%rbp), %rax
cmpq 0x20(%r12), %rax
jae 0x151cc
movq 0x28(%rbp), %rax
xorl %ebx, %ebx
cmpq 0x28(%r12), %rax
setb %bl
testl %ebx, %ebx
je 0x1531f
movl 0x10(%r12), %ebx
subl 0x18(%rbp), %ebx
testq %r15, %r15
je 0x1520e
movq 0x20(%rbp), %rsi
movq 0x28(%rbp), %rdx
movq %r15, %rdi
leaq 0xc4(%rsp), %rcx
leaq 0x88(%rsp), %r8
callq 0x14d5b
movl 0x28(%rsp), %edi
subl 0x88(%rsp), %edi
jmp 0x15216
movl 0x20(%r12), %edi
subl 0x28(%rbp), %edi
movl 0x8(%rsp), %ecx
cmpl 0x34(%rsp), %ecx
jge 0x15670
movslq %ecx, %r12
shlq $0x5, %r12
addq 0x98(%rsp), %r12
movq %r14, 0x8(%r12)
movl %ebx, %edx
negl %edx
movl %edx, 0x14(%r12)
testl %ebx, %ebx
js 0x1524f
movl 0x78(%rsp), %r15d
jmp 0x152eb
movq 0x40(%rsp), %r15
movl 0x28(%r15), %r13d
subl 0x20(%r15), %r13d
movl 0x28(%rbp), %eax
subl 0x20(%rbp), %eax
movl %eax, 0x80(%rsp)
movl %edi, 0x84(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
movl 0xc(%rsp), %ecx
callq 0x15c93
movl %eax, 0x7c(%rsp)
movl %eax, 0x18(%r12)
movq 0x10(%r15), %rsi
movq 0x20(%r15), %rdx
addl %ebx, %r13d
addl %eax, %r13d
movl 0xc(%rsp), %r15d
movl %r15d, %edi
movl %r13d, %ecx
callq 0x15b3f
movl %eax, %r13d
movslq 0x7c(%rsp), %rax
movq 0x10(%rbp), %rsi
addq %rax, %rsi
movq 0x20(%rbp), %rdx
addq %rax, %rdx
movl 0x80(%rsp), %ecx
subl %eax, %ecx
movl %r15d, %edi
callq 0x15b3f
movl 0x84(%rsp), %edi
movl 0x8(%rsp), %ecx
movl %eax, %r15d
addl %r13d, %r15d
movl 0x74(%rsp), %r13d
subl 0x1c(%r14), %r15d
addl %ebx, %edi
xorl %ebx, %ebx
incl %ecx
movl %ecx, 0x8(%rsp)
movl %ebx, %esi
movl %r13d, %edx
callq 0x28204
subl %eax, %r15d
movl %r15d, 0x10(%r12)
movq 0xa0(%rsp), %rcx
movq (%rcx), %rax
movq %rax, (%r12)
movq %r12, (%rcx)
movq 0x68(%rsp), %r15
movq 0x40(%rsp), %r12
movq 0x8(%rbp), %rbp
addq $0x20, %r14
cmpq %r12, %rbp
jne 0x15158
movq 0xa0(%rsp), %rdi
callq 0x1fcb3
movq 0x8(%r12), %r12
movq 0xb8(%rsp), %rax
incq %rax
testq %r12, %r12
movq 0xb0(%rsp), %rbx
movl 0x8(%rsp), %ecx
jne 0x150ed
movq 0x90(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movq 0x8(%rcx), %rax
movl (%rcx), %ecx
movq %rcx, %rsi
incq %rsi
movl $0xc0000001, %edi       # imm = 0xC0000001
movl $0x1, %r8d
xorl %edx, %edx
movq %r8, %r9
shlq $0x5, %r9
movq (%rax,%r9), %rbx
movl $0xc0000001, %r10d      # imm = 0xC0000001
xorl %r11d, %r11d
testq %rbx, %rbx
je 0x153c2
movq 0x8(%rbx), %r14
movl 0x18(%r14), %ebp
addl 0x10(%rbx), %ebp
cmpl %r10d, %ebp
cmovgq %rbx, %r11
movq (%rbx), %r14
cmovgl %ebp, %r10d
movq %r14, %rbx
testq %r14, %r14
jne 0x153a1
addq %rax, %r9
movq %r11, 0x10(%r9)
movl %r10d, 0x18(%r9)
cmpl %edi, %r10d
cmovgeq %r9, %rdx
cmovgl %r10d, %edi
incq %r8
cmpq %rsi, %r8
jne 0x15388
movl 0x18(%rdx), %esi
movl %esi, 0x1c(%rsp)
xorl %ebx, %ebx
cmpq %rax, %rdx
je 0x1544c
movq 0x50(%rsp), %rbp
movq 0x58(%rsp), %r12
movq 0x48(%rsp), %r15
movl 0xc(%rsp), %r14d
movq %rbx, %rsi
movq 0x8(%rdx), %rbx
movq %rsi, 0x8(%rbx)
movq $0x0, 0x8(%rdx)
movq 0x10(%rdx), %rdx
movslq 0x14(%rdx), %rsi
testq %rsi, %rsi
jle 0x15441
movq 0x8(%rdx), %rdi
movq 0x8(%rdi), %rdi
movslq 0x18(%rdx), %r8
subq %r8, %rsi
subq %rsi, 0x28(%rdi)
subq %rsi, 0x18(%rdi)
addq %r8, 0x20(%rbx)
addq %r8, 0x10(%rbx)
movq 0x8(%rdx), %rdx
cmpq %rax, %rdx
jne 0x15402
jmp 0x15460
movq 0x50(%rsp), %rbp
movq 0x58(%rsp), %r12
movq 0x48(%rsp), %r15
movl 0xc(%rsp), %r14d
testq %rbx, %rbx
je 0x1547c
xorl %esi, %esi
movq %rbx, %rdx
movq %rsi, (%rdx)
movq %rdx, %rsi
movq 0x8(%rdx), %rdi
movq %rdi, %rdx
testq %rdi, %rdi
jne 0x1546a
addq $0x28, %rax
xorl %edi, %edi
movq (%rax), %rdx
testq %rdx, %rdx
je 0x15490
movq %rdi, (%rdx)
movq %rdx, %rdi
addq $0x20, %rax
decl %ecx
jne 0x15482
callq 0x27f4d
movq %rbx, (%rsp)
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %r13d, %ecx
movl %r14d, %r8d
movq 0x68(%rsp), %r9
callq 0x14c1a
movq %rax, (%rsp)
movq 0x28(%rsp), %rbx
testq %rbx, %rbx
je 0x154ed
movq 0x8(%rbx), %rdi
callq 0x2dd41
movq 0x18(%rbx), %rdi
callq 0x2dd41
leaq 0x28(%rsp), %rdi
callq 0x2dd51
movq %r15, %r14
movq (%rsp), %rdi
movl $0x1, %esi
callq 0x16593
movq %rax, (%rsp)
movq %rax, %rdi
movl $0x1, %esi
callq 0x161cb
movq %rax, (%rsp)
testq %rax, %rax
je 0x1564c
cmpl $0x1, %r13d
setne %bl
movq %rax, %rdi
callq 0x16534
movq %rax, (%rsp)
movq %rax, %rdi
movl $0x1, %esi
callq 0x161cb
movq %rax, (%rsp)
movl 0x30(%r14), %r8d
movq 0x38(%r14), %r9
movq %rax, %rdi
movq 0x38(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %r13d, %ecx
callq 0x14c1a
movq %rax, (%rsp)
movl 0x30(%rsp), %ecx
notb %cl
orb %bl, %cl
testb $0x1, %cl
jne 0x15589
cmpl $0x0, 0x40(%r14)
jne 0x15589
movq %rax, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x14b2e
movq %rax, (%rsp)
movq (%rsp), %rdi
movl $0x1, %esi
callq 0x16593
movq %rax, %rbx
movq %rax, (%rsp)
leaq 0xab5cb(%rip), %rax     # 0xc0b70
movl (%rax), %esi
cmpl $0xb71b0, %esi          # imm = 0xB71B0
je 0x155da
movl 0x30(%r14), %r8d
movq %rbx, %rdi
leaq 0x1c(%rsp), %rdx
movl %r13d, %ecx
movq 0x20(%rsp), %r9
leaq 0x10(%rsp), %rax
pushq %rax
pushq 0x38(%r14)
callq 0x14de2
addq $0x10, %rsp
movq %rbx, (%rsp)
cmpl $0x0, 0x30(%r14)
jne 0x155ea
movq (%rsp), %rdi
callq 0x16520
movq (%rsp), %rdi
movl $0x1, %esi
callq 0x161cb
movq %rax, (%rsp)
movl 0x70(%rsp), %eax
cmpl %eax, 0x1c(%rsp)
leaq 0x10(%rsp), %rbx
jl 0x15644
movl $0x10, %edi
callq 0x2dc95
movq (%rsp), %rcx
movq %rcx, 0x8(%rax)
movq (%rbp), %rcx
movq %rcx, (%rax)
movq %rax, (%rbp)
leal -0x1(%r12), %eax
movl $0x0, 0x30(%rsp)
cmpl $0x2, %r12d
movl %eax, %r12d
jge 0x14f8d
jmp 0x1564c
movq %rsp, %rdi
callq 0x27ea8
leaq 0x10(%rsp), %rdi
callq 0x27ea8
movq %rbp, %rdi
callq 0x1fcb3
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x78e41(%rip), %rdi     # 0x8e4b8
leaq 0x78e25(%rip), %rsi     # 0x8e4a3
leaq 0x78e4d(%rip), %rcx     # 0x8e4d2
movl $0x18e, %edx            # imm = 0x18E
callq 0x6460
leaq 0x78e22(%rip), %rdi     # 0x8e4b8
leaq 0x78e06(%rip), %rsi     # 0x8e4a3
leaq 0x78e2e(%rip), %rcx     # 0x8e4d2
movl $0x169, %edx            # imm = 0x169
callq 0x6460