// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/chainBlock.c
// Function: chainBlocks
struct chain *chainBlocks(
	char *qName, int qSize, char qStrand,	/* Info on query sequence */
	char *tName, int tSize, 		/* Info on target. */
	struct cBlock **pBlockList, 		/* Unordered ungapped alignments. */
	ConnectCost connectCost, 		/* Calculate cost to connect nodes. */
	GapCost gapCost, 			/* Cost for non-overlapping nodes. */
	void *gapData, 				/* Passed through to connect/gapCosts */
	FILE *details)				/* NULL except for debugging */
/* Create list of chains from list of blocks.  The blockList will get
 * eaten up as the blocks are moved from the list to the chain. 
 * The list of chains returned is sorted by score. 
 *
 * The details FILE may be NULL, and is where additional information
 * about the chaining is put.
 *
 * Note that the connectCost needs to adjust for possibly partially 
 * overlapping blocks, and that these need to be taken out of the
 * resulting chains in general.  This can get fairly complex.  Also
 * the chains will need some cleanup at the end.  Use the chainConnect
 * module to help with this.  See hg/mouseStuff/axtChain for example usage. */
{
struct kdTree *tree;
struct kdLeaf *leafList = NULL, *leaf;
struct cBlock *block;
struct chain *chainList = NULL, *chain;
struct lm *lm;

/* Empty lists will be problematic later, so deal with them here. */
if (*pBlockList == NULL)
   return NULL;

/* Make a leaf for each block. */
lm = lmInit(0);  /* Memory for tree, branches and leaves. */
for (block = *pBlockList; block != NULL; block = block->next)
    {
    /* Watch out for 0-length blocks in input: */
    if (block->tStart == block->tEnd)
	continue;
    lmAllocVar(lm, leaf);
    leaf->cb = block;
    leaf->totalScore = block->score;
    slAddHead(&leafList, leaf);
    }

/* Figure out chains. */
slSort(&leafList, kdLeafCmpT);
tree = kdTreeMake(leafList, lm);
findBestPredecessors(tree, leafList, connectCost, gapCost, gapData);
slSort(&leafList, kdLeafCmpTotal);
chainList = peelChains(qName, qSize, qStrand, tName, tSize, leafList, details);

/* Rescore chains (since some truncated) */
for (chain = chainList; chain != NULL; chain = chain->next)
    chain->score = scoreBlocks(chain->blockList, connectCost, gapData);
slSort(&chainList,  chainCmpScore);

/* Clean up and go home. */
lmCleanup(&lm);
*pBlockList = NULL;
return chainList;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %dl, %al
movq 0x28(%rbp), %rdx
movq 0x20(%rbp), %rdx
movq 0x18(%rbp), %rdx
movq 0x10(%rbp), %rdx
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movb %al, -0x15(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x29407
movq $0x0, -0x8(%rbp)
jmp 0x2955a
xorl %edi, %edi
callq 0x3dc20
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x29480
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x50(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x29436
jmp 0x29473
movq -0x68(%rbp), %rdi
movl $0x28, %esi
callq 0x3de60
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rax
cvtsi2sdl 0x18(%rax), %xmm0
movq -0x48(%rbp), %rax
movsd %xmm0, 0x18(%rax)
movq -0x48(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x29570
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x2941d
leaq -0x40(%rbp), %rdi
leaq 0x125(%rip), %rsi       # 0x295b0
callq 0x2ab90
movq -0x40(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x295f0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq 0x10(%rbp), %rdx
movq 0x18(%rbp), %rcx
movq 0x20(%rbp), %r8
callq 0x29760
leaq -0x40(%rbp), %rdi
leaq 0x39b(%rip), %rsi       # 0x29860
callq 0x2ab90
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movb -0x15(%rbp), %dl
movq -0x20(%rbp), %rcx
movl -0x24(%rbp), %r8d
movq -0x40(%rbp), %r9
movq 0x28(%rbp), %rax
movsbl %dl, %edx
movq %rax, (%rsp)
callq 0x298d0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x2952e
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rbp), %rsi
movq 0x20(%rbp), %rdx
callq 0x29b60
movq -0x60(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x294fc
leaq -0x58(%rbp), %rdi
leaq -0x1509(%rip), %rsi     # 0x28030
callq 0x2ab90
leaq -0x68(%rbp), %rdi
callq 0x3dd90
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)