// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/jkOwnLib/gfBlatLib.c
// Function: gfAlignTrans
void gfAlignTrans(int *pConn, char *tSeqDir, aaSeq *seq, int minMatch, 
    struct hash *tFileCache, struct gfOutput *out)
/* Search indexed translated genome on server with an amino acid sequence. 
 * Then load homologous bits of genome locally and do detailed alignment.
 * Call 'outFunction' with each alignment that is found. */
{
struct ssBundle *bun;
struct gfClump *clumps[2][3], *clump;
struct gfRange *rangeList = NULL, *range, *rl;
struct dnaSeq *targetSeq, *tSeqList = NULL;
char targetName[PATH_LEN];
int tileSize;
int frame, isRc = 0;
struct hash *t3Hash = NULL;
struct slRef *t3RefList = NULL, *ref;
struct gfSeqSource *ssList = NULL, *ss;
struct trans3 *t3;
struct lm *lm = lmInit(0);

/* Get clumps from server. */
gfQuerySeqTrans(*pConn, seq, clumps, lm, &ssList, &tileSize);
close(*pConn);
*pConn = -1;

for (isRc = 0; isRc <= 1;  ++isRc)
    {
    /* Figure out which parts of sequence we need to load. */
    for (frame = 0; frame < 3; ++frame)
	{
	rl = seqClumpToRangeList(clumps[isRc][frame], frame);
	rangeList = slCat(rangeList, rl);
	}
    /* Convert from amino acid to nucleotide coordinates. */
    rangeCoorTimes3(rangeList);
    slSort(&rangeList, gfRangeCmpTarget);
    rangeList = gfRangesBundle(rangeList, ffIntronMax);
    loadHashT3Ranges(rangeList, tSeqDir, tFileCache, seq->size, 
    	isRc, &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 (frame = 0; frame < 3; ++frame)
	{
	for (clump = clumps[isRc][frame]; clump != NULL; clump = clump->next)
	    {
	    struct gfSeqSource *ss = clump->target;
	    t3 = trans3Find(t3Hash, clumpTargetName(clump), clump->tStart*3, clump->tEnd*3);
	    ss->seq = t3->trans[frame];
	    ss->start = t3->start/3;
	    ss->end = t3->end/3;
	    clumpToHspRange(clump, seq, tileSize, frame, t3, &rangeList, TRUE, FALSE);
	    }
	}
    slReverse(&rangeList);
    slSort(&rangeList, gfRangeCmpTarget);
    rangeList = gfRangesBundle(rangeList, ffIntronMax/3);

    /* Do detailed alignment of each of the clustered ranges. */
    for (range = rangeList; range != NULL; range = range->next)
	{
	targetSeq = range->tSeq;
	AllocVar(bun);
	bun->qSeq = seq;
	bun->genoSeq = targetSeq;
	bun->ffList = gfRangesToFfItem(range->components, seq);
	bun->isProt = TRUE;
	t3 = hashMustFindVal(t3Hash, range->tName);
	bun->t3List = t3;
	ssStitch(bun, ffCdna, minMatch, ssAliCount);
	getTargetName(range->tName, out->includeTargetFile, targetName);
	saveAlignments(targetName, t3->nibSize, 0, 
	    bun, t3Hash, FALSE, isRc, ffCdna, minMatch, out);
	ssBundleFree(&bun);
	}

    /* Cleanup for this strand of database. */
    gfRangeFreeList(&rangeList);
    freeHash(&t3Hash);
    for (ref = t3RefList; ref != NULL; ref = ref->next)
        {
	struct trans3 *t3 = ref->val;
	trans3Free(&t3);
	}
    slFreeList(&t3RefList);
    freeDnaSeqList(&tSeqList);
    }

/* Final cleanup. */
for (isRc=0; isRc<=1; ++isRc)
    for (frame=0; frame<3; ++frame)
	gfClumpFreeList(&clumps[isRc][frame]);
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 $0x318, %rsp            # imm = 0x318
movq %r9, %rbp
movq %r8, 0x68(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdx, %r12
movq %rsi, 0x58(%rsp)
movq %rdi, %r14
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movq %rax, 0x48(%rsp)
movq %rax, 0x10(%rsp)
movq %rax, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
movq %rax, 0x30(%rsp)
xorl %edi, %edi
callq 0x2bea4
movq %rax, %r13
movq %rax, 0x78(%rsp)
movl (%r14), %r15d
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
leaq 0x7d149(%rip), %rdx     # 0x8dee3
movl %r15d, %edi
movq %r12, %rsi
callq 0x129f6
leaq 0x110(%rsp), %rsi
movl %r15d, %edi
callq 0x30e9d
movq %rax, %rbx
leaq 0x7d014(%rip), %rdi     # 0x8ddd3
movq %rax, %rsi
callq 0x217c8
testl %eax, %eax
je 0x10de9
movq 0x8(%r12), %rsi
leaq 0x7d071(%rip), %rdi     # 0x8de48
movq %rbx, %rdx
xorl %eax, %eax
callq 0x268ca
xorl %r13d, %r13d
jmp 0x10fc6
movq %r13, 0x28(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, %rdi
callq 0x12aac
movq %rax, 0x40(%rsp)
leaq 0x110(%rsp), %rbx
xorl %r13d, %r13d
movl %r15d, %edi
movq %rbx, %rsi
callq 0x30e9d
cmpl $0x646e65, 0x110(%rsp) # imm = 0x646E65
je 0x10f90
leaq 0x7cfa5(%rip), %rdi     # 0x8ddd3
movq %rbx, %rsi
callq 0x217c8
testl %eax, %eax
jne 0x10f75
movq %rbx, %rdi
leaq 0xb0(%rsp), %rsi
movl $0xc, %edx
callq 0x223ad
cmpl $0x7, %eax
jg 0x10e68
leaq 0x7d08e(%rip), %rdi     # 0x8deed
movl %eax, %esi
xorl %eax, %eax
callq 0x26b6f
movl $0x38, %edi
callq 0x2dc95
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
callq 0x3b838
movl %eax, 0x8(%rbx)
movq 0xb8(%rsp), %rdi
callq 0x3b838
movl %eax, 0xc(%rbx)
movl $0x28, %edi
callq 0x2dc95
movq %rax, %r14
movq 0xc0(%rsp), %rdi
callq 0x1f9f6
movq %rax, 0x8(%r14)
movq %r13, (%r14)
movq %r14, 0x10(%rbx)
movq 0xc8(%rsp), %rdi
callq 0x3b838
movl %eax, 0x18(%rbx)
movq 0xd0(%rsp), %rdi
callq 0x3b838
movl %eax, 0x1c(%rbx)
movq 0xd8(%rsp), %rdi
callq 0x3b838
movl %eax, 0x20(%rbx)
movq 0xe0(%rsp), %rax
movq 0xe8(%rsp), %rdi
xorl %r13d, %r13d
cmpb $0x2d, (%rax)
sete %r13b
callq 0x3b838
cltq
leaq (,%r13,2), %rcx
addq %r13, %rcx
leaq 0x80(%rsp,%rcx,8), %rcx
movq (%rcx,%rax,8), %rdx
movq %rdx, (%rbx)
movq %rbx, (%rcx,%rax,8)
movl %r15d, %edi
movq 0x28(%rsp), %rsi
callq 0xfb6b
movq %rax, 0x28(%rbx)
movq %rax, %rdi
callq 0x1fbec
movq %r14, %r13
cmpl 0x20(%rbx), %eax
leaq 0x110(%rsp), %rbx
je 0x10e0b
leaq 0x7cfb5(%rip), %rdi     # 0x8df12
leaq 0x7ce54(%rip), %rsi     # 0x8ddb8
leaq 0x7cfd2(%rip), %rcx     # 0x8df3d
movl $0x109, %edx            # imm = 0x109
callq 0x6460
movq 0x8(%r12), %rsi
leaq 0x7cec7(%rip), %rdi     # 0x8de48
leaq 0x110(%rsp), %rdx
xorl %eax, %eax
callq 0x268ca
leaq 0x80(%rsp), %rbx
xorl %r14d, %r14d
xorl %r15d, %r15d
leaq (%rbx,%r15), %rdi
callq 0x1fcb3
addq $0x8, %r15
cmpq $0x18, %r15
jne 0x10f9e
leaq 0x1(%r14), %rax
addq $0x18, %rbx
testq %r14, %r14
movq %rax, %r14
je 0x10f9b
movq 0x18(%rsp), %r14
movq %r13, 0x30(%rsp)
movl (%r14), %edi
callq 0x6e80
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
leaq 0x80(%rsp), %r14
leaq 0x38(%rsp), %r15
xorl %r13d, %r13d
movq %rbp, 0x50(%rsp)
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
movl %ebx, %esi
callq 0x113da
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x1fc95
movq %rax, 0x8(%rsp)
incq %rbx
cmpq $0x3, %rbx
jne 0x10ff1
movq %r14, 0x70(%rsp)
movq 0x8(%rsp), %rdi
callq 0x10cea
leaq 0x8(%rsp), %rdi
leaq -0x150a(%rip), %rsi     # 0xfb28
callq 0x1fd04
movq 0x8(%rsp), %rdi
leaq 0xafb2d(%rip), %rax     # 0xc0b70
movl (%rax), %esi
callq 0xfc3f
movq %rax, 0x8(%rsp)
movl 0x18(%r12), %ecx
movq %rax, %rdi
movq 0x58(%rsp), %rsi
movq 0x68(%rsp), %rdx
movl %r13d, %r8d
leaq 0x10(%rsp), %r9
pushq %r15
leaq 0x50(%rsp), %rax
pushq %rax
callq 0x114bc
addq $0x10, %rsp
movq 0x8(%rsp), %rbx
movq %rbx, 0xb0(%rsp)
testq %rbx, %rbx
leaq 0xb0(%rsp), %r14
je 0x110ac
movq (%rbx), %rbx
movq %r14, %rdi
callq 0xfa88
movq %rbx, 0xb0(%rsp)
testq %rbx, %rbx
jne 0x11094
movq $0x0, 0x8(%rsp)
movq %r13, 0x18(%rsp)
leaq (,%r13,2), %rax
addq %r13, %rax
leaq (%rsp,%rax,8), %rax
addq $0x80, %rax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
movq 0x28(%rsp), %rax
movq (%rax,%r14,8), %rbx
testq %rbx, %rbx
je 0x111a1
movq 0x10(%rbx), %rbp
movq 0x10(%rsp), %r15
movq 0x10(%rbp), %rax
testq %rax, %rax
cmoveq %rbp, %rax
movq 0x8(%rax), %r13
testq %r13, %r13
jne 0x11120
leaq 0x7caae(%rip), %rdi     # 0x8dbbb
leaq 0x7cca4(%rip), %rsi     # 0x8ddb8
movl $0x251, %edx            # imm = 0x251
xorl %eax, %eax
callq 0x26b6f
movl 0x18(%rbx), %eax
movl 0x1c(%rbx), %ecx
leal (%rax,%rax,2), %edx
leal (%rcx,%rcx,2), %ecx
movq %r15, %rdi
movq %r13, %rsi
callq 0x15e63
movq 0x18(%rax,%r14,8), %rcx
movq %rcx, 0x10(%rbp)
movslq 0x30(%rax), %rcx
imulq $0x55555556, %rcx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
movl %ecx, 0x18(%rbp)
movslq 0x34(%rax), %rcx
imulq $0x55555556, %rcx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
movl %ecx, 0x1c(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
movq 0x40(%rsp), %rdx
movl %r14d, %ecx
movq %rax, %r8
leaq 0x8(%rsp), %r9
pushq $0x0
pushq $0x1
callq 0x1088d
addq $0x10, %rsp
movq (%rbx), %rbx
jmp 0x110e0
incq %r14
cmpq $0x3, %r14
jne 0x110d7
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1fcb3
movq %rbx, %rdi
leaq -0x169d(%rip), %rsi     # 0xfb28
callq 0x1fd04
movq 0x8(%rsp), %rdi
leaq 0xaf99a(%rip), %rax     # 0xc0b70
movslq (%rax), %rax
imulq $0x55555556, %rax, %rsi # imm = 0x55555556
movq %rsi, %rax
shrq $0x3f, %rax
shrq $0x20, %rsi
addl %eax, %esi
callq 0xfc3f
movq %rax, 0x8(%rsp)
testq %rax, %rax
movq 0x50(%rsp), %r13
movq 0x60(%rsp), %r15
leaq 0x110(%rsp), %rbp
je 0x112ce
movq %rax, %r14
movq 0x18(%r14), %rbx
movl $0x48, %edi
callq 0x2dc95
movq %rax, 0x20(%rsp)
movq %r12, 0x10(%rax)
movq %rbx, 0x18(%rax)
movq 0x28(%r14), %rdi
movq %r12, %rsi
callq 0x10414
movq 0x20(%rsp), %rcx
movq %rax, 0x8(%rcx)
movl $0x1, %eax
movl %eax, 0x30(%rcx)
movq 0x10(%rsp), %rdi
movq 0x10(%r14), %rsi
callq 0x28fdd
movq %rax, %rbx
movq 0x20(%rsp), %rdi
movq %rax, 0x38(%rdi)
movl $0x1, %esi
movl %r15d, %edx
movl $0x10, %ecx
callq 0x14ecb
movq 0x10(%r14), %rdi
movl 0x48(%r13), %esi
movq %rbp, %rdx
callq 0x100d0
movl 0x38(%rbx), %esi
leaq 0x20(%rsp), %rbx
movl $0x1, %eax
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %r8
movq %rbp, %rdi
xorl %edx, %edx
xorl %r9d, %r9d
pushq %r13
pushq %r15
pushq %rax
pushq 0x30(%rsp)
callq 0x1022f
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x14940
movq (%r14), %r14
testq %r14, %r14
jne 0x11215
movq 0x8(%rsp), %rbx
movq %rbx, 0xb0(%rsp)
testq %rbx, %rbx
leaq 0x38(%rsp), %r15
leaq 0xb0(%rsp), %r13
je 0x11305
movq (%rbx), %rbx
movq %r13, %rdi
callq 0xfa88
movq %rbx, 0xb0(%rsp)
testq %rbx, %rbx
jne 0x112ed
movq $0x0, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x29565
movq 0x38(%rsp), %rbx
testq %rbx, %rbx
movq 0x70(%rsp), %r14
je 0x11343
movq 0x8(%rbx), %rax
movq %rax, 0xb0(%rsp)
movq %r13, %rdi
callq 0x15ddb
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x11327
movq %r15, %rdi
callq 0x1fcd6
leaq 0x48(%rsp), %rdi
callq 0x24af5
movq 0x18(%rsp), %rcx
leaq 0x1(%rcx), %r13
addq $0x18, %r14
testq %rcx, %rcx
je 0x10fef
leaq 0x80(%rsp), %rbx
xorl %r14d, %r14d
xorl %r15d, %r15d
leaq (%rbx,%r15), %rdi
callq 0xdb1f
addq $0x8, %r15
cmpq $0x18, %r15
jne 0x11379
leaq 0x1(%r14), %rax
addq $0x18, %rbx
testq %r14, %r14
movq %rax, %r14
je 0x11376
movq 0x30(%rsp), %rbx
testq %rbx, %rbx
je 0x113b4
movq 0x8(%rbx), %rdi
callq 0x2dd41
movq (%rbx), %rbx
jmp 0x113a1
leaq 0x30(%rsp), %rdi
callq 0x1fcd6
leaq 0x78(%rsp), %rdi
callq 0x2bf4b
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq