// File: /workspace/github_c_makefile_star2_O2/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, 0x2c(%rsp)
movq %rdx, %rbx
movq %rsi, 0x30(%rsp)
movq %rdi, %r13
andq $0x0, 0x40(%rsp)
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x26f00
movq %rax, 0x50(%rsp)
movq %rax, 0x60(%rsp)
movq 0x10(%rbx), %rax
movq %rax, 0x48(%rsp)
movl $0xc0000001, %ebp       # imm = 0xC0000001
movl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
testq %r13, %r13
je 0x12c09
movq 0x50(%rsp), %rdi
pushq $0x28
popq %rsi
callq 0x26ff4
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 0x12bc1
movq 0x28(%r13), %rax
leaq 0x8(%rbx), %rcx
movq %rbx, %r8
addq $0xc, %r8
movq %rdx, %rsi
movq %rax, %rdx
callq 0x1207f
movq 0x10(%r13), %rsi
movq 0x20(%r13), %rdx
jmp 0x12bd0
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 0x12d95
movl %eax, 0x18(%rbx)
movl 0x8(%rbx), %eax
cmpl %eax, %r12d
cmovgel %eax, %r12d
movl 0xc(%rbx), %eax
cmpl %eax, %ebp
cmovlel %eax, %ebp
movq %r15, (%rbx)
movq %rbx, 0x40(%rsp)
movq 0x8(%r13), %r13
movq %rbx, %r15
jmp 0x12b54
movd %r12d, %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
testq %r15, %r15
je 0x12c2d
movq 0x8(%r15), %xmm1
psubd %xmm0, %xmm1
movq %xmm1, 0x8(%r15)
movq (%r15), %r15
jmp 0x12c13
subl %r12d, %ebp
movl 0x2c(%rsp), %eax
movl %eax, 0xa2386(%rip)     # 0xb4fc0
movl 0x28(%rsp), %eax
movl %eax, 0xa2380(%rip)     # 0xb4fc4
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x18(%rax), %esi
pxor %xmm0, %xmm0
movdqu %xmm0, 0x10(%rsp)
leaq 0x237(%rip), %rax       # 0x12e98
movq %rax, 0x8(%rsp)
leaq 0x151(%rip), %rax       # 0x12dbe
movq %rax, (%rsp)
leaq 0x6a806(%rip), %rcx     # 0x7d47e
pushq $0x2b
popq %rdx
leaq 0x40(%rsp), %r9
movl %ebp, %r8d
callq 0x1ba88
movq %rax, %r14
movq %rax, 0x38(%rsp)
movq 0x8(%rax), %rbp
movq %rax, %r13
addq $0x8, %r13
movq %rbp, %rax
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x12cf2
movl 0x8(%rbp), %ebx
movl 0x10(%rbp), %ecx
subl 0x14(%rax), %ecx
subl 0xc(%rax), %ebx
cmpl %ebx, %ecx
cmovll %ecx, %ebx
testl %ebx, %ebx
jns 0x12c9b
negl %ebx
movq 0x20(%rax), %r15
movq 0x20(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
movl %ebx, %edx
movl 0x28(%rsp), %ecx
callq 0x12eb3
subl %eax, %ebx
movslq %ebx, %rcx
subq %rcx, 0x18(%r15)
subq %rcx, 0x28(%r15)
cltq
addq %rax, 0x10(%r12)
addq %rax, 0x20(%r12)
jmp 0x12c9b
xorl %edi, %edi
movq (%r13), %r13
testq %r13, %r13
je 0x12d09
movq 0x20(%r13), %rax
movq %rdi, (%rax)
movq %rax, %rdi
jmp 0x12cf4
callq 0x236b0
movq 0xa0(%rsp), %rcx
movq %rax, (%rcx)
xorl %edi, %edi
movq %r14, %rax
movq (%rax), %rax
testq %rax, %rax
je 0x12d3e
leaq 0x8(%rax), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x12d1e
movq 0x20(%rcx), %rdx
movq %rdi, (%rdx)
movq %rdx, %rdi
jmp 0x12d2a
callq 0x236b0
movq 0xb0(%rsp), %rcx
movq %rax, (%rcx)
cvttsd2si 0x10(%r14), %eax
movq 0xa8(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x38(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x12d72
andq $0x0, 0x8(%rax)
jmp 0x12d63
leaq 0x38(%rsp), %rdi
callq 0x1ad0d
leaq 0x60(%rsp), %rdi
callq 0x26fa2
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq