// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/psl.c
// Function: pslTrimToQueryRange
struct psl *pslTrimToQueryRange(struct psl *oldPsl, int qMin, int qMax)
/* Return psl trimmed to fit inside qMin/qMax.  Note this does not
 * update the match/misMatch and related fields. */
{
int newSize;
int oldBlockCount = oldPsl->blockCount;
boolean qIsRc = (oldPsl->strand[0] == '-');
int newBlockCount = 0, completeBlockCount = 0;
int i;
struct psl *newPsl = NULL;
int qMn = qMin, qMx = qMax;   /* qMin/qMax adjusted for strand. */

/* Deal with case where we're completely trimmed out quickly. */
newSize = rangeIntersection(oldPsl->qStart, oldPsl->qEnd, qMin, qMax);
if (newSize <= 0)
    return NULL;

if (qIsRc)
    reverseIntRange(&qMn, &qMx, oldPsl->qSize);

/* Count how many blocks will survive trimming. */
oldBlockCount = oldPsl->blockCount;
for (i=0; i<oldBlockCount; ++i)
    {
    int s = oldPsl->qStarts[i];
    int e = s + oldPsl->blockSizes[i];
    int sz = e - s;
    int overlap;
    if ((overlap = rangeIntersection(s, e, qMn, qMx)) > 0)
        ++newBlockCount;
    if (overlap == sz)
        ++completeBlockCount;
    }

if (newBlockCount == 0)
    return NULL;

/* Allocate new psl and fill in what we already know. */
AllocVar(newPsl);
strcpy(newPsl->strand, oldPsl->strand);
newPsl->qName = cloneString(oldPsl->qName);
newPsl->qSize = oldPsl->qSize;
newPsl->tName = cloneString(oldPsl->tName);
newPsl->tSize = oldPsl->tSize;
newPsl->blockCount = newBlockCount;
AllocArray(newPsl->blockSizes, newBlockCount);
AllocArray(newPsl->qStarts, newBlockCount);
AllocArray(newPsl->tStarts, newBlockCount);

/* Fill in blockSizes, qStarts, tStarts with real data. */
newBlockCount = completeBlockCount = 0;
for (i=0; i<oldBlockCount; ++i)
    {
    int oldSz = oldPsl->blockSizes[i];
    int sz = oldSz;
    int qS = oldPsl->qStarts[i];
    int qE = qS + sz;
    int tS = oldPsl->tStarts[i];
    int tE = tS + sz;
    if (rangeIntersection(qS, qE, qMn, qMx) > 0)
        {
	int diff;
	if ((diff = (qMn - qS)) > 0)
	    {
	    tS += diff;
	    qS += diff;
	    sz -= diff;
	    }
	if ((diff = (qE - qMx)) > 0)
	    {
	    tE -= diff;
	    qE -= diff;
	    sz -= diff;
	    }
	newPsl->qStarts[newBlockCount] = qS;
	newPsl->tStarts[newBlockCount] = tS;
	newPsl->blockSizes[newBlockCount] = sz;
	++newBlockCount;
	if (sz == oldSz)
	    ++completeBlockCount;
	}
    }
pslRecalcBounds(newPsl);
return newPsl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x28(%rax), %eax
cmpl $0x2d, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x3c(%rax), %edi
movq -0x10(%rbp), %rax
movl 0x40(%rax), %esi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
callq 0x305c0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jg 0x50f43
movq $0x0, -0x8(%rbp)
jmp 0x51210
cmpl $0x0, -0x24(%rbp)
je 0x50f5d
movq -0x10(%rbp), %rax
movl 0x38(%rax), %edx
leaq -0x3c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x33350
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x50fe6
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x60(%rcx), %rcx
movslq -0x30(%rbp), %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
subl -0x44(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x44(%rbp), %edi
movl -0x48(%rbp), %esi
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
callq 0x305c0
movl %eax, -0x50(%rbp)
cmpl $0x0, %eax
jle 0x50fc8
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jne 0x50fd9
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x50fdb
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x50f6e
cmpl $0x0, -0x28(%rbp)
jne 0x50ff9
movq $0x0, -0x8(%rbp)
jmp 0x51210
movl $0x88, %edi
callq 0x40c50
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
addq $0x28, %rdi
movq -0x10(%rbp), %rsi
addq $0x28, %rsi
callq 0x6680
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2a450
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x2a450
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x50(%rax)
movl -0x28(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x5c(%rax)
movslq -0x28(%rbp), %rdi
shlq $0x2, %rdi
callq 0x409d0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x60(%rax)
movslq -0x28(%rbp), %rdi
shlq $0x2, %rdi
callq 0x409d0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x68(%rax)
movslq -0x28(%rbp), %rdi
shlq $0x2, %rdi
callq 0x409d0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x70(%rax)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x511ff
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x5c(%rbp), %edi
movl -0x60(%rbp), %esi
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
callq 0x305c0
cmpl $0x0, %eax
jle 0x511ef
movl -0x3c(%rbp), %eax
subl -0x5c(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, %eax
jle 0x5116e
movl -0x6c(%rbp), %eax
addl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x6c(%rbp), %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x6c(%rbp), %ecx
movl -0x58(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x58(%rbp)
movl -0x60(%rbp), %eax
subl -0x40(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, %eax
jle 0x5119d
movl -0x6c(%rbp), %ecx
movl -0x68(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x68(%rbp)
movl -0x6c(%rbp), %ecx
movl -0x60(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x6c(%rbp), %ecx
movl -0x58(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x58(%rbp)
movl -0x5c(%rbp), %edx
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x64(%rbp), %edx
movq -0x38(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x58(%rbp), %edx
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jne 0x511ed
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x511ef
jmp 0x511f1
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x510cf
movq -0x38(%rbp), %rdi
callq 0x50a80
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)