// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/jkOwnLib/gfBlatLib.c
// Function: gfAlignTransTrans
void gfAlignTransTrans(int *pConn, char *tSeqDir, struct dnaSeq *qSeq, 
	boolean qIsRc, int minMatch, struct hash *tFileCache, 
	struct gfOutput *out, boolean isRna)
/* Search indexed translated genome on server with an dna sequence.  Translate
 * this sequence in three frames. Load homologous bits of genome locally
 * and do detailed alignment.  Call 'outFunction' with each alignment
 * that is found. */
{
struct gfClump *clumps[2][3][3], *clump;
char targetName[PATH_LEN];
int qFrame, tFrame, tIsRc;
struct gfSeqSource *ssList = NULL, *ss;
struct lm *lm = lmInit(0);
int tileSize;
struct gfRange *rangeList = NULL, *rl, *range;
struct trans3 *qTrans = trans3New(qSeq), *t3;
struct slRef *t3RefList = NULL, *t3Ref;
struct hash *t3Hash = NULL;
struct dnaSeq *tSeqList = NULL;
enum ffStringency stringency = (isRna ? ffCdna : ffLoose);

/* Query server for clumps. */
gfQuerySeqTransTrans(*pConn, qSeq, clumps, lm, &ssList, &tileSize);
close(*pConn);
*pConn = -1;

for (tIsRc=0; tIsRc <= 1; ++tIsRc)
    {
    /* Figure out which ranges need to be loaded and load them. */
    for (qFrame = 0; qFrame < 3; ++qFrame)
        {
        for (tFrame = 0; tFrame < 3; ++tFrame)
            {
	    rl = seqClumpToRangeList(clumps[tIsRc][qFrame][tFrame], tFrame);
	    rangeList = slCat(rangeList, rl);
	    }
	}
    rangeCoorTimes3(rangeList);
    slSort(&rangeList, gfRangeCmpTarget);
    rangeList = gfRangesBundle(rangeList, ffIntronMax);
    loadHashT3Ranges(rangeList, tSeqDir, tFileCache,
    	qSeq->size/3, tIsRc, &t3Hash, &tSeqList, &t3RefList);

    /* The old range list was not very precise - it was just to get
     * the DNA loaded.  */
    gfRangeFreeList(&rangeList);

    /* Patch up clump list and associated sequence source to refer
     * to bits of genome loaded into memory.  Create new range list
     * by extending hits in clumps. */
    for (qFrame = 0; qFrame < 3; ++qFrame)
	{
	for (tFrame = 0; tFrame < 3; ++tFrame)
	    {
	    for (clump = clumps[tIsRc][qFrame][tFrame]; clump != NULL; clump = clump->next)
		{
		struct gfSeqSource *ss = clump->target;
		struct gfRange *rangeSet = NULL;
		t3 = trans3Find(t3Hash, clumpTargetName(clump), clump->tStart*3, clump->tEnd*3);
		ss->seq = t3->trans[tFrame];
		ss->start = t3->start/3;
		ss->end = t3->end/3;
		clumpToHspRange(clump, qTrans->trans[qFrame], tileSize, tFrame, t3, &rangeSet, TRUE, FALSE);
		untranslateRangeList(rangeSet, qFrame, tFrame, NULL, t3, t3->start);
		rangeList = slCat(rangeSet, rangeList);
		}
	    }
	}
    slReverse(&rangeList);
    slSort(&rangeList, gfRangeCmpTarget);
    rangeList = gfRangesBundle(rangeList, ffIntronMax);

    for (range = rangeList; range != NULL; range = range->next)
	{
	struct dnaSeq *targetSeq = range->tSeq;
	struct ssBundle *bun;

	AllocVar(bun);
	bun->qSeq = qSeq;
	bun->genoSeq = targetSeq;
	bun->ffList = gfRangesToFfItem(range->components, qSeq);
	ssStitch(bun, stringency, minMatch, ssAliCount);
	getTargetName(range->tName, out->includeTargetFile, targetName);
	t3 = range->t3;
	saveAlignments(targetName, t3->nibSize, t3->start, 
	    bun, NULL, qIsRc, tIsRc, stringency, minMatch, out);
	ssBundleFree(&bun);
	}

    /* Cleanup for this strand of database. */
    gfRangeFreeList(&rangeList);
    freeHash(&t3Hash);
    for (t3Ref = t3RefList; t3Ref != NULL; t3Ref = t3Ref->next)
        {
	struct trans3 *t3 = t3Ref->val;
	trans3Free(&t3);
	}
    slFreeList(&t3RefList);
    freeDnaSeqList(&tSeqList);
    }
trans3Free(&qTrans);
for (ss = ssList; ss != NULL; ss = ss->next)
    freeMem(ss->fileName);
slFreeList(&ssList);
lmCleanup(&lm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x398, %rsp            # imm = 0x398
movq %r9, 0xe8(%rsp)
movq %r8, 0xe0(%rsp)
movl %ecx, 0x4c(%rsp)
movq %rdx, %r12
movq %rsi, 0xd8(%rsp)
movq %rdi, %r14
xorl %ebx, %ebx
movq %rbx, 0x40(%rsp)
xorl %edi, %edi
callq 0x2bea4
movq %rax, 0x68(%rsp)
movq %rbx, 0x8(%rsp)
movq %r12, %rdi
callq 0x15d78
movq %rax, 0x60(%rsp)
movq %rbx, 0x38(%rsp)
movq %rbx, 0x30(%rsp)
cmpl $0x0, 0x3d8(%rsp)
movl $0x0, %eax
movq %rax, 0x50(%rsp)
movq %rbx, 0x58(%rsp)
sete 0x20(%rsp)
movq %r14, 0x28(%rsp)
movl (%r14), %ebp
movq 0x68(%rsp), %r13
leaq 0x100(%rsp), %r15
movl $0x90, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x63b0
leaq 0x7c86a(%rip), %rdx     # 0x8dfa3
movl %ebp, %edi
movq %r12, %rsi
callq 0x129f6
leaq 0x190(%rsp), %rsi
movl %ebp, %edi
callq 0x30e9d
movq %rax, %rbx
leaq 0x7c677(%rip), %rdi     # 0x8ddd3
movq %rax, %rsi
callq 0x217c8
testl %eax, %eax
movq %r12, 0x18(%rsp)
je 0x11790
movq 0x8(%r12), %rsi
leaq 0x7c6cf(%rip), %rdi     # 0x8de48
leaq 0x190(%rsp), %rdx
xorl %eax, %eax
callq 0x268ca
xorl %r14d, %r14d
jmp 0x11993
movq %rbx, %rdi
callq 0x12aac
movq %rax, 0x50(%rsp)
leaq 0x190(%rsp), %rbx
xorl %r14d, %r14d
movl %ebp, %edi
movq %rbx, %rsi
callq 0x30e9d
cmpl $0x646e65, 0x190(%rsp) # imm = 0x646E65
je 0x11948
leaq 0x7c609(%rip), %rdi     # 0x8ddd3
movq %rbx, %rsi
callq 0x217c8
testl %eax, %eax
jne 0x1192d
movq %r13, %r15
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
movl $0xc, %edx
callq 0x223ad
cmpl $0x8, %eax
jg 0x11804
leaq 0x7c7b3(%rip), %rdi     # 0x8dfae
movl %eax, %esi
xorl %eax, %eax
callq 0x26b6f
movl $0x38, %edi
callq 0x2dc95
movq %rax, %rbx
movq 0x70(%rsp), %rdi
callq 0x3b838
movl %eax, 0x8(%rbx)
movq 0x78(%rsp), %rdi
callq 0x3b838
movl %eax, 0xc(%rbx)
movl $0x28, %edi
callq 0x2dc95
movq %rax, %r12
movq 0x80(%rsp), %rdi
callq 0x1f9f6
movq %rax, 0x8(%r12)
movq %r14, (%r12)
movq %r12, 0x10(%rbx)
movq 0x88(%rsp), %rdi
callq 0x3b838
movl %eax, 0x18(%rbx)
movq 0x90(%rsp), %rdi
callq 0x3b838
movl %eax, 0x1c(%rbx)
movq 0x98(%rsp), %rdi
callq 0x3b838
movl %eax, 0x20(%rbx)
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rdi
xorl %r13d, %r13d
cmpb $0x2d, (%rax)
sete %r13b
callq 0x3b838
movl %eax, %r14d
movq 0xb0(%rsp), %rdi
callq 0x3b838
movslq %r14d, %rcx
cltq
leaq (%rcx,%rcx,2), %rcx
leaq (,%r13,8), %rdx
addq %r13, %rdx
leaq 0x100(%rsp,%rdx,8), %rdx
leaq (%rdx,%rcx,8), %rcx
movq (%rcx,%rax,8), %rdx
movq %rdx, (%rbx)
movq %rbx, (%rcx,%rax,8)
movl %ebp, %edi
movq %r15, %r13
movq %r15, %rsi
callq 0xfb6b
movq %rax, 0x28(%rbx)
movq %rax, %rdi
callq 0x1fbec
movq %r12, %r14
cmpl 0x20(%rbx), %eax
movq 0x18(%rsp), %r12
leaq 0x190(%rsp), %rbx
je 0x117a8
leaq 0x7c5fd(%rip), %rdi     # 0x8df12
leaq 0x7c49c(%rip), %rsi     # 0x8ddb8
leaq 0x7c6b0(%rip), %rcx     # 0x8dfd3
movl $0x152, %edx            # imm = 0x152
callq 0x6460
movq 0x8(%r12), %rsi
leaq 0x7c50f(%rip), %rdi     # 0x8de48
leaq 0x190(%rsp), %rdx
xorl %eax, %eax
callq 0x268ca
leaq 0x100(%rsp), %rbx
xorl %r15d, %r15d
movq %rbx, %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
leaq (%r12,%rbp), %rdi
callq 0x1fcb3
addq $0x8, %rbp
cmpq $0x18, %rbp
jne 0x1195b
incq %r13
addq $0x18, %r12
cmpq $0x3, %r13
jne 0x11959
leaq 0x1(%r15), %rax
addq $0x48, %rbx
testq %r15, %r15
movq %rax, %r15
je 0x11953
leaq 0x100(%rsp), %r15
xorl %eax, %eax
movb 0x20(%rsp), %cl
movb %cl, %al
leal 0x1(,%rax,2), %r12d
movq %r14, 0x40(%rsp)
movq 0x28(%rsp), %rbx
movl (%rbx), %edi
callq 0x6e80
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq 0x38(%rsp), %r13
leaq 0x58(%rsp), %rbp
movq $0x0, 0x10(%rsp)
movq %r12, 0xf8(%rsp)
movq %r15, 0xf0(%rsp)
movq %r15, %rbx
xorl %r15d, %r15d
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rdi
movl %r14d, %esi
callq 0x113da
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x1fc95
movq %rax, 0x8(%rsp)
incq %r14
cmpq $0x3, %r14
jne 0x119e6
incq %r15
addq $0x18, %rbx
cmpq $0x3, %r15
jne 0x119e3
movq 0x8(%rsp), %rdi
callq 0x10cea
leaq 0x8(%rsp), %rdi
leaq -0x1f08(%rip), %rsi     # 0xfb28
callq 0x1fd04
movq 0x8(%rsp), %rdi
leaq 0xaf12f(%rip), %rax     # 0xc0b70
movl (%rax), %esi
callq 0xfc3f
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rcx
movslq 0x18(%rcx), %rcx
imulq $0x55555556, %rcx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
movq %rax, %rdi
movq 0xd8(%rsp), %rsi
movq 0xe8(%rsp), %rdx
movq 0x10(%rsp), %r15
movl %r15d, %r8d
leaq 0x30(%rsp), %r9
pushq %r13
pushq %rbp
callq 0x114bc
addq $0x10, %rsp
movq 0x8(%rsp), %rbx
movq %rbx, 0x70(%rsp)
testq %rbx, %rbx
leaq 0x70(%rsp), %r14
je 0x11abf
movq (%rbx), %rbx
movq %r14, %rdi
callq 0xfa88
movq %rbx, 0x70(%rsp)
testq %rbx, %rbx
jne 0x11aaa
movq $0x0, 0x8(%rsp)
leaq (%r15,%r15,8), %rax
leaq (%rsp,%rax,8), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
leaq (%r15,%r15,2), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
movq 0x28(%rsp), %rax
movq (%rax,%r12,8), %rbp
testq %rbp, %rbp
je 0x11c01
movq 0x10(%rbp), %r13
movq $0x0, 0x70(%rsp)
movq 0x30(%rsp), %r14
movq 0x10(%r13), %rax
testq %rax, %rax
cmoveq %r13, %rax
movq 0x8(%rax), %rbx
testq %rbx, %rbx
jne 0x11b45
leaq 0x7c089(%rip), %rdi     # 0x8dbbb
leaq 0x7c27f(%rip), %rsi     # 0x8ddb8
movl $0x251, %edx            # imm = 0x251
xorl %eax, %eax
callq 0x26b6f
movl 0x18(%rbp), %eax
movl 0x1c(%rbp), %ecx
leal (%rax,%rax,2), %edx
leal (%rcx,%rcx,2), %ecx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x15e63
movq %rax, %r14
movq 0x18(%rax,%r12,8), %rax
movq %rax, 0x10(%r13)
movslq 0x30(%r14), %rax
imulq $0x55555556, %rax, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rax
addl %ecx, %eax
movl %eax, 0x18(%r13)
movslq 0x34(%r14), %rax
imulq $0x55555556, %rax, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rax
addl %ecx, %eax
movl %eax, 0x1c(%r13)
movq 0x60(%rsp), %rax
movq 0x18(%rax,%r15,8), %rsi
movq %rbp, %rdi
movq 0x50(%rsp), %rdx
movl %r12d, %ecx
movq %r14, %r8
leaq 0x70(%rsp), %r9
pushq $0x0
pushq $0x1
callq 0x1088d
addq $0x10, %rsp
movq 0x70(%rsp), %rbx
movl 0x30(%r14), %r9d
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
xorl %ecx, %ecx
movq %r14, %r8
callq 0x115f6
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1fc95
movq %rax, 0x8(%rsp)
movq (%rbp), %rbp
jmp 0x11afc
incq %r12
cmpq $0x3, %r12
jne 0x11af3
incq %r15
cmpq $0x3, %r15
jne 0x11ade
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1fcb3
movq %rbx, %rdi
leaq -0x210a(%rip), %rsi     # 0xfb28
callq 0x1fd04
movq 0x8(%rsp), %rdi
leaq 0xaef2d(%rip), %rax     # 0xc0b70
movl (%rax), %esi
callq 0xfc3f
movq %rax, 0x8(%rsp)
testq %rax, %rax
movq 0xe0(%rsp), %rbx
movq 0x18(%rsp), %r14
movq 0x3d0(%rsp), %r13
movq 0x10(%rsp), %r12
je 0x11d24
movq %rax, %r15
movq %r13, %rbp
movq %rbx, %r13
movq 0x18(%r15), %rbx
movl $0x48, %edi
callq 0x2dc95
movq %rax, 0x70(%rsp)
movq %r14, 0x10(%rax)
movq %rbx, 0x18(%rax)
movq %r13, %rbx
movq %rbp, %r13
movq 0x28(%r15), %rdi
movq %r14, %rsi
callq 0x10414
movq 0x70(%rsp), %rdi
movq %rax, 0x8(%rdi)
movq 0xf8(%rsp), %r14
movl %r14d, %esi
movl %ebx, %edx
movl $0x10, %ecx
callq 0x14ecb
movq 0x10(%r15), %rdi
movl 0x48(%rbp), %esi
leaq 0x190(%rsp), %rbp
movq %rbp, %rdx
callq 0x100d0
movq 0x38(%r15), %rax
movl 0x30(%rax), %edx
movl 0x38(%rax), %esi
movq 0x70(%rsp), %rcx
movq %rbp, %rdi
xorl %r8d, %r8d
movl 0x4c(%rsp), %r9d
pushq %r13
pushq %rbx
pushq %r14
movq 0x30(%rsp), %r14
pushq %r12
callq 0x1022f
addq $0x20, %rsp
leaq 0x70(%rsp), %rdi
callq 0x14940
movq (%r15), %r15
testq %r15, %r15
jne 0x11c75
movq 0x8(%rsp), %rbx
movq %rbx, 0x70(%rsp)
testq %rbx, %rbx
leaq 0x38(%rsp), %r13
leaq 0x58(%rsp), %rbp
leaq 0x70(%rsp), %r14
je 0x11d57
movq (%rbx), %rbx
movq %r14, %rdi
callq 0xfa88
movq %rbx, 0x70(%rsp)
testq %rbx, %rbx
jne 0x11d42
movq $0x0, 0x8(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x29565
movq 0x38(%rsp), %rbx
testq %rbx, %rbx
movq 0xf0(%rsp), %r15
je 0x11d95
movq 0x8(%rbx), %rax
movq %rax, 0x70(%rsp)
movq %r14, %rdi
callq 0x15ddb
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x11d7c
movq %r13, %rdi
callq 0x1fcd6
movq %rbp, %rdi
callq 0x24af5
movq 0x10(%rsp), %rcx
leaq 0x1(%rcx), %rax
addq $0x48, %r15
testq %rcx, %rcx
movq %rax, 0x10(%rsp)
je 0x119d5
leaq 0x60(%rsp), %rdi
callq 0x15ddb
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0x11de2
movq 0x8(%rbx), %rdi
callq 0x2dd41
movq (%rbx), %rbx
jmp 0x11dcf
leaq 0x40(%rsp), %rdi
callq 0x1fcd6
leaq 0x68(%rsp), %rdi
callq 0x2bf4b
addq $0x398, %rsp            # imm = 0x398
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq