// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/lib/maf.c
// Function: mafSubsetE
struct mafAli *mafSubsetE(struct mafAli *maf, char *componentSource,
	int newStart, int newEnd, bool getInitialDashes)
/* Extract subset of maf that intersects a given range
 * in a component sequence.  The newStart and newEnd
 * are given in the forward strand coordinates of the
 * component sequence.  The componentSource is typically
 * something like 'mm3.chr1'.  This will return NULL
 * if maf does not intersect range.  The score field
 * in the returned maf will not be filled in (since
 * we don't know which scoring scheme to use). */
{
struct mafComp *mcMaster = mafFindComponent(maf, componentSource);
struct mafAli *subset;
struct mafComp *mc, *subMc;
char *s, *e;
int textStart, textSize;

/* Reverse complement input range if necessary. */
if (mcMaster->strand == '-')
    reverseIntRange(&newStart, &newEnd, mcMaster->srcSize);

/* Check if any real intersection and return NULL if not. */
if (newStart >= newEnd)
    return NULL;
if (newStart >= mcMaster->start + mcMaster->size)
    return NULL;
if (newEnd <= mcMaster->start)
    return NULL;

/* Clip to bounds of actual data. */
if (newStart < mcMaster->start)
    newStart = mcMaster->start;
if (newEnd > mcMaster->start + mcMaster->size)
    newEnd = mcMaster->start + mcMaster->size;

/* Translate position in master sequence to position in
 * multiple alignment. */
s = skipIgnoringDash(mcMaster->text, newStart - mcMaster->start, TRUE);
e = skipIgnoringDash(s, newEnd - newStart, TRUE);
textStart = s - mcMaster->text;
textSize = e - s;

if (getInitialDashes && (newStart == mcMaster->start))
    {
    textStart = 0;
    textSize += s - mcMaster->text;
    }

/* Allocate subset structure and fill it in */
AllocVar(subset);
subset->textSize = textSize;
for (mc = maf->components; mc != NULL; mc = mc->next)
    {
    AllocVar(subMc);
    subMc->src = cloneString(mc->src);
    subMc->srcSize = mc->srcSize;
    subMc->strand = mc->strand;
    if (mc->size != 0)
        {
        subMc->start = mc->start + countNonDash(mc->text, textStart);
        subMc->size = countNonDash(mc->text+textStart, textSize);
        subMc->text = cloneStringZ(mc->text + textStart, textSize);
        if (mc->quality != NULL)
            subMc->quality = cloneStringZ(mc->quality + textStart, textSize);
        }
    else
	{
        /* empty row annotation */
        subMc->size = 0;
        subMc->start = mc->start;
	}

    subMc->leftStatus = mc->leftStatus;
    subMc->leftLen = mc->leftLen;
    subMc->rightStatus = mc->rightStatus;
    subMc->rightLen = mc->rightLen;

    slAddHead(&subset->components, subMc);
    }
slReverse(&subset->components);
return subset;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %ebp
movq %rdi, %r15
movl %edx, (%rsp)
movl %ecx, 0x4(%rsp)
callq 0x2cf7b
movq %rax, %r12
cmpb $0x2d, 0x14(%rax)
jne 0x2d245
movl 0x10(%r12), %edx
movq %rsp, %rdi
leaq 0x4(%rsp), %rsi
callq 0x25145
movl (%rsp), %ecx
movl 0x4(%rsp), %eax
cmpl %eax, %ecx
jge 0x2d3e5
movl 0x18(%r12), %edx
xorl %r14d, %r14d
cmpl %edx, %eax
jle 0x2d3e8
movl 0x1c(%r12), %esi
addl %edx, %esi
cmpl %esi, %ecx
jge 0x2d3e8
cmpl %edx, %ecx
jge 0x2d27a
movl %edx, (%rsp)
movl 0x1c(%r12), %ecx
addl 0x18(%r12), %ecx
cmpl %ecx, %eax
jle 0x2d28c
movl %ecx, 0x4(%rsp)
movq 0x20(%r12), %rdi
movl (%rsp), %esi
subl 0x18(%r12), %esi
movl $0x1, %edx
callq 0x25363
movq %rax, %r13
movl 0x4(%rsp), %esi
subl (%rsp), %esi
movq %rax, %rdi
movl $0x1, %edx
callq 0x25363
movq %rax, %rbx
subq %r13, %rbx
subq 0x20(%r12), %r13
testb %bpl, %bpl
je 0x2d2e4
movl (%rsp), %eax
xorl %ecx, %ecx
cmpl 0x18(%r12), %eax
movl %r13d, %eax
cmovel %ecx, %eax
cmoveq %r13, %rcx
addq %rcx, %rbx
movl %eax, %r13d
movl $0x28, %edi
callq 0x2dc95
movq %rax, %r14
movl %ebx, 0x18(%rax)
movq 0x10(%r15), %rbp
testq %rbp, %rbp
je 0x2d3d7
movslq %r13d, %r15
movl $0x40, %edi
callq 0x2dc95
movq %rax, %r12
movq 0x8(%rbp), %rdi
callq 0x1f9f6
movq %rax, 0x8(%r12)
movl 0x10(%rbp), %eax
movl %eax, 0x10(%r12)
movb 0x14(%rbp), %al
movb %al, 0x14(%r12)
cmpl $0x0, 0x1c(%rbp)
je 0x2d38d
movl 0x18(%rbp), %r13d
movq 0x20(%rbp), %rdi
movl %r15d, %esi
callq 0x25399
addl %r13d, %eax
movl %eax, 0x18(%r12)
movq 0x20(%rbp), %rdi
addq %r15, %rdi
movl %ebx, %esi
callq 0x25399
movl %eax, 0x1c(%r12)
movq 0x20(%rbp), %rdi
addq %r15, %rdi
movl %ebx, %esi
callq 0x1f9a7
movq %rax, 0x20(%r12)
movq 0x28(%rbp), %rdi
testq %rdi, %rdi
je 0x2d39e
addq %r15, %rdi
movl %ebx, %esi
callq 0x1f9a7
movq %rax, 0x28(%r12)
jmp 0x2d39e
movl $0x0, 0x1c(%r12)
movl 0x18(%rbp), %eax
movl %eax, 0x18(%r12)
movb 0x30(%rbp), %al
movb %al, 0x30(%r12)
movl 0x34(%rbp), %eax
movl %eax, 0x34(%r12)
movb 0x38(%rbp), %al
movb %al, 0x38(%r12)
movl 0x3c(%rbp), %eax
movl %eax, 0x3c(%r12)
movq 0x10(%r14), %rax
movq %rax, (%r12)
movq %r12, 0x10(%r14)
movq (%rbp), %rbp
testq %rbp, %rbp
jne 0x2d304
movq %r14, %rdi
addq $0x10, %rdi
callq 0x1fcb3
jmp 0x2d3e8
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq