// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/twoBit.c
// Function: twoBitReadSeqFragExt
struct dnaSeq *twoBitReadSeqFragExt(struct twoBitFile *tbf, char *name,
	int fragStart, int fragEnd, boolean doMask, int *retFullSize)
/* Read part of sequence from .2bit file.  To read full
 * sequence call with start=end=0.  Sequence will be lower
 * case if doMask is false, mixed case (repeats in lower)
 * if doMask is true. */
{
struct dnaSeq *seq;
void *f = tbf->f;
int i;
int packByteCount, packedStart, packedEnd, remainder, midStart, midEnd;
int outSize;
UBYTE *packed, *packedAlloc;
DNA *dna;

/* get sequence header information, which is cached */
dnaUtilOpen();
struct twoBit *twoBit = getTwoBitSeqHeader(tbf, name);

/* validate range. */
if (fragEnd == 0)
    fragEnd = twoBit->size;
if (fragEnd > twoBit->size)
    errAbort("twoBitReadSeqFrag in %s end (%d) >= seqSize (%d)", name, fragEnd, twoBit->size);
outSize = fragEnd - fragStart;
if (outSize < 1)
    errAbort("twoBitReadSeqFrag in %s start (%d) >= end (%d)", name, fragStart, fragEnd);

/* Allocate dnaSeq, and fill in zero tag at end of sequence. */
AllocVar(seq);
if (outSize == twoBit->size)
    seq->name = cloneString(name);
else
    {
    char buf[256*2];
    safef(buf, sizeof(buf), "%s:%d-%d", name, fragStart, fragEnd);
    seq->name = cloneString(buf);
    }
seq->size = outSize;
dna = seq->dna = needLargeMem(outSize+1);
seq->dna[outSize] = 0;


/* Skip to bits we need and read them in. */
packedStart = (fragStart>>2);
packedEnd = ((fragEnd+3)>>2);
packByteCount = packedEnd - packedStart;
packed = packedAlloc = needLargeMem(packByteCount);
(*tbf->ourSeekCur)(f, packedStart);
(*tbf->ourMustRead)(f, packed, packByteCount);

/* Handle case where everything is in one packed byte */
if (packByteCount == 1)
    {
    int pOff = (packedStart<<2);
    int pStart = fragStart - pOff;
    int pEnd = fragEnd - pOff;
    UBYTE partial = *packed;
    assert(pEnd <= 4);
    assert(pStart >= 0);
    for (i=pStart; i<pEnd; ++i)
	*dna++ = valToNt[(partial >> (6-i-i)) & 3];
    }
else
    {
    /* Handle partial first packed byte. */
    midStart = fragStart;
    remainder = (fragStart&3);
    if (remainder > 0)
	{
	UBYTE partial = *packed++;
	int partCount = 4 - remainder;
	for (i=partCount-1; i>=0; --i)
	    {
	    dna[i] = valToNt[partial&3];
	    partial >>= 2;
	    }
	midStart += partCount;
	dna += partCount;
	}

    /* Handle middle bytes. */
    remainder = fragEnd&3;
    midEnd = fragEnd - remainder;
    for (i=midStart; i<midEnd; i += 4)
        {
	UBYTE b = *packed++;
	dna[3] = valToNt[b&3];
	b >>= 2;
	dna[2] = valToNt[b&3];
	b >>= 2;
	dna[1] = valToNt[b&3];
	b >>= 2;
	dna[0] = valToNt[b&3];
	dna += 4;
	}

    if (remainder >0)
	{
	UBYTE part = *packed;
	part >>= (8-remainder-remainder);
	for (i=remainder-1; i>=0; --i)
	    {
	    dna[i] = valToNt[part&3];
	    part >>= 2;
	    }
	}
    }
freez(&packedAlloc);

if (twoBit->nBlockCount > 0)
    {
    int startIx = findGreatestLowerBound(twoBit->nBlockCount, twoBit->nStarts, fragStart);
    for (i=startIx; i<twoBit->nBlockCount; ++i)
        {
	int s = twoBit->nStarts[i];
	int e = s + twoBit->nSizes[i];
	if (s >= fragEnd)
	    break;
	if (s < fragStart)
	   s = fragStart;
	if (e > fragEnd)
	   e = fragEnd;
	if (s < e)
	    memset(seq->dna + s - fragStart, 'n', e - s);
	}
    }

if (doMask)
    {
    toUpperN(seq->dna, seq->size);
    if (twoBit->maskBlockCount > 0)
	{
	int startIx = findGreatestLowerBound(twoBit->maskBlockCount, twoBit->maskStarts,
		fragStart);
	for (i=startIx; i<twoBit->maskBlockCount; ++i)
	    {
	    int s = twoBit->maskStarts[i];
	    int e = s + twoBit->maskSizes[i];
	    if (s >= fragEnd)
		break;
	    if (s < fragStart)
		s = fragStart;
	    if (e > fragEnd)
		e = fragEnd;
	    if (s < e)
		toLowerN(seq->dna + s - fragStart, e - s);
	    }
	}
    }
if (retFullSize != NULL)
    *retFullSize = twoBit->size;
return seq;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq %r9, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movb $0x0, %al
callq 0x34580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5a2e0
movq %rax, -0x78(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x59c35
movq -0x78(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jbe 0x59c5d
movq -0x10(%rbp), %rsi
movl -0x18(%rbp), %edx
movq -0x78(%rbp), %rax
movl 0x18(%rax), %ecx
leaq 0x84aba(%rip), %rdi     # 0xde710
movb $0x0, %al
callq 0x35d40
movl -0x18(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x58(%rbp)
cmpl $0x1, -0x58(%rbp)
jge 0x59c84
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
leaq 0x84ac4(%rip), %rdi     # 0xde741
movb $0x0, %al
callq 0x35d40
movl $0x28, %edi
callq 0x40c50
movq %rax, -0x30(%rbp)
movl -0x58(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0x59cb4
movq -0x10(%rbp), %rdi
callq 0x2a450
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x59cf1
leaq -0x280(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl -0x14(%rbp), %r8d
movl -0x18(%rbp), %r9d
movl $0x200, %esi            # imm = 0x200
leaq 0x843bb(%rip), %rdx     # 0xde08e
movb $0x0, %al
callq 0x31090
leaq -0x280(%rbp), %rdi
callq 0x2a450
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x58(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x40950
movq -0x30(%rbp), %rcx
movq %rax, 0x10(%rcx)
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x58(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x14(%rbp), %eax
sarl $0x2, %eax
movl %eax, -0x44(%rbp)
movl -0x18(%rbp), %eax
addl $0x3, %eax
sarl $0x2, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
subl -0x44(%rbp), %eax
movl %eax, -0x40(%rbp)
movslq -0x40(%rbp), %rdi
callq 0x40950
movq %rax, -0x68(%rbp)
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq *%rax
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x38(%rbp), %rdi
movq -0x60(%rbp), %rsi
movslq -0x40(%rbp), %rdx
callq *%rax
cmpl $0x1, -0x40(%rbp)
jne 0x59e6c
movl -0x44(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x284(%rbp)
movl -0x14(%rbp), %eax
subl -0x284(%rbp), %eax
movl %eax, -0x288(%rbp)
movl -0x18(%rbp), %eax
subl -0x284(%rbp), %eax
movl %eax, -0x28c(%rbp)
movq -0x60(%rbp), %rax
movb (%rax), %al
movb %al, -0x28d(%rbp)
cmpl $0x4, -0x28c(%rbp)
jg 0x59dca
jmp 0x59de9
leaq 0x8499f(%rip), %rdi     # 0xde770
leaq 0x849a2(%rip), %rsi     # 0xde77a
movl $0x30f, %edx            # imm = 0x30F
leaq 0x849a3(%rip), %rcx     # 0xde787
callq 0x6450
cmpl $0x0, -0x288(%rbp)
jl 0x59df4
jmp 0x59e13
leaq 0x849e3(%rip), %rdi     # 0xde7de
leaq 0x84978(%rip), %rsi     # 0xde77a
movl $0x310, %edx            # imm = 0x310
leaq 0x84979(%rip), %rcx     # 0xde787
callq 0x6450
movl -0x288(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x28c(%rbp), %eax
jge 0x59e67
movzbl -0x28d(%rbp), %eax
movl $0x6, %ecx
subl -0x3c(%rbp), %ecx
subl -0x3c(%rbp), %ecx
sarl %cl, %eax
andl $0x3, %eax
movslq %eax, %rcx
leaq 0xae668(%rip), %rax     # 0x1084b0
movb (%rax,%rcx), %cl
movq -0x70(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x70(%rbp)
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x59e1c
jmp 0x5a091
movl -0x14(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x14(%rbp), %eax
andl $0x3, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jle 0x59f19
movq -0x60(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x60(%rbp)
movb (%rax), %al
movb %al, -0x28e(%rbp)
movl $0x4, %eax
subl -0x4c(%rbp), %eax
movl %eax, -0x294(%rbp)
movl -0x294(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x59ef9
movzbl -0x28e(%rbp), %eax
andl $0x3, %eax
movslq %eax, %rcx
leaq 0xae5e0(%rip), %rax     # 0x1084b0
movb (%rax,%rcx), %dl
movq -0x70(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movzbl -0x28e(%rbp), %eax
sarl $0x2, %eax
movb %al, -0x28e(%rbp)
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x59eb6
movl -0x294(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x294(%rbp), %ecx
movq -0x70(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl -0x18(%rbp), %eax
andl $0x3, %eax
movl %eax, -0x4c(%rbp)
movl -0x18(%rbp), %eax
subl -0x4c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x5a015
movq -0x60(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x60(%rbp)
movb (%rax), %al
movb %al, -0x295(%rbp)
movzbl -0x295(%rbp), %eax
andl $0x3, %eax
movslq %eax, %rcx
leaq 0xae548(%rip), %rax     # 0x1084b0
movb (%rax,%rcx), %cl
movq -0x70(%rbp), %rax
movb %cl, 0x3(%rax)
movzbl -0x295(%rbp), %eax
sarl $0x2, %eax
movb %al, -0x295(%rbp)
movzbl -0x295(%rbp), %eax
andl $0x3, %eax
movslq %eax, %rcx
leaq 0xae51a(%rip), %rax     # 0x1084b0
movb (%rax,%rcx), %cl
movq -0x70(%rbp), %rax
movb %cl, 0x2(%rax)
movzbl -0x295(%rbp), %eax
sarl $0x2, %eax
movb %al, -0x295(%rbp)
movzbl -0x295(%rbp), %eax
andl $0x3, %eax
movslq %eax, %rcx
leaq 0xae4ec(%rip), %rax     # 0x1084b0
movb (%rax,%rcx), %cl
movq -0x70(%rbp), %rax
movb %cl, 0x1(%rax)
movzbl -0x295(%rbp), %eax
sarl $0x2, %eax
movb %al, -0x295(%rbp)
movzbl -0x295(%rbp), %eax
andl $0x3, %eax
movslq %eax, %rcx
leaq 0xae4be(%rip), %rax     # 0x1084b0
movb (%rax,%rcx), %cl
movq -0x70(%rbp), %rax
movb %cl, (%rax)
movq -0x70(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x70(%rbp)
movl -0x3c(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x3c(%rbp)
jmp 0x59f31
cmpl $0x0, -0x4c(%rbp)
jle 0x5a08f
movq -0x60(%rbp), %rax
movb (%rax), %al
movb %al, -0x296(%rbp)
movl $0x8, %ecx
subl -0x4c(%rbp), %ecx
subl -0x4c(%rbp), %ecx
movzbl -0x296(%rbp), %eax
sarl %cl, %eax
movb %al, -0x296(%rbp)
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x5a08d
movzbl -0x296(%rbp), %eax
andl $0x3, %eax
movslq %eax, %rcx
leaq 0xae44c(%rip), %rax     # 0x1084b0
movb (%rax,%rcx), %dl
movq -0x70(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movzbl -0x296(%rbp), %eax
sarl $0x2, %eax
movb %al, -0x296(%rbp)
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5a04a
jmp 0x5a08f
jmp 0x5a091
leaq -0x68(%rbp), %rdi
callq 0x40d70
movq -0x78(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jbe 0x5a19a
movq -0x78(%rbp), %rax
movl 0x1c(%rax), %edi
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rsi
movl -0x14(%rbp), %edx
callq 0x5a390
movl %eax, -0x29c(%rbp)
movl -0x29c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jae 0x5a198
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2a0(%rbp)
movl -0x2a0(%rbp), %eax
movq -0x78(%rbp), %rcx
movq 0x28(%rcx), %rcx
movslq -0x3c(%rbp), %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, -0x2a4(%rbp)
movl -0x2a0(%rbp), %eax
cmpl -0x18(%rbp), %eax
jl 0x5a11b
jmp 0x5a198
movl -0x2a0(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x5a12f
movl -0x14(%rbp), %eax
movl %eax, -0x2a0(%rbp)
movl -0x2a4(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x5a143
movl -0x18(%rbp), %eax
movl %eax, -0x2a4(%rbp)
movl -0x2a0(%rbp), %eax
cmpl -0x2a4(%rbp), %eax
jge 0x5a188
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x2a0(%rbp), %rax
addq %rax, %rdi
movslq -0x14(%rbp), %rcx
xorl %eax, %eax
subq %rcx, %rax
addq %rax, %rdi
movl -0x2a4(%rbp), %eax
subl -0x2a0(%rbp), %eax
movslq %eax, %rdx
movl $0x6e, %esi
callq 0x63a0
jmp 0x5a18a
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5a0ce
jmp 0x5a19a
cmpl $0x0, -0x1c(%rbp)
je 0x5a2b2
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x2dc40
movq -0x78(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jbe 0x5a2b0
movq -0x78(%rbp), %rax
movl 0x30(%rax), %edi
movq -0x78(%rbp), %rax
movq 0x38(%rax), %rsi
movl -0x14(%rbp), %edx
callq 0x5a390
movl %eax, -0x2a8(%rbp)
movl -0x2a8(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jae 0x5a2ae
movq -0x78(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2ac(%rbp)
movl -0x2ac(%rbp), %eax
movq -0x78(%rbp), %rcx
movq 0x40(%rcx), %rcx
movslq -0x3c(%rbp), %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, -0x2b0(%rbp)
movl -0x2ac(%rbp), %eax
cmpl -0x18(%rbp), %eax
jl 0x5a239
jmp 0x5a2ae
movl -0x2ac(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x5a24d
movl -0x14(%rbp), %eax
movl %eax, -0x2ac(%rbp)
movl -0x2b0(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x5a261
movl -0x18(%rbp), %eax
movl %eax, -0x2b0(%rbp)
movl -0x2ac(%rbp), %eax
cmpl -0x2b0(%rbp), %eax
jge 0x5a29e
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x2ac(%rbp), %rax
addq %rax, %rdi
movslq -0x14(%rbp), %rcx
xorl %eax, %eax
subq %rcx, %rax
addq %rax, %rdi
movl -0x2b0(%rbp), %esi
subl -0x2ac(%rbp), %esi
callq 0x2dc90
jmp 0x5a2a0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5a1ec
jmp 0x5a2b0
jmp 0x5a2b2
cmpq $0x0, -0x28(%rbp)
je 0x5a2c6
movq -0x78(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
nopw %cs:(%rax,%rax)