// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/jkOwnLib/gfInternal.c
// Function: gfiExpandAndLoadCached
struct dnaSeq *gfiExpandAndLoadCached(struct gfRange *range, 
	struct hash *tFileCache, char *tSeqDir, int querySize, 
	int *retTotalSeqSize, boolean respectFrame, boolean isRc, int expansion)
/* Expand range to cover an additional expansion bases on either side.
 * Load up target sequence and return. (Done together because don't
 * know target size before loading.) */
{
struct dnaSeq *target = NULL;
char fileName[PATH_LEN+256];

safef(fileName, sizeof(fileName), "%s/%s", tSeqDir, range->tName);
if (nibIsFile(fileName))
    {
    struct nibInfo *nib = hashFindVal(tFileCache, fileName);
    if (nib == NULL)
        {
	nib = nibInfoNew(fileName);
	hashAdd(tFileCache, fileName, nib);
	}
    if (isRc)
	reverseIntRange(&range->tStart, &range->tEnd, nib->size);
    gfiExpandRange(range, querySize, nib->size, respectFrame, isRc, expansion);
    target = nibLdPart(fileName, nib->f, nib->size, 
    	range->tStart, range->tEnd - range->tStart);
    if (isRc)
	{
	reverseComplement(target->dna, target->size);
	reverseIntRange(&range->tStart, &range->tEnd, nib->size);
	}
    *retTotalSeqSize = nib->size;
    }
else
    {
    struct twoBitFile *tbf = NULL;
    // split a filename+chrom like "/gbdb/hg19/hg19.2bit:chr1"
    // (can also be URL like "http://hgdownload.soe.ucsc.edu/gbdb/hg19/hg19.2bit:chr1")
    // into filename and tSeqName
    char *tSeqName = strrchr(fileName, ':');
    int tSeqSize = 0;
    if (tSeqName == NULL)
        errAbort("No colon in .2bit response from gfServer");
    *tSeqName++ = 0;
    tbf = hashFindVal(tFileCache, fileName);
    if (tbf == NULL)
        {
	tbf = twoBitOpen(fileName);
	hashAdd(tFileCache, fileName, tbf);
	}
    tSeqSize = twoBitSeqSize(tbf, tSeqName);
    if (isRc)
	reverseIntRange(&range->tStart, &range->tEnd, tSeqSize);
    gfiExpandRange(range, querySize, tSeqSize, respectFrame, isRc, expansion);
    target = twoBitReadSeqFragLower(tbf, tSeqName, range->tStart, range->tEnd);
    if (isRc)
	{
	reverseComplement(target->dna, target->size);
	reverseIntRange(&range->tStart, &range->tEnd, tSeqSize);
	}
    *retTotalSeqSize = tSeqSize;
    }
return target;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movl %r9d, %r15d
movq %r8, %rbp
movl %ecx, %r13d
movq %rdx, %rcx
movq %rsi, %r12
movq %rdi, %r14
movq 0x10(%rdi), %r8
leaq 0x7f8e7(%rip), %rdx     # 0x92b39
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl $0x300, %esi            # imm = 0x300
xorl %eax, %eax
callq 0x23c18
movq %rbx, %rdi
callq 0x3221b
testl %eax, %eax
je 0x13331
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x29029
movq %rax, %rbx
testq %rax, %rax
jne 0x132a8
leaq 0x10(%rsp), %rdi
callq 0x32301
movq %rax, %rbx
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0x28dbe
movl 0x350(%rsp), %r12d
testl %r12d, %r12d
je 0x132c5
leaq 0x20(%r14), %rdi
leaq 0x24(%r14), %rsi
movl 0x10(%rbx), %edx
callq 0x25145
movl 0x10(%rbx), %edx
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %ecx
movl %r12d, %r8d
movl 0x358(%rsp), %r9d
callq 0x13130
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movl 0x20(%r14), %ecx
movl 0x24(%r14), %r8d
subl %ecx, %r8d
leaq 0x10(%rsp), %rdi
callq 0x31db3
movq %rax, %r15
testl %r12d, %r12d
je 0x13328
leaq 0x20(%r14), %r12
addq $0x24, %r14
movq 0x10(%r15), %rdi
movslq 0x18(%r15), %rsi
callq 0x250f6
movl 0x10(%rbx), %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x25145
movl 0x10(%rbx), %r12d
jmp 0x13426
movq %rbp, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
movl $0x3a, %esi
callq 0x67c0
movq %rax, %rbx
movq %rax, %rbp
testq %rax, %rax
jne 0x1335e
leaq 0x7ae40(%rip), %rdi     # 0x8e197
xorl %eax, %eax
callq 0x26b6f
incq %rbx
movb $0x0, (%rbp)
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x29029
movq %rax, %rbp
testq %rax, %rax
jne 0x13397
leaq 0x10(%rsp), %rdi
callq 0x3e08d
movq %rax, %rbp
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0x28dbe
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3e8b2
movl %eax, %r12d
cmpl $0x0, 0x350(%rsp)
je 0x133bf
leaq 0x20(%r14), %rdi
leaq 0x24(%r14), %rsi
movl %r12d, %edx
callq 0x25145
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl 0x350(%rsp), %r13d
movl %r13d, %r8d
movl 0x358(%rsp), %r9d
callq 0x13130
movl 0x20(%r14), %edx
movl 0x24(%r14), %ecx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3e8a7
movq %rax, %r15
testl %r13d, %r13d
je 0x13421
leaq 0x20(%r14), %rbx
addq $0x24, %r14
movq 0x10(%r15), %rdi
movslq 0x18(%r15), %rsi
callq 0x250f6
movq %rbx, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x25145
movq 0x8(%rsp), %rbp
movl %r12d, (%rbp)
movq %r15, %rax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq