// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/jkOwnLib/supStitch.c
// Function: ssFindBestBig
static void ssFindBestBig(struct ffAli *ffList, bioSeq *qSeq, bioSeq *tSeq,
	enum ffStringency stringency, boolean isProt, struct trans3 *t3List,
	struct ffAli **retBestAli, int *retScore, struct ffAli **retLeftovers)
/* Go set up things to call chainBlocks to find best way to string together
 * blocks in alignment. */
{
struct cBlock *boxList = NULL, *box, *prevBox;
struct ffAli *ff, *farRight = NULL;
struct lm *lm = lmInit(0);
int boxSize;
DNA *firstH = tSeq->dna;
struct chain *chainList, *chain, *bestChain;
int tMin = BIGNUM, tMax = -BIGNUM;


/* Make up box list for chainer. */
for (ff = ffList; ff != NULL; ff = ff->right)
    {
    lmAllocVar(lm, box);
    boxSize = ff->nEnd - ff->nStart;
    box->qStart = ff->nStart - qSeq->dna;
    box->qEnd = box->qStart + boxSize;
    if (t3List)
        {
	trans3Offsets(t3List, ff->hStart, ff->hEnd, &box->tStart, &box->tEnd);
	}
    else
        {
	box->tStart = ff->hStart - firstH;
	box->tEnd = box->tStart + boxSize;
	}
    box->data = ff;
    box->score = bioScoreMatch(isProt, ff->nStart, ff->hStart, boxSize);
    if (tMin > box->tStart) tMin = box->tStart;
    if (tMax < box->tEnd) tMax = box->tEnd;
    slAddHead(&boxList, box);
    }

/* Adjust boxes so that tMin is always 0. */
for (box = boxList; box != NULL; box = box->next)
    {
    box->tStart -= tMin;
    box->tEnd -= tMin;
    }
tMax -= tMin;

ssStringency = stringency;
ssIsProt = isProt;
chainList = chainBlocks(qSeq->name, qSeq->size, '+', "tSeq", tMax, &boxList,
	ssConnectCost, ssGapCost, NULL, NULL);

/* Fixup crossovers on best (first) chain. */
bestChain = chainList;
prevBox = bestChain->blockList;
for (box = prevBox->next; box != NULL; box = box->next)
    {
    int overlap = findOverlap(prevBox, box);
    if (overlap > 0)
        {
	struct ffAli *left = prevBox->data;
	struct ffAli *right = box->data;
	int crossover = findCrossover(left, right, overlap, isProt);
        int remain = overlap - crossover;
	left->nEnd -= remain;
	left->hEnd -= remain;
	right->nStart += crossover;
	right->hStart += crossover;
	}
    prevBox = box;
    }

/* Copy stuff from first chain to bestAli. */
farRight = NULL;
for (box = chainList->blockList; box != NULL; box = box->next)
    {
    ff = box->data;
    ff->left = farRight;
    farRight = ff;
    }
*retBestAli = ffMakeRightLinks(farRight);

/* Copy stuff from other chains to leftovers. */
farRight = NULL;
for (chain = chainList->next; chain != NULL; chain = chain->next)
    {
    for (box = chain->blockList; box != NULL; box = box->next)
        {
        ff = box->data;
	ff->left = farRight;
	farRight = ff;
	}
    }
*retLeftovers = ffMakeRightLinks(farRight);

*retScore = bestChain->score;
for (chain = chainList; chain != NULL; chain = chain->next)
    chain->blockList = NULL;	/* Don't want to free this, it's local. */
chainFreeList(&chainList);
lmCleanup(&lm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x58(%rsp)
movl %r8d, 0x28(%rsp)
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, 0x30(%rsp)
movq %rdi, %r13
movq $0x0, 0x40(%rsp)
xorl %edi, %edi
callq 0x2c220
movq %rax, 0x50(%rsp)
movq %rax, 0x60(%rsp)
testq %r13, %r13
je 0x159ef
movl %ebp, 0x2c(%rsp)
movq 0x10(%rbx), %rax
movq %rax, 0x48(%rsp)
movl $0x3fffffff, %ebp       # imm = 0x3FFFFFFF
movl $0xc0000001, %r15d      # imm = 0xC0000001
xorl %r12d, %r12d
movl $0x28, %esi
movq 0x50(%rsp), %rdi
callq 0x2c325
movq %rax, %rbx
movl 0x18(%r13), %eax
movq 0x10(%r13), %rsi
movl %eax, %r14d
subl %esi, %r14d
movq 0x30(%rsp), %rcx
movl 0x10(%rcx), %ecx
movl %esi, %edx
subl %ecx, %edx
subl %ecx, %eax
movl %edx, 0x10(%rbx)
movl %eax, 0x14(%rbx)
movq 0x20(%r13), %rdx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x1597b
movq 0x28(%r13), %rax
leaq 0x8(%rbx), %rcx
movq %rbx, %r8
addq $0xc, %r8
movq %rdx, %rsi
movq %rax, %rdx
callq 0x14e0e
movq 0x10(%r13), %rsi
movq 0x20(%r13), %rdx
jmp 0x1598a
movl %edx, %eax
subl 0x48(%rsp), %eax
movl %eax, 0x8(%rbx)
addl %r14d, %eax
movl %eax, 0xc(%rbx)
movq %r13, 0x20(%rbx)
movl 0x28(%rsp), %edi
movl %r14d, %ecx
callq 0x15b80
movl %eax, 0x18(%rbx)
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %ecx
cmpl %eax, %ebp
cmovgel %eax, %ebp
cmpl %ecx, %r15d
cmovlel %ecx, %r15d
movq %r12, (%rbx)
movq %rbx, 0x40(%rsp)
movq 0x8(%r13), %r13
movq %rbx, %r12
testq %r13, %r13
jne 0x15915
movd %ebp, %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
movq 0x8(%rbx), %xmm1
psubd %xmm0, %xmm1
movq %xmm1, 0x8(%rbx)
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x159d0
subl %ebp, %r15d
movl 0x2c(%rsp), %ebp
jmp 0x159f5
movl $0x80000002, %r15d      # imm = 0x80000002
movq 0xa0(%rsp), %r12
movl %ebp, 0xab59d(%rip)     # 0xc0fa0
movl 0x28(%rsp), %eax
movl %eax, 0xab597(%rip)     # 0xc0fa4
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x18(%rax), %esi
pxor %xmm0, %xmm0
movdqu %xmm0, 0x10(%rsp)
leaq 0x29f(%rip), %rax       # 0x15cc9
movq %rax, 0x8(%rsp)
leaq 0x18a(%rip), %rax       # 0x15bc0
movq %rax, (%rsp)
leaq 0x78a9d(%rip), %rcx     # 0x8e4de
leaq 0x40(%rsp), %r9
movl $0x2b, %edx
movl %r15d, %r8d
callq 0x1f634
movq %rax, %r14
movq %rax, 0x38(%rsp)
movq 0x8(%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x15acc
movq %rcx, %r15
movl 0x8(%rcx), %ebx
movl 0x10(%rcx), %ecx
subl 0x14(%rax), %ecx
subl 0xc(%rax), %ebx
cmpl %ebx, %ecx
cmovll %ecx, %ebx
testl %ebx, %ebx
jns 0x15ab8
negl %ebx
movq 0x20(%rax), %r13
movq 0x20(%r15), %rbp
movq 0x28(%r13), %rdi
movq 0x10(%rbp), %rsi
movq 0x20(%rbp), %rdx
movl %ebx, %ecx
movl 0x28(%rsp), %r8d
callq 0x15ce4
subl %eax, %ebx
movslq %ebx, %rcx
subq %rcx, 0x18(%r13)
subq %rcx, 0x28(%r13)
cltq
addq %rax, 0x10(%rbp)
addq %rax, 0x20(%rbp)
movq (%r15), %rcx
movq %r15, %rax
testq %rcx, %rcx
jne 0x15a67
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x15ae2
xorl %ecx, %ecx
movq 0x20(%rax), %rdi
movq %rcx, (%rdi)
movq (%rax), %rax
movq %rdi, %rcx
testq %rax, %rax
jne 0x15ace
jmp 0x15ae4
xorl %edi, %edi
movq 0xb0(%rsp), %r15
movq 0xa8(%rsp), %rbx
callq 0x28293
movq %rax, (%r12)
movq (%r14), %rax
testq %rax, %rax
je 0x15b34
xorl %ecx, %ecx
movq 0x8(%rax), %rdx
testq %rdx, %rdx
je 0x15b24
movq 0x20(%rdx), %rdi
movq %rcx, (%rdi)
movq (%rdx), %rdx
movq %rdi, %rcx
testq %rdx, %rdx
jne 0x15b10
jmp 0x15b27
movq %rcx, %rdi
movq (%rax), %rax
movq %rdi, %rcx
testq %rax, %rax
jne 0x15b07
jmp 0x15b36
xorl %edi, %edi
callq 0x28293
movq %rax, (%r15)
cvttsd2si 0x10(%r14), %eax
movl %eax, (%rbx)
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x15b5d
movq $0x0, 0x8(%rax)
movq (%rax), %rax
jmp 0x15b4b
leaq 0x38(%rsp), %rdi
callq 0x1e79d
leaq 0x60(%rsp), %rdi
callq 0x2c2c7
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq