// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %rbx
subq $0x3a8, %rsp            # imm = 0x3A8
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x2e8(%rbp)
xorl %edi, %edi
callq 0x3dc20
movq %rax, -0x2f8(%rbp)
movq $0x0, -0x308(%rbp)
movq -0x20(%rbp), %rdi
callq 0x1a4b0
movq %rax, -0x320(%rbp)
movq $0x0, -0x330(%rbp)
movq $0x0, -0x340(%rbp)
movq $0x0, -0x348(%rbp)
movl 0x18(%rbp), %edx
movl $0x3, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x34c(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x20(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
movq -0x2f8(%rbp), %rcx
leaq -0x2e8(%rbp), %r8
leaq -0x2fc(%rbp), %r9
callq 0x140f0
movq -0x10(%rbp), %rax
movl (%rax), %edi
callq 0x6e90
movq -0x10(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0x2dc(%rbp)
cmpl $0x1, -0x2dc(%rbp)
jg 0x14087
movl $0x0, -0x2d4(%rbp)
cmpl $0x3, -0x2d4(%rbp)
jge 0x13bda
movl $0x0, -0x2d8(%rbp)
cmpl $0x3, -0x2d8(%rbp)
jge 0x13bc4
movslq -0x2dc(%rbp), %rcx
leaq -0xc0(%rbp), %rax
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movslq -0x2d4(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x2d8(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x2d8(%rbp), %esi
callq 0x136d0
movq %rax, -0x310(%rbp)
movq -0x308(%rbp), %rdi
movq -0x310(%rbp), %rsi
callq 0x2aa60
movq %rax, -0x308(%rbp)
movl -0x2d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2d8(%rbp)
jmp 0x13b50
jmp 0x13bc6
movl -0x2d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2d4(%rbp)
jmp 0x13b39
movq -0x308(%rbp), %rdi
callq 0x12d70
leaq -0x308(%rbp), %rdi
leaq -0x23c4(%rip), %rsi     # 0x11830
callq 0x2ab90
movq -0x308(%rbp), %rdi
leaq 0xf3099(%rip), %rax     # 0x106ca0
movl (%rax), %esi
callq 0x119f0
movq %rax, -0x308(%rbp)
movq -0x308(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rax
movq %rax, -0x380(%rbp)
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movq -0x380(%rbp), %rdx
movl %eax, %ecx
movl -0x2dc(%rbp), %r8d
leaq -0x340(%rbp), %r9
leaq -0x348(%rbp), %r10
leaq -0x330(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x137d0
leaq -0x308(%rbp), %rdi
callq 0x117e0
movl $0x0, -0x2d4(%rbp)
cmpl $0x3, -0x2d4(%rbp)
jge 0x13e7b
movl $0x0, -0x2d8(%rbp)
cmpl $0x3, -0x2d8(%rbp)
jge 0x13e65
movslq -0x2dc(%rbp), %rcx
leaq -0xc0(%rbp), %rax
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movslq -0x2d4(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x2d8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
je 0x13e4f
movq -0xc8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x358(%rbp)
movq $0x0, -0x360(%rbp)
movq -0x340(%rbp), %rax
movq %rax, -0x388(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x12300
movq -0x388(%rbp), %rdi
movq %rax, %rsi
movq -0xc8(%rbp), %rax
imull $0x3, 0x18(%rax), %edx
movq -0xc8(%rbp), %rax
imull $0x3, 0x1c(%rax), %ecx
callq 0x1a610
movq %rax, -0x328(%rbp)
movq -0x328(%rbp), %rax
movslq -0x2d8(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rcx
movq -0x358(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x328(%rbp), %rax
movl 0x30(%rax), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x358(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x328(%rbp), %rax
movl 0x34(%rax), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x358(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0xc8(%rbp), %rdi
movq -0x320(%rbp), %rax
movslq -0x2d4(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rsi
movl -0x2fc(%rbp), %edx
movl -0x2d8(%rbp), %ecx
movq -0x328(%rbp), %r8
leaq -0x360(%rbp), %r9
xorl %eax, %eax
movl $0x1, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x12980
movq -0x360(%rbp), %rdi
movl -0x2d4(%rbp), %esi
movl -0x2d8(%rbp), %edx
movq -0x328(%rbp), %r8
movq -0x328(%rbp), %rax
movl 0x30(%rax), %r9d
xorl %eax, %eax
movl %eax, %ecx
callq 0x13960
movq -0x360(%rbp), %rdi
movq -0x308(%rbp), %rsi
callq 0x2aa60
movq %rax, -0x308(%rbp)
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
jmp 0x13cdc
jmp 0x13e51
movl -0x2d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2d8(%rbp)
jmp 0x13c9a
jmp 0x13e67
movl -0x2d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2d4(%rbp)
jmp 0x13c83
leaq -0x308(%rbp), %rdi
callq 0x2aad0
leaq -0x308(%rbp), %rdi
leaq -0x2665(%rip), %rsi     # 0x11830
callq 0x2ab90
movq -0x308(%rbp), %rdi
leaq 0xf2df8(%rip), %rax     # 0x106ca0
movl (%rax), %esi
callq 0x119f0
movq %rax, -0x308(%rbp)
movq -0x308(%rbp), %rax
movq %rax, -0x318(%rbp)
cmpq $0x0, -0x318(%rbp)
je 0x13ffa
movq -0x318(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x368(%rbp)
movl $0x48, %edi
callq 0x40c50
movq %rax, -0x370(%rbp)
movq -0x20(%rbp), %rcx
movq -0x370(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x368(%rbp), %rcx
movq -0x370(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x318(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x12370
movq %rax, %rcx
movq -0x370(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x370(%rbp), %rdi
movl -0x34c(%rbp), %esi
movl -0x28(%rbp), %edx
movl 0xf1ea6(%rip), %ecx     # 0x105df4
callq 0x18b80
movq -0x318(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rbp), %rax
movl 0x48(%rax), %esi
leaq -0x2d0(%rbp), %rdx
callq 0x11f70
movq -0x318(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x328(%rbp)
leaq -0x2d0(%rbp), %rdi
movq -0x328(%rbp), %rax
movl 0x38(%rax), %esi
movq -0x328(%rbp), %rax
movl 0x30(%rax), %edx
movq -0x370(%rbp), %rcx
movl -0x24(%rbp), %r9d
movl -0x2dc(%rbp), %ebx
movl -0x34c(%rbp), %r11d
movl -0x28(%rbp), %r10d
movq 0x10(%rbp), %rax
xorl %r8d, %r8d
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x121d0
leaq -0x370(%rbp), %rdi
callq 0x183a0
movq -0x318(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x318(%rbp)
jmp 0x13ec4
leaq -0x308(%rbp), %rdi
callq 0x117e0
leaq -0x340(%rbp), %rdi
callq 0x3a080
movq -0x330(%rbp), %rax
movq %rax, -0x338(%rbp)
cmpq $0x0, -0x338(%rbp)
je 0x1405b
movq -0x338(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x378(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x1a560
movq -0x338(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x338(%rbp)
jmp 0x14020
leaq -0x330(%rbp), %rdi
callq 0x2ab30
leaq -0x348(%rbp), %rdi
callq 0x32850
movl -0x2dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2dc(%rbp)
jmp 0x13b22
leaq -0x320(%rbp), %rdi
callq 0x1a560
movq -0x2e8(%rbp), %rax
movq %rax, -0x2f0(%rbp)
cmpq $0x0, -0x2f0(%rbp)
je 0x140ce
movq -0x2f0(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x40d40
movq -0x2f0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x2f0(%rbp)
jmp 0x140a1
leaq -0x2e8(%rbp), %rdi
callq 0x2ab30
leaq -0x2f8(%rbp), %rdi
callq 0x3dd90
addq $0x3a8, %rsp            # imm = 0x3A8
popq %rbx
popq %rbp
retq