// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movq %r9, %r15
movl %r8d, 0x24(%rsp)
movl %ecx, 0x3c(%rsp)
movq %rdx, %r13
movq %rsi, 0x40(%rsp)
movq %rdi, %r12
movq $0x0, 0x30(%rsp)
xorl %edi, %edi
callq 0x2bea4
movq %rax, 0x48(%rsp)
testq %r12, %r12
je 0x15990
movq 0x10(%r13), %rax
movq %rax, 0x50(%rsp)
movl $0x3fffffff, %r14d      # imm = 0x3FFFFFFF
movl $0xc0000001, %ebx       # imm = 0xC0000001
movq 0x48(%rsp), %rdi
movl $0x28, %esi
callq 0x2bfa9
movq %rax, %r13
movl 0x10(%r12), %eax
movl 0x18(%r12), %ecx
movl %ecx, %ebp
subl %eax, %ebp
movq 0x40(%rsp), %rdx
movl 0x10(%rdx), %edx
subl %edx, %eax
subl %edx, %ecx
movl %eax, 0x10(%r13)
movl %ecx, 0x14(%r13)
movq 0x20(%r12), %rsi
testq %r15, %r15
je 0x1592b
movq 0x28(%r12), %rdx
leaq 0x8(%r13), %rcx
movq %r13, %r8
addq $0xc, %r8
movq %r15, %rdi
callq 0x14d5b
jmp 0x15939
subl 0x50(%rsp), %esi
movl %esi, 0x8(%r13)
addl %ebp, %esi
movl %esi, 0xc(%r13)
movq %r12, 0x20(%r13)
movq 0x10(%r12), %rsi
movq 0x20(%r12), %rdx
movl 0x24(%rsp), %edi
movl %ebp, %ecx
callq 0x15b3f
movl %eax, 0x18(%r13)
movl 0x8(%r13), %eax
cmpl %eax, %r14d
cmovll %r14d, %eax
movl 0xc(%r13), %r8d
cmpl %r8d, %ebx
cmovgl %ebx, %r8d
movq 0x30(%rsp), %rcx
movq %rcx, (%r13)
movq %r13, 0x30(%rsp)
movq 0x8(%r12), %r12
movl %r8d, %ebx
movl %eax, %r14d
testq %r12, %r12
jne 0x158d3
jmp 0x1599b
movl $0xc0000001, %r8d       # imm = 0xC0000001
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq 0x30(%rsp), %rcx
testq %rcx, %rcx
je 0x159b0
subl %eax, 0x8(%rcx)
subl %eax, 0xc(%rcx)
movq (%rcx), %rcx
jmp 0x159a0
subl %eax, %r8d
movl 0x3c(%rsp), %eax
movl %eax, 0xab5e3(%rip)     # 0xc0fa0
movl 0x24(%rsp), %eax
movl %eax, 0xab5dd(%rip)     # 0xc0fa4
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x18(%rax), %esi
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
leaq 0x296(%rip), %rax       # 0x15c78
movq %rax, 0x8(%rsp)
leaq 0x191(%rip), %rax       # 0x15b7f
movq %rax, (%rsp)
leaq 0x78aa5(%rip), %rcx     # 0x8e49e
leaq 0x30(%rsp), %r9
movl $0x2b, %edx
callq 0x1f16c
movq %rax, %r14
movq %rax, 0x28(%rsp)
movq 0x8(%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x15a70
movq %rcx, %rbx
movl 0x8(%rcx), %ebp
movl 0x10(%rcx), %ecx
subl 0x14(%rax), %ecx
subl 0xc(%rax), %ebp
cmpl %ebp, %ecx
cmovll %ecx, %ebp
testl %ebp, %ebp
jns 0x15a68
negl %ebp
movq 0x20(%rax), %r15
movq 0x20(%rbx), %r12
movq %r15, %rdi
movq %r12, %rsi
movl %ebp, %edx
movl 0x24(%rsp), %ecx
callq 0x15c93
subl %eax, %ebp
movslq %ebp, %rcx
subq %rcx, 0x18(%r15)
subq %rcx, 0x28(%r15)
cltq
addq %rax, 0x10(%r12)
addq %rax, 0x20(%r12)
movq (%rbx), %rcx
movq %rbx, %rax
jmp 0x15a17
movq 0x90(%rsp), %r12
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x15a9c
xorl %ecx, %ecx
movq 0x20(%rax), %rdi
movq %rcx, (%rdi)
movq (%rax), %rax
movq %rdi, %rcx
testq %rax, %rax
jne 0x15a88
jmp 0x15a9e
xorl %edi, %edi
movq 0xa0(%rsp), %r15
movq 0x98(%rsp), %rbx
callq 0x27f4d
movq %rax, (%r12)
movq 0x28(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x15af3
xorl %ecx, %ecx
movq 0x8(%rax), %rdx
testq %rdx, %rdx
je 0x15ae3
movq 0x20(%rdx), %rdi
movq %rcx, (%rdi)
movq (%rdx), %rdx
movq %rdi, %rcx
testq %rdx, %rdx
jne 0x15acf
jmp 0x15ae6
movq %rcx, %rdi
movq (%rax), %rax
movq %rdi, %rcx
testq %rax, %rax
jne 0x15ac6
jmp 0x15af5
xorl %edi, %edi
callq 0x27f4d
movq %rax, (%r15)
cvttsd2si 0x10(%r14), %eax
movl %eax, (%rbx)
movq 0x28(%rsp), %rax
testq %rax, %rax
je 0x15b1c
movq $0x0, 0x8(%rax)
movq (%rax), %rax
jmp 0x15b0a
leaq 0x28(%rsp), %rdi
callq 0x1e3a1
leaq 0x48(%rsp), %rdi
callq 0x2bf4b
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq