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

/* Deal with case where we're completely trimmed out quickly. */
newSize = rangeIntersection(oldPsl->tStart, oldPsl->tEnd, tMin, tMax);
if (newSize <= 0)
    return NULL;

if (tIsRc)
    reverseIntRange(&tMn, &tMx, oldPsl->tSize);

/* Count how many blocks will survive trimming. */
oldBlockCount = oldPsl->blockCount;
for (i=0; i<oldBlockCount; ++i)
    {
    int s = oldPsl->tStarts[i];
    int e = s + oldPsl->blockSizes[i];
    int sz = e - s;
    int overlap;
    if ((overlap = rangeIntersection(s, e, tMn, tMx)) > 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 tS = oldPsl->tStarts[i];
    int tE = tS + sz;
    int qS = oldPsl->qStarts[i];
    int qE = qS + sz;
    if (rangeIntersection(tS, tE, tMn, tMx) > 0)
        {
	int diff;
	if ((diff = (tMn - tS)) > 0)
	    {
	    tS += diff;
	    qS += diff;
	    sz -= diff;
	    }
	if ((diff = (tE - tMx)) > 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 0x29(%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 0x54(%rax), %edi
movq -0x10(%rbp), %rax
movl 0x58(%rax), %esi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
callq 0x305c0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jg 0x50be3
movq $0x0, -0x8(%rbp)
jmp 0x50eb0
cmpl $0x0, -0x24(%rbp)
je 0x50bfd
movq -0x10(%rbp), %rax
movl 0x50(%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 0x50c86
movq -0x10(%rbp), %rax
movq 0x70(%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 0x50c68
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jne 0x50c79
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x50c7b
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x50c0e
cmpl $0x0, -0x28(%rbp)
jne 0x50c99
movq $0x0, -0x8(%rbp)
jmp 0x50eb0
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 0x50e9f
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 0x70(%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 0x68(%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 0x50e8f
movl -0x3c(%rbp), %eax
subl -0x5c(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, %eax
jle 0x50e0e
movl -0x6c(%rbp), %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x6c(%rbp), %eax
addl -0x64(%rbp), %eax
movl %eax, -0x64(%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 0x50e3d
movl -0x6c(%rbp), %ecx
movl -0x60(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x6c(%rbp), %ecx
movl -0x68(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x68(%rbp)
movl -0x6c(%rbp), %ecx
movl -0x58(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x58(%rbp)
movl -0x64(%rbp), %edx
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x5c(%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 0x50e8d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x50e8f
jmp 0x50e91
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x50d6f
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)