// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/jkOwnLib/ffSeedExtend.c
// Function: hardRefineSplice
static struct ffAli *hardRefineSplice(struct ffAli *left, struct ffAli *right,
	struct dnaSeq *qSeq, struct dnaSeq *tSeq, struct ffAli *ffList, 
	int orientation)
/* Do difficult refinement of splice site.  See if
 * can get nice splice sites without breaking too much.  */
{
/* Strategy: peel back about 6 bases on either side of intron.
 * Then try positioning the intron at each position in the
 * peeled area and assessing score. */
int peelSize = 12;
char nSeq[12+1], hSeq[12+1+1];
char nSym[25], hSym[25];
int symCount;
int seqScore, spliceScore, score, maxScore = 0;
int nGap = right->nStart - left->nEnd;
int hGap = right->hStart - left->hEnd;
int peelLeft = (peelSize - nGap)/2;
int intronSize = hGap - nGap;
char *npStart = left->nEnd - peelLeft;
char *npEnd = npStart + peelSize;
char *hpStart = left->hEnd - peelLeft;
char *hpEnd = npEnd + (right->hStart - right->nStart);
struct axtScoreScheme *ss = axtScoreSchemeRnaDefault();
static int modSize[3] = {0, 1, -1};
int modIx;
int bestPos = -1, bestMod = 0;
int iPos;

memcpy(nSeq, npStart, peelSize);
nSeq[peelSize] = 0;
for (modIx=0; modIx < ArraySize(modSize); ++modIx)
    {
    int modOne = modSize[modIx];
    int modPeelSize = peelSize - modOne;
    int iSize = intronSize + modOne;
    for (iPos=0; iPos <= modPeelSize; iPos++)
        {
	grabAroundIntron(hpStart, iPos, iSize, modPeelSize, hSeq);
	if (bandExt(TRUE, ss, 2, nSeq, peelSize, hSeq, modPeelSize, 1,
		sizeof(hSym), &symCount, nSym, hSym, NULL, NULL))
	    {
	    seqScore = axtScoreSym(ss, symCount, nSym, hSym);
	    spliceScore = calcSpliceScore(ss, hpStart[iPos], hpStart[iPos+1],
		    hpStart[iPos+iSize-2], hpStart[iPos+iSize-1], orientation);
	    score = seqScore + spliceScore;
	    if (score > maxScore)
		{
		maxScore = score;
		bestPos = iPos;
		bestMod = modOne;
		}
	    }
	}
    }
if (maxScore > 0)
    {
    int modPeelSize = peelSize - bestMod;
    int i,diff, cutSymIx = 0;
    int nIx, hIx;
    struct ffAli *ff;

    /* Regenerate the best alignment. */
    grabAroundIntron(hpStart, bestPos, intronSize + bestMod, modPeelSize, hSeq); 
    bandExt(TRUE, ss, 2, nSeq, peelSize, hSeq, modPeelSize, 1,
	    sizeof(hSym), &symCount, nSym, hSym, NULL, NULL);

    /* Peel back surrounding ffAli's */
    if (left->nStart > npStart || right->nEnd < npEnd)
	{
	/* It would take a lot of code to handle this case. 
	 * I believe it is rare enough that it's not worth
	 * it.  This verbosity will help keep track of how
	 * often it comes up. */
	verbose(2, "Unable to peel in hardRefineSplice\n");
	return ffList;
	}
    diff = left->nEnd - npStart;
    left->nEnd -= diff;
    left->hEnd -= diff;
    diff = right->nStart - npEnd;
    right->nStart -= diff;
    right->hStart -= diff;

    /* Step through base by base alignment from the left until
     * hit intron, converting it into ffAli format. */
    nIx = hIx = 0;
    ff = left;
    for (i=0; i<symCount; ++i)
	{
	if (hIx == bestPos)
	    {
	    cutSymIx = i;
	    break;
	    }
	if (hSym[i] == '-')
	    {
	    ff = NULL;
	    nIx += 1;
	    }
	else if (nSym[i] == '-')
	    {
	    ff = NULL;
	    hIx += 1;
	    }
	else
	    {
	    if (ff == NULL)
		{
		AllocVar(ff);
		ff->left = left;
		ff->right = right;
		left->right = ff;
		right->left = ff;
		left = ff;
		ff->nStart = ff->nEnd = npStart + nIx;
		ff->hStart = ff->hEnd = hpStart + hIx;
		}
	    ++nIx;
	    ++hIx;
	    ff->nEnd += 1;
	    ff->hEnd += 1;
	    }
	}

    /* Step through base by base alignment from the right until
     * hit intron, converting it into ffAli format. */
    ff = right;
    hIx = nIx = 0;	/* Index from right side. */
    for (i = symCount-1; i >= cutSymIx; --i)
	{
	if (hSym[i] == '-')
	    {
	    ff = NULL;
	    nIx += 1;
	    }
	else if (nSym[i] == '-')
	    {
	    ff = NULL;
	    hIx += 1;
	    }
	else
	    {
	    if (ff == NULL)
		{
		AllocVar(ff);
		ff->left = left;
		ff->right = right;
		left->right = ff;
		right->left = ff;
		left = ff;
		ff->nStart = ff->nEnd = npEnd - nIx;
		ff->hStart = ff->hEnd = hpEnd - hIx;
		}
	    ++nIx;
	    ++hIx;
	    ff->nStart -= 1;
	    ff->hStart -= 1;
	    }
	}
    }
return ffList;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movl %r9d, -0x44(%rbp)
movl $0xc, -0x48(%rbp)
movl $0x0, -0xb4(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0xb8(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0xbc(%rbp)
movl -0x48(%rbp), %eax
subl -0xb8(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0xc0(%rbp)
movl -0xbc(%rbp), %eax
subl -0xb8(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0xc0(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movslq -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0xc0(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x28(%rbp), %rdx
movq 0x10(%rdx), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0xe8(%rbp)
movb $0x0, %al
callq 0x21e40
movq %rax, -0xf0(%rbp)
movl $0xffffffff, -0xf8(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0xfc(%rbp)
leaq -0x55(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movslq -0x48(%rbp), %rdx
callq 0x6570
movslq -0x48(%rbp), %rax
movb $0x0, -0x55(%rbp,%rax)
movl $0x0, -0xf4(%rbp)
movslq -0xf4(%rbp), %rax
cmpq $0x3, %rax
jae 0x1e2be
movslq -0xf4(%rbp), %rcx
leaq 0xe7d89(%rip), %rax     # 0x105e48
movl (%rax,%rcx,4), %eax
movl %eax, -0x104(%rbp)
movl -0x48(%rbp), %eax
subl -0x104(%rbp), %eax
movl %eax, -0x108(%rbp)
movl -0xc4(%rbp), %eax
addl -0x104(%rbp), %eax
movl %eax, -0x10c(%rbp)
movl $0x0, -0x100(%rbp)
movl -0x100(%rbp), %eax
cmpl -0x108(%rbp), %eax
jg 0x1e2a8
movq -0xe0(%rbp), %rdi
movl -0x100(%rbp), %esi
movl -0x10c(%rbp), %edx
movl -0x108(%rbp), %ecx
leaq -0x63(%rbp), %r8
callq 0x1e810
movq -0xf0(%rbp), %rsi
leaq -0x55(%rbp), %rcx
movl -0x48(%rbp), %r8d
leaq -0x63(%rbp), %r9
movl -0x108(%rbp), %ebx
leaq -0x80(%rbp), %r10
leaq -0xa0(%rbp), %rax
movl $0x1, %edi
movl $0x2, %edx
leaq -0xa4(%rbp), %r11
xorl %r14d, %r14d
movl %ebx, (%rsp)
movl $0x1, 0x8(%rsp)
movl $0x19, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
callq 0x1fac0
cmpl $0x0, %eax
je 0x1e292
movq -0xf0(%rbp), %rdi
movl -0xa4(%rbp), %esi
leaq -0x80(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
callq 0x21250
movl %eax, -0xa8(%rbp)
movq -0xf0(%rbp), %rdi
movq -0xe0(%rbp), %rax
movslq -0x100(%rbp), %rcx
movb (%rax,%rcx), %sil
movq -0xe0(%rbp), %rax
movl -0x100(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0xe0(%rbp), %rax
movl -0x100(%rbp), %ecx
addl -0x10c(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0xe0(%rbp), %rax
movl -0x100(%rbp), %r8d
addl -0x10c(%rbp), %r8d
subl $0x1, %r8d
movslq %r8d, %r8
movb (%rax,%r8), %al
movl -0x44(%rbp), %r9d
movsbl %sil, %esi
movsbl %dl, %edx
movsbl %cl, %ecx
movsbl %al, %r8d
callq 0x1e880
movl %eax, -0xac(%rbp)
movl -0xa8(%rbp), %eax
addl -0xac(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
cmpl -0xb4(%rbp), %eax
jle 0x1e290
movl -0xb0(%rbp), %eax
movl %eax, -0xb4(%rbp)
movl -0x100(%rbp), %eax
movl %eax, -0xf8(%rbp)
movl -0x104(%rbp), %eax
movl %eax, -0xfc(%rbp)
jmp 0x1e292
jmp 0x1e294
movl -0x100(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x100(%rbp)
jmp 0x1e0f3
jmp 0x1e2aa
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x1e0a0
cmpl $0x0, -0xb4(%rbp)
jle 0x1e7eb
movl -0x48(%rbp), %eax
subl -0xfc(%rbp), %eax
movl %eax, -0x110(%rbp)
movl $0x0, -0x11c(%rbp)
movq -0xe0(%rbp), %rdi
movl -0xf8(%rbp), %esi
movl -0xc4(%rbp), %edx
addl -0xfc(%rbp), %edx
movl -0x110(%rbp), %ecx
leaq -0x63(%rbp), %r8
callq 0x1e810
movq -0xf0(%rbp), %rsi
leaq -0x55(%rbp), %rcx
movl -0x48(%rbp), %r8d
leaq -0x63(%rbp), %r9
movl -0x110(%rbp), %ebx
leaq -0x80(%rbp), %r10
leaq -0xa0(%rbp), %rax
movl $0x1, %edi
movl $0x2, %edx
leaq -0xa4(%rbp), %r11
xorl %r14d, %r14d
movl %ebx, (%rsp)
movl $0x1, 0x8(%rsp)
movl $0x19, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
callq 0x1fac0
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0xd0(%rbp), %rax
ja 0x1e39f
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0xd8(%rbp), %rax
jae 0x1e3bf
movl $0x2, %edi
leaq 0xba0fd(%rip), %rsi     # 0xd84a8
movb $0x0, %al
callq 0x60040
movq -0x40(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x1e7f3
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0xd0(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x118(%rbp)
movl -0x118(%rbp), %edx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rcx
movslq %edx, %rsi
xorl %edx, %edx
subq %rsi, %rdx
addq %rdx, %rcx
movq %rcx, 0x18(%rax)
movl -0x118(%rbp), %edx
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rcx
movslq %edx, %rsi
xorl %edx, %edx
subq %rsi, %rdx
addq %rdx, %rcx
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xd8(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x118(%rbp)
movl -0x118(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movslq %edx, %rsi
xorl %edx, %edx
subq %rsi, %rdx
addq %rdx, %rcx
movq %rcx, 0x10(%rax)
movl -0x118(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rcx
movslq %edx, %rsi
xorl %edx, %edx
subq %rsi, %rdx
addq %rdx, %rcx
movq %rcx, 0x20(%rax)
movl $0x0, -0x124(%rbp)
movl $0x0, -0x120(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x130(%rbp)
movl $0x0, -0x114(%rbp)
movl -0x114(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jge 0x1e62e
movl -0x124(%rbp), %eax
cmpl -0xf8(%rbp), %eax
jne 0x1e4bd
movl -0x114(%rbp), %eax
movl %eax, -0x11c(%rbp)
jmp 0x1e62e
movslq -0x114(%rbp), %rax
movsbl -0xa0(%rbp,%rax), %eax
cmpl $0x2d, %eax
jne 0x1e4f0
movq $0x0, -0x130(%rbp)
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
jmp 0x1e618
movslq -0x114(%rbp), %rax
movsbl -0x80(%rbp,%rax), %eax
cmpl $0x2d, %eax
jne 0x1e520
movq $0x0, -0x130(%rbp)
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x1e616
cmpq $0x0, -0x130(%rbp)
jne 0x1e5d2
movl $0x38, %edi
callq 0x40c50
movq %rax, -0x130(%rbp)
movq -0x20(%rbp), %rcx
movq -0x130(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x130(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x130(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x130(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x130(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0xd0(%rbp), %rcx
movslq -0x120(%rbp), %rax
addq %rax, %rcx
movq -0x130(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x130(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0xe0(%rbp), %rcx
movslq -0x124(%rbp), %rax
addq %rax, %rcx
movq -0x130(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x130(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
movq -0x130(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq -0x130(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
jmp 0x1e618
jmp 0x1e61a
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x1e48c
movq -0x28(%rbp), %rax
movq %rax, -0x130(%rbp)
movl $0x0, -0x120(%rbp)
movl $0x0, -0x124(%rbp)
movl -0xa4(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x114(%rbp)
movl -0x114(%rbp), %eax
cmpl -0x11c(%rbp), %eax
jl 0x1e7e9
movslq -0x114(%rbp), %rax
movsbl -0xa0(%rbp,%rax), %eax
cmpl $0x2d, %eax
jne 0x1e6a1
movq $0x0, -0x130(%rbp)
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
jmp 0x1e7d3
movslq -0x114(%rbp), %rax
movsbl -0x80(%rbp,%rax), %eax
cmpl $0x2d, %eax
jne 0x1e6d1
movq $0x0, -0x130(%rbp)
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x1e7d1
cmpq $0x0, -0x130(%rbp)
jne 0x1e78d
movl $0x38, %edi
callq 0x40c50
movq %rax, -0x130(%rbp)
movq -0x20(%rbp), %rcx
movq -0x130(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x130(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x130(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x130(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x130(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0xd8(%rbp), %rcx
movslq -0x120(%rbp), %rdx
xorl %eax, %eax
subq %rdx, %rax
addq %rax, %rcx
movq -0x130(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x130(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0xe8(%rbp), %rcx
movslq -0x124(%rbp), %rdx
xorl %eax, %eax
subq %rdx, %rax
addq %rax, %rcx
movq -0x130(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x130(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
movq -0x130(%rbp), %rax
movq 0x10(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x130(%rbp), %rax
movq 0x20(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x20(%rax)
jmp 0x1e7d3
jmp 0x1e7d5
movl -0x114(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x1e65c
jmp 0x1e7eb
movq -0x40(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)