// File: /workspace/github_c_makefile_star2_O2/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 0x71297(%rip), %rdx     # 0x81b0a
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl $0x300, %esi            # imm = 0x300
xorl %eax, %eax
callq 0x1fab2
movq %rbx, %rdi
callq 0x2ce73
testl %eax, %eax
je 0x10952
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x244c6
movq %rax, %rbx
testq %rax, %rax
jne 0x108c9
leaq 0x10(%rsp), %rdi
callq 0x2cf20
movq %rax, %rbx
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0x242d0
movl 0x350(%rsp), %r12d
testl %r12d, %r12d
je 0x108e6
leaq 0x20(%r14), %rdi
leaq 0x24(%r14), %rsi
movl 0x10(%rbx), %edx
callq 0x20d61
movl 0x10(%rbx), %edx
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %ecx
movl %r12d, %r8d
movl 0x358(%rsp), %r9d
callq 0x107a8
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
movl 0x20(%r14), %ecx
movl 0x24(%r14), %r8d
subl %ecx, %r8d
leaq 0x10(%rsp), %rdi
callq 0x2ca0c
movq %rax, %r15
testl %r12d, %r12d
je 0x10949
leaq 0x20(%r14), %r12
addq $0x24, %r14
movq 0x10(%r15), %rdi
movslq 0x18(%r15), %rsi
callq 0x20d38
movl 0x10(%rbx), %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x20d61
movl 0x10(%rbx), %r12d
jmp 0x10a45
movq %rbp, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
pushq $0x3a
popq %rsi
callq 0x67c0
movq %rax, %rbx
movq %rax, %rbp
testq %rax, %rax
jne 0x1097d
leaq 0x6c801(%rip), %rdi     # 0x7d177
xorl %eax, %eax
callq 0x223fb
incq %rbx
movb $0x0, (%rbp)
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x244c6
movq %rax, %rbp
testq %rax, %rax
jne 0x109b6
leaq 0x10(%rsp), %rdi
callq 0x3842b
movq %rax, %rbp
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0x242d0
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x38be6
movl %eax, %r12d
cmpl $0x0, 0x350(%rsp)
je 0x109de
leaq 0x20(%r14), %rdi
leaq 0x24(%r14), %rsi
movl %r12d, %edx
callq 0x20d61
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl 0x350(%rsp), %r13d
movl %r13d, %r8d
movl 0x358(%rsp), %r9d
callq 0x107a8
movl 0x20(%r14), %edx
movl 0x24(%r14), %ecx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x38bdb
movq %rax, %r15
testl %r13d, %r13d
je 0x10a40
leaq 0x20(%r14), %rbx
addq $0x24, %r14
movq 0x10(%r15), %rdi
movslq 0x18(%r15), %rsi
callq 0x20d38
movq %rbx, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x20d61
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