// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x1, -0x48(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x18bcc
jmp 0x18e36
cmpl $0x14, -0x10(%rbp)
jle 0x18bd9
movl $0x14, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x18c0a
movq -0x38(%rbp), %rsi
addq $0x8, %rsi
leaq -0x30(%rbp), %rdi
callq 0x1a870
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x18be5
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x2ab30
leaq -0x30(%rbp), %rdi
leaq 0x1dbe(%rip), %rsi      # 0x1a9e0
callq 0x1a900
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x1ab90
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x18e29
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl 0x30(%rax), %r8d
movq -0x8(%rbp), %rax
movq 0x38(%rax), %r9
leaq -0x40(%rbp), %r11
leaq -0x44(%rbp), %r10
leaq -0x30(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x18e40
movq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x1b4f0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x1ae30
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x18cc6
leaq -0x30(%rbp), %rdi
callq 0x37a70
jmp 0x18e29
movq -0x40(%rbp), %rdi
callq 0x1b400
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x1ae30
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl 0x30(%rax), %r8d
movq -0x8(%rbp), %rax
movq 0x38(%rax), %r9
callq 0x187f0
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x18d37
cmpl $0x1, -0xc(%rbp)
jne 0x18d37
movq -0x8(%rbp), %rax
cmpl $0x0, 0x40(%rax)
jne 0x18d37
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
callq 0x18660
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x1b4f0
movq %rax, -0x40(%rbp)
leaq 0xedf50(%rip), %rax     # 0x106ca0
cmpl $0xb71b0, (%rax)        # imm = 0xB71B0
je 0x18d96
movq -0x40(%rbp), %rdi
leaq 0xedf3d(%rip), %rax     # 0x106ca0
movl (%rax), %esi
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl 0x30(%rax), %r8d
movq -0x28(%rbp), %r9
movq -0x8(%rbp), %rax
movq 0x38(%rax), %r10
leaq -0x44(%rbp), %rdx
leaq -0x30(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x18a50
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x18da9
movq -0x40(%rbp), %rdi
callq 0x1b3d0
movq -0x40(%rbp), %rdi
movl $0x1, %esi
callq 0x1ae30
movq %rax, -0x40(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x10(%rbp), %eax
jl 0x18df0
movl $0x10, %edi
callq 0x40c50
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
movq -0x38(%rbp), %rsi
callq 0x18f00
jmp 0x18e04
leaq -0x40(%rbp), %rdi
callq 0x37a70
leaq -0x30(%rbp), %rdi
callq 0x37a70
jmp 0x18e29
movl $0x0, -0x48(%rbp)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jg 0x18e24
leaq -0x30(%rbp), %rdi
callq 0x37a70
jmp 0x18e29
jmp 0x18c44
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x2aad0
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)