// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/lib/chain.c
// Function: chainSubsetOnQ
void chainSubsetOnQ(struct chain *chain, int subStart, int subEnd, 
    struct chain **retSubChain,  struct chain **retChainToFree)
/* Get subchain of chain bounded by subStart-subEnd on 
 * query side.  Return result in *retSubChain.  In some
 * cases this may be the original chain, in which case
 * *retChainToFree is NULL.  When done call chainFree on
 * *retChainToFree.  The score and id fields are not really
 * properly filled in. */
{
struct chain *sub = NULL;
struct cBlock *oldB, *b, *bList = NULL;
int qStart = BIGNUM, qEnd = -BIGNUM;
int tStart = BIGNUM, tEnd = -BIGNUM;

/* Check for easy case. */
if (subStart <= chain->qStart && subEnd >= chain->qEnd)
    {
    *retSubChain = chain;
    *retChainToFree = NULL;
    return;
    }
/* Build new block list and calculate bounds. */
for (oldB = chain->blockList; oldB != NULL; oldB = oldB->next)
    {
    if (oldB->qEnd <= subStart)
        continue;
    if (oldB->qStart >= subEnd)
        break;
    b = CloneVar(oldB);
    if (b->qStart < subStart)
        {
	b->tStart += subStart - b->qStart;
	b->qStart = subStart;
	}
    if (b->qEnd > subEnd)
        {
	b->tEnd -= b->qEnd - subEnd;
	b->qEnd = subEnd;
	}
    slAddHead(&bList, b);
    if (tStart > b->tStart)
        tStart = b->tStart;
    if (tEnd < b->tEnd)
        tEnd = b->tEnd;
    if (qStart > b->qStart)
        qStart = b->qStart;
    if (qEnd < b->qEnd)
        qEnd = b->qEnd;
    }
slReverse(&bList);

/* Make new chain based on old. */
if (bList != NULL)
    {
    AllocVar(sub);
    sub->blockList = bList;
    sub->qName = cloneString(chain->qName);
    sub->qSize = chain->qSize;
    sub->qStrand = chain->qStrand;
    sub->qStart = qStart;
    sub->qEnd = qEnd;
    sub->tName = cloneString(chain->tName);
    sub->tSize = chain->tSize;
    sub->tStart = tStart;
    sub->tEnd = tEnd;
    sub->id = chain->id;
    }
*retSubChain = *retChainToFree = sub;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebp
movl %esi, %r12d
movq $0x0, 0x8(%rsp)
cmpl %esi, 0x40(%rdi)
jl 0x1f447
cmpl %ebp, 0x44(%rdi)
jle 0x1f5cb
movq %rcx, 0x18(%rsp)
movq %r8, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x8(%rdi), %r13
testq %r13, %r13
je 0x1f50f
movl $0x3fffffff, 0x4(%rsp)  # imm = 0x3FFFFFFF
movl $0xc0000001, (%rsp)     # imm = 0xC0000001
xorl %r14d, %r14d
movl $0xc0000001, %r15d      # imm = 0xC0000001
movl $0x3fffffff, %ebx       # imm = 0x3FFFFFFF
cmpl %r12d, 0x14(%r13)
jle 0x1f500
cmpl %ebp, 0x10(%r13)
jge 0x1f529
movl $0x28, %esi
movq %r13, %rdi
callq 0x1fe44
movl 0x10(%rax), %ecx
movl %r12d, %edx
subl %ecx, %edx
jle 0x1f4b1
addl %edx, 0x8(%rax)
movl %r12d, 0x10(%rax)
movl %r12d, %ecx
movl 0x14(%rax), %edx
movl %ebp, %esi
subl %edx, %esi
jge 0x1f4c7
addl 0xc(%rax), %esi
movl %esi, 0xc(%rax)
movl %ebp, 0x14(%rax)
movl %ebp, %edx
jmp 0x1f4ca
movl 0xc(%rax), %esi
movq %r14, (%rax)
movq %rax, 0x8(%rsp)
movl 0x8(%rax), %edi
movl 0x4(%rsp), %r8d
cmpl %edi, %r8d
cmovgel %edi, %r8d
movl %r8d, 0x4(%rsp)
movl (%rsp), %edi
cmpl %esi, %edi
cmovlel %esi, %edi
movl %edi, (%rsp)
cmpl %ecx, %ebx
cmovgel %ecx, %ebx
cmpl %edx, %r15d
cmovlel %edx, %r15d
movq %rax, %r14
movq (%r13), %r13
testq %r13, %r13
jne 0x1f480
jmp 0x1f529
movl $0xc0000001, %r15d      # imm = 0xC0000001
movl $0x3fffffff, %ebx       # imm = 0x3FFFFFFF
movl $0x3fffffff, 0x4(%rsp)  # imm = 0x3FFFFFFF
movl $0xc0000001, (%rsp)     # imm = 0xC0000001
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x20173
cmpq $0x0, (%r12)
je 0x1f5b6
movl $0x50, %edi
callq 0x2dff4
movq %rax, %r12
movq 0x8(%rsp), %rax
movq %rax, 0x8(%r12)
movq 0x10(%rsp), %r14
movq 0x30(%r14), %rdi
callq 0x1feba
movq %rax, 0x30(%r12)
movl 0x38(%r14), %eax
movl %eax, 0x38(%r12)
movb 0x3c(%r14), %al
movb %al, 0x3c(%r12)
movl %ebx, 0x40(%r12)
movl %r15d, 0x44(%r12)
movq 0x18(%r14), %rdi
callq 0x1feba
movq %rax, 0x18(%r12)
movl 0x20(%r14), %eax
movl %eax, 0x20(%r12)
movl 0x4(%rsp), %eax
movl %eax, 0x24(%r12)
movl (%rsp), %eax
movl %eax, 0x28(%r12)
movl 0x48(%r14), %eax
movl %eax, 0x48(%r12)
jmp 0x1f5b9
xorl %r12d, %r12d
movq 0x20(%rsp), %rax
movq %r12, (%rax)
movq 0x18(%rsp), %rax
movq %r12, (%rax)
jmp 0x1f5d5
movq %rdi, (%rcx)
movq $0x0, (%r8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq