// File: /workspace/github_c_makefile_star2_O2/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 $0xb8, %rsp
movq 0x10(%rdi), %rax
movq %rax, 0x38(%rsp)
movq 0x18(%rdi), %rax
movq %rax, 0x18(%rsp)
andq $0x0, 0x8(%rsp)
movl %esi, (%rsp)
movq 0x8(%rdi), %r14
testq %r14, %r14
je 0x128ff
movl %ecx, %ebp
movl %edx, %ebx
movq %rdi, 0x78(%rsp)
leaq 0x8(%rdi), %rax
movq %rax, 0x68(%rsp)
testq %r14, %r14
je 0x1223a
leaq 0x8(%r14), %rsi
leaq 0x8(%rsp), %rdi
callq 0x1317c
movq (%r14), %r14
jmp 0x12222
cmpl $0x14, %ebx
pushq $0x14
popq %rax
cmovll %ebx, %eax
movl %eax, 0x4c(%rsp)
movq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x1c583
leaq 0xfa6(%rip), %rsi       # 0x13201
leaq 0x8(%rsp), %rdi
callq 0x131a7
movq 0x8(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rdx
callq 0x1327f
movq %rax, %r12
movq %rax, 0x8(%rsp)
movb $0x1, %al
testq %r12, %r12
je 0x128f7
movl %eax, 0x50(%rsp)
movq 0x78(%rsp), %rax
movl 0x30(%rax), %ebx
movq 0x38(%rax), %r13
movq %r12, %rdi
callq 0x23733
cmpl $0xa, %eax
jl 0x122f1
subq $0x8, %rsp
movq %r12, %rdi
movq 0x40(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl 0x8(%rsp), %ecx
movl %ebx, %r8d
movq %r13, %r9
leaq 0x10(%rsp), %rax
pushq %rax
leaq 0x24(%rsp), %rax
pushq %rax
leaq 0x40(%rsp), %rax
pushq %rax
callq 0x12aff
addq $0x20, %rsp
movq 0x28(%rsp), %rbx
jmp 0x127ac
movl %ebx, 0x4(%rsp)
movl %ebp, 0x48(%rsp)
movq %r12, %rdi
callq 0x23733
movl %eax, %ebx
leal 0x1(%rbx), %ebp
pushq $0x20
popq %rdi
callq 0x28bb0
movq %rax, %r15
movl %ebx, (%rax)
movl %ebp, 0x20(%rsp)
movslq %ebp, %rdi
shlq $0x5, %rdi
callq 0x28a1f
testl %ebx, %ebx
movl $0x0, %r14d
cmovgl %ebx, %r14d
movq %r15, 0x70(%rsp)
movq %rax, 0x40(%rsp)
movq %rax, 0x8(%r15)
shlq $0x5, %r14
xorl %r15d, %r15d
movq %r12, 0x80(%rsp)
cmpq %r15, %r14
je 0x12385
movq 0x40(%rsp), %rbp
movq %r12, 0x28(%rbp,%r15)
movq 0x10(%r12), %rsi
movq 0x20(%r12), %rdx
movl 0x28(%r12), %ecx
subl %edx, %ecx
movl 0x4(%rsp), %edi
callq 0x12d95
movl %eax, 0x3c(%rbp,%r15)
movq 0x8(%r12), %r12
addq $0x20, %r15
jmp 0x1234c
movl 0x20(%rsp), %eax
imull %ebx, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, %r14d
movslq %eax, %rdi
shlq $0x5, %rdi
callq 0x28a1f
movq %rax, %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x88(%rsp)
movq %rcx, 0x18(%rax)
movq 0x40(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x98(%rsp)
xorl %ecx, %ecx
pushq $0x1
popq %rax
movq 0x80(%rsp), %r12
movq %r12, %rbp
movq %r13, 0xa8(%rsp)
movl %r14d, 0x54(%rsp)
testq %rbp, %rbp
je 0x12651
cmpl %r14d, %ecx
jge 0x12930
movq %rax, 0xa0(%rsp)
movq %rax, %rdi
shlq $0x5, %rdi
movq 0x40(%rsp), %rdx
addq %rdx, %rdi
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x10(%rsp)
shlq $0x5, %rax
movq 0x88(%rsp), %rsi
leaq (%rsi,%rax), %rcx
movq %rdx, 0x8(%rsi,%rax)
movl 0x1c(%rdi), %edx
movl %edx, 0x58(%rsp)
movl %edx, 0x10(%rsi,%rax)
movq %rdi, 0x90(%rsp)
movq %rcx, (%rdi)
movq 0x98(%rsp), %r15
cmpq %rbp, %r12
je 0x12624
andl $0x0, 0x30(%rsp)
testq %r13, %r13
je 0x124cc
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rcx
callq 0x12005
movl %eax, %ebx
movq 0x20(%rbp), %rsi
movq 0x28(%rbp), %rdx
movq %r13, %rdi
leaq 0x30(%rsp), %rcx
leaq 0xb4(%rsp), %r8
callq 0x1207f
testl %ebx, %ebx
je 0x12616
movq %r15, 0x20(%rsp)
movl 0x10(%rbp), %r15d
subl 0x18(%r12), %r15d
testq %r13, %r13
je 0x1250c
movq 0x20(%r12), %rsi
movq 0x28(%r12), %rdx
movq %r13, %rdi
leaq 0xb0(%rsp), %rcx
leaq 0x64(%rsp), %r8
callq 0x1207f
movl 0x30(%rsp), %edi
subl 0x64(%rsp), %edi
jmp 0x12514
movq 0x10(%r12), %rax
cmpq 0x10(%rbp), %rax
jae 0x12616
movq 0x18(%r12), %rax
cmpq 0x18(%rbp), %rax
jae 0x12616
movq 0x20(%r12), %rax
cmpq 0x20(%rbp), %rax
jae 0x12616
movq 0x28(%r12), %rax
xorl %ebx, %ebx
cmpq 0x28(%rbp), %rax
setb %bl
jmp 0x12488
movl 0x20(%rbp), %edi
subl 0x28(%r12), %edi
movl 0x10(%rsp), %ecx
cmpl %r14d, %ecx
jge 0x12911
movslq %ecx, %rbx
shlq $0x5, %rbx
addq 0x88(%rsp), %rbx
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rbx)
movl %r15d, %edx
negl %edx
movl %edx, 0x14(%rbx)
testl %r15d, %r15d
js 0x12550
movl 0x58(%rsp), %r13d
jmp 0x125e0
movl 0x28(%rbp), %r14d
subl 0x20(%rbp), %r14d
movl 0x28(%r12), %ecx
subl 0x20(%r12), %ecx
movl %ecx, 0x5c(%rsp)
movl %edi, 0x60(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
movl 0x4(%rsp), %ecx
callq 0x12eb3
movl %eax, %r13d
movl %eax, 0x18(%rbx)
movq 0x10(%rbp), %rsi
movq 0x20(%rbp), %rdx
addl %r15d, %r14d
addl %eax, %r14d
movl 0x4(%rsp), %edi
movl %r14d, %ecx
callq 0x12d95
movl %eax, %r14d
movslq %r13d, %rax
movq 0x10(%r12), %rsi
addq %rax, %rsi
movq 0x20(%r12), %rdx
addq %rax, %rdx
movl 0x5c(%rsp), %ecx
subl %eax, %ecx
movl 0x4(%rsp), %edi
callq 0x12d95
movl 0x60(%rsp), %edi
movl 0x10(%rsp), %ecx
movl %eax, %r13d
addl %r14d, %r13d
movl 0x54(%rsp), %r14d
movq 0x20(%rsp), %rax
subl 0x1c(%rax), %r13d
addl %r15d, %edi
xorl %r15d, %r15d
incl %ecx
movl %ecx, 0x10(%rsp)
movl %r15d, %esi
movl (%rsp), %edx
callq 0x2391e
subl %eax, %r13d
movl %r13d, 0x10(%rbx)
movq 0x90(%rsp), %rcx
movq (%rcx), %rax
movq %rax, (%rbx)
movq %rbx, (%rcx)
movq 0xa8(%rsp), %r13
movq 0x20(%rsp), %r15
movq 0x8(%r12), %r12
addq $0x20, %r15
jmp 0x12448
movq 0x90(%rsp), %rdi
callq 0x1c567
movq 0x8(%rbp), %rbp
movq 0xa0(%rsp), %rax
incq %rax
movq 0x80(%rsp), %r12
movl 0x10(%rsp), %ecx
jmp 0x123e3
movq 0x70(%rsp), %rcx
movq %rcx, 0x30(%rsp)
movq 0x8(%rcx), %rax
movl (%rcx), %ecx
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
leal 0x1(%rcx), %esi
movl $0xc0000001, %edi       # imm = 0xC0000001
pushq $0x1
popq %r8
xorl %edx, %edx
cmpq %rsi, %r8
je 0x126cc
movq %r8, %r9
shlq $0x5, %r9
addq %rax, %r9
movl $0xc0000001, %r10d      # imm = 0xC0000001
xorl %r11d, %r11d
movq %r9, %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x126b4
movq 0x8(%rbx), %r14
movl 0x18(%r14), %ebp
addl 0x10(%rbx), %ebp
cmpl %r10d, %ebp
cmovgl %ebp, %r10d
cmovgq %rbx, %r11
jmp 0x12694
movq %r11, 0x10(%r9)
cmpl %edi, %r10d
cmovgeq %r9, %rdx
movl %r10d, 0x18(%r9)
cmovgl %r10d, %edi
incq %r8
jmp 0x12679
movl 0x18(%rdx), %esi
movl %esi, 0x14(%rsp)
xorl %ebx, %ebx
movl 0x48(%rsp), %ebp
cmpq %rax, %rdx
je 0x1271f
movq 0x8(%rdx), %rsi
movq %rbx, 0x8(%rsi)
andq $0x0, 0x8(%rdx)
movq 0x10(%rdx), %r8
movslq 0x14(%r8), %rdi
movq 0x8(%r8), %rdx
movq %rsi, %rbx
testq %rdi, %rdi
jle 0x126d9
movq 0x8(%rdx), %r9
movslq 0x18(%r8), %r8
subq %r8, %rdi
subq %rdi, 0x28(%r9)
subq %rdi, 0x18(%r9)
addq %r8, 0x20(%rsi)
addq %r8, 0x10(%rsi)
movq %rsi, %rbx
jmp 0x126d9
movq %rbx, %rsi
xorl %edx, %edx
testq %rsi, %rsi
je 0x12738
movq %rsi, %rdi
movq %rdx, (%rsi)
movq 0x8(%rsi), %rsi
movq %rdi, %rdx
jmp 0x12724
addq $0x28, %rax
xorl %edi, %edi
subl $0x1, %ecx
jb 0x12757
movq (%rax), %rdx
testq %rdx, %rdx
je 0x12751
movq %rdi, (%rdx)
movq %rdx, %rdi
addq $0x20, %rax
jmp 0x1273e
callq 0x236b0
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl (%rsp), %ecx
movl 0x4(%rsp), %r8d
movq %r13, %r9
callq 0x11f43
movq %rax, %rbx
movq 0x30(%rsp), %r14
testq %r14, %r14
je 0x127a7
movq 0x8(%r14), %rdi
callq 0x28c2d
movq 0x18(%r14), %rdi
callq 0x28c2d
leaq 0x30(%rsp), %rdi
callq 0x28c3d
movq 0x68(%rsp), %r14
movq %rbx, %rdi
pushq $0x1
popq %rbx
movl %ebx, %esi
callq 0x13696
movq %rax, %rdi
movl %ebx, %esi
callq 0x13352
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x128ed
movl %ebp, %r15d
movl (%rsp), %ebx
cmpl $0x1, %ebx
setne %bpl
movq %rax, %rdi
callq 0x1363f
movq %rax, 0x28(%rsp)
movq %rax, %rdi
pushq $0x1
popq %r13
movl %r13d, %esi
callq 0x13352
movq 0x78(%rsp), %r12
movl 0x30(%r12), %r8d
movq 0x38(%r12), %r9
movq %rax, %rdi
movq 0x38(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl %ebx, %ecx
callq 0x11f43
movq %rax, %rbx
movl 0x50(%rsp), %eax
notb %al
orb %bpl, %al
testb $0x1, %al
jne 0x12843
cmpl $0x0, 0x40(%r12)
jne 0x12843
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %edx
callq 0x11e86
movq %rbx, %rdi
movl %r13d, %esi
callq 0x13696
movq %rax, %rbx
leaq 0xa2318(%rip), %rax     # 0xb4b70
movl (%rax), %esi
cmpl $0xb71b0, %esi          # imm = 0xB71B0
je 0x1288b
movl 0x30(%r12), %r8d
movq %rbx, %rdi
leaq 0x14(%rsp), %rdx
movl (%rsp), %ecx
movq 0x18(%rsp), %r9
leaq 0x8(%rsp), %rax
pushq %rax
pushq 0x38(%r12)
callq 0x1210f
addq $0x10, %rsp
cmpl $0x0, 0x30(%r12)
movl %r15d, %ebp
jne 0x1289e
movq %rbx, %rdi
callq 0x1362b
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x13352
movq %rax, %rbx
movq %rax, 0x28(%rsp)
movl 0x4c(%rsp), %eax
cmpl %eax, 0x14(%rsp)
jl 0x128e3
pushq $0x10
popq %rdi
callq 0x28bb0
movq %rbx, 0x8(%rax)
movq (%r14), %rcx
movq %rcx, (%rax)
movq %rax, (%r14)
cmpl $0x2, %ebp
jl 0x128ed
decl %ebp
movq 0x8(%rsp), %r12
xorl %eax, %eax
jmp 0x1228b
leaq 0x28(%rsp), %rdi
callq 0x23624
leaq 0x8(%rsp), %rdi
callq 0x23624
movq %r14, %rdi
callq 0x1c567
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6ab80(%rip), %rdi     # 0x7d498
leaq 0x6ab64(%rip), %rsi     # 0x7d483
leaq 0x6ab8c(%rip), %rcx     # 0x7d4b2
movl $0x18e, %edx            # imm = 0x18E
callq 0x6460
leaq 0x6ab61(%rip), %rdi     # 0x7d498
leaq 0x6ab45(%rip), %rsi     # 0x7d483
leaq 0x6ab6d(%rip), %rcx     # 0x7d4b2
movl $0x169, %edx            # imm = 0x169
callq 0x6460