// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/chainBlock.c
// Function: bestPredecessor
static struct predScore bestPredecessor(
	struct kdLeaf *lonely,	    /* We're finding this leaf's predecessor */
	ConnectCost connectCost,    /* Cost to connect two leafs. */
	GapCost gapCost,	    /* Lower bound on gap cost. */
	void *gapData,		    /* Data to pass to Gap/Connect cost */
	int dim,		    /* Dimension level of tree splits on. */
	struct kdBranch *branch,    /* Subtree to explore */
	struct predScore bestSoFar) /* Best predecessor so far. */
/* Find the highest scoring predecessor to this leaf, and
 * thus iteratively the highest scoring subchain that ends
 * in this leaf. */
{
struct kdLeaf *leaf;
double maxScore = branch->maxScore + lonely->cb->score;

/* If best score in this branch of tree wouldn't be enough
 * don't bother exploring it. First try without calculating
 * gap score in case gap score is a little expensive to calculate. */
if (maxScore < bestSoFar.score)
    return bestSoFar;
maxScore -= gapCost(lonely->cb->qStart - branch->maxQ, 
	lonely->cb->tStart - branch->maxT, gapData);
if (maxScore < bestSoFar.score)
    return bestSoFar;


/* If it's a terminal branch, then calculate score to connect
 * with it. */
else if ((leaf = branch->leaf) != NULL)
    {
    if (leaf->cb->qStart < lonely->cb->qStart 
     && leaf->cb->tStart < lonely->cb->tStart)
	{
	double score = leaf->totalScore + lonely->cb->score - 
		connectCost(leaf->cb, lonely->cb, gapData);
	if (score > bestSoFar.score)
	   {
	   bestSoFar.score = score;
	   bestSoFar.pred = branch;
	   }
	}
    return bestSoFar;
    }

/* Otherwise explore sub-trees that could harbor predecessors. */
else
    {
    int newDim = 1-dim;
    int dimCoord = (dim == 0 ? lonely->cb->qStart : lonely->cb->tStart);
    
    /* Explore hi branch first as it is more likely to have high
     * scores.  However only explore it if it can have things starting
     * before us. */
    if (dimCoord > branch->cutCoord)
         bestSoFar = bestPredecessor(lonely, connectCost, gapCost, gapData,
	 	newDim, branch->hi, bestSoFar);
    bestSoFar = bestPredecessor(lonely, connectCost, gapCost, gapData,
    	newDim, branch->lo, bestSoFar);
    return bestSoFar;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movl %r8d, -0x34(%rbp)
movq %r9, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movsd 0x20(%rcx), %xmm0
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
cvtsi2sdl 0x18(%rcx), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm1
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2a008
movq -0x88(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x10(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x2a271
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl 0x10(%rcx), %edi
movq -0x40(%rbp), %rcx
subl 0x28(%rcx), %edi
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl 0x8(%rcx), %esi
movq -0x40(%rbp), %rcx
subl 0x2c(%rcx), %esi
movq -0x30(%rbp), %rdx
callq *%rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
cvtsi2sd %ecx, %xmm1
movsd -0x50(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm1
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2a07c
movq -0x88(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x10(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x2a271
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x2a165
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x10(%rcx), %eax
jge 0x2a14a
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2a14a
movq -0x48(%rbp), %rax
movsd 0x18(%rax), %xmm0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
cvtsi2sdl 0x18(%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rsi
movq -0x30(%rbp), %rdx
callq *%rax
movsd -0x90(%rbp), %xmm0
movl %eax, %ecx
movq -0x88(%rbp), %rax
cvtsi2sd %ecx, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
ucomisd 0x8(%rax), %xmm0
jbe 0x2a148
movq -0x88(%rbp), %rax
movsd -0x58(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x2a14a
movq -0x88(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x10(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x2a271
movl $0x1, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x2a189
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %eax
movl %eax, -0x94(%rbp)
jmp 0x2a19a
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jle 0x2a209
movq -0x88(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl -0x5c(%rbp), %r8d
movq -0x40(%rbp), %r9
movq 0x8(%r9), %r9
movq (%rax), %r10
movq %r10, (%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x29f90
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, -0x70(%rbp)
movsd %xmm0, -0x68(%rbp)
movq -0x70(%rbp), %rcx
movq %rcx, (%rax)
movq -0x68(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x88(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl -0x5c(%rbp), %r8d
movq -0x40(%rbp), %r9
movq (%r9), %r9
movq (%rax), %r10
movq %r10, (%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x29f90
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, -0x80(%rbp)
movsd %xmm0, -0x78(%rbp)
movq -0x80(%rbp), %rcx
movq %rcx, (%rax)
movq -0x78(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq (%rax), %rcx
movq %rcx, -0x10(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movsd -0x8(%rbp), %xmm0
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)