// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0xa0(%rbp)
movl $0x0, -0x2ac(%rbp)
movq $0x0, -0x2b8(%rbp)
movq $0x0, -0x2c0(%rbp)
movq $0x0, -0x2d0(%rbp)
xorl %edi, %edi
callq 0x3dc20
movq %rax, -0x2e8(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rsi
leaq -0x70(%rbp), %rdx
movq -0x2e8(%rbp), %rcx
leaq -0x2d0(%rbp), %r8
leaq -0x2a4(%rbp), %r9
callq 0x13390
movq -0x8(%rbp), %rax
movl (%rax), %edi
callq 0x6e90
movq -0x8(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0x2ac(%rbp)
cmpl $0x1, -0x2ac(%rbp)
jg 0x132c0
movl $0x0, -0x2a8(%rbp)
cmpl $0x3, -0x2a8(%rbp)
jge 0x12ef9
movslq -0x2ac(%rbp), %rcx
leaq -0x70(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x2a8(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x2a8(%rbp), %esi
callq 0x136d0
movq %rax, -0x90(%rbp)
movq -0x80(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x2aa60
movq %rax, -0x80(%rbp)
movl -0x2a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a8(%rbp)
jmp 0x12e9c
movq -0x80(%rbp), %rdi
callq 0x12d70
leaq -0x80(%rbp), %rdi
leaq -0x16dd(%rip), %rsi     # 0x11830
callq 0x2ab90
movq -0x80(%rbp), %rdi
leaq 0xf3d83(%rip), %rax     # 0x106ca0
movl (%rax), %esi
callq 0x119f0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
movl -0x2ac(%rbp), %r8d
leaq -0x2b8(%rbp), %r9
leaq -0xa0(%rbp), %r10
leaq -0x2c0(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x137d0
leaq -0x80(%rbp), %rdi
callq 0x117e0
movl $0x0, -0x2a8(%rbp)
cmpl $0x3, -0x2a8(%rbp)
jge 0x130b2
movslq -0x2ac(%rbp), %rcx
leaq -0x70(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq -0x2a8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x1309c
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x2f0(%rbp)
movq -0x2b8(%rbp), %rax
movq %rax, -0x300(%rbp)
movq -0x78(%rbp), %rdi
callq 0x12300
movq -0x300(%rbp), %rdi
movq %rax, %rsi
movq -0x78(%rbp), %rax
imull $0x3, 0x18(%rax), %edx
movq -0x78(%rbp), %rax
imull $0x3, 0x1c(%rax), %ecx
callq 0x1a610
movq %rax, -0x2e0(%rbp)
movq -0x2e0(%rbp), %rax
movslq -0x2a8(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rcx
movq -0x2f0(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x2e0(%rbp), %rax
movl 0x30(%rax), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x2f0(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x2e0(%rbp), %rax
movl 0x34(%rax), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x2f0(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x78(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x2a4(%rbp), %edx
movl -0x2a8(%rbp), %ecx
movq -0x2e0(%rbp), %r8
leaq -0x80(%rbp), %r9
xorl %eax, %eax
movl $0x1, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x12980
movq -0x78(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0x12fa6
jmp 0x1309e
movl -0x2a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a8(%rbp)
jmp 0x12f78
leaq -0x80(%rbp), %rdi
callq 0x2aad0
leaq -0x80(%rbp), %rdi
leaq -0x1896(%rip), %rsi     # 0x11830
callq 0x2ab90
movq -0x80(%rbp), %rdi
leaq 0xf3bca(%rip), %rax     # 0x106ca0
movl (%rax), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %esi
callq 0x119f0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x13236
movq -0x88(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x98(%rbp)
movl $0x48, %edi
callq 0x40c50
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x88(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x12370
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl $0x1, 0x30(%rax)
movq -0x2b8(%rbp), %rdi
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x39590
movq %rax, -0x2e0(%rbp)
movq -0x2e0(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x38(%rbp), %rdi
movl -0x1c(%rbp), %edx
movl 0xf2c51(%rip), %ecx     # 0x105df4
movl $0x1, %esi
callq 0x18b80
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x48(%rax), %esi
leaq -0x2a0(%rbp), %rdx
callq 0x11f70
leaq -0x2a0(%rbp), %rdi
movq -0x2e0(%rbp), %rax
movl 0x38(%rax), %esi
movq -0x38(%rbp), %rcx
movq -0x2b8(%rbp), %r8
movl -0x2ac(%rbp), %r11d
movl -0x1c(%rbp), %r10d
movq -0x30(%rbp), %rax
xorl %r9d, %r9d
movl %r9d, %edx
movl %r11d, (%rsp)
movl $0x1, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x121d0
leaq -0x38(%rbp), %rdi
callq 0x183a0
movq -0x88(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x88(%rbp)
jmp 0x130f6
leaq -0x80(%rbp), %rdi
callq 0x117e0
leaq -0x2b8(%rbp), %rdi
callq 0x3a080
movq -0x2c0(%rbp), %rax
movq %rax, -0x2c8(%rbp)
cmpq $0x0, -0x2c8(%rbp)
je 0x13294
movq -0x2c8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x2f8(%rbp)
leaq -0x2f8(%rbp), %rdi
callq 0x1a560
movq -0x2c8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x2c8(%rbp)
jmp 0x13259
leaq -0x2c0(%rbp), %rdi
callq 0x2ab30
leaq -0xa0(%rbp), %rdi
callq 0x32850
movl -0x2ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ac(%rbp)
jmp 0x12e85
movl $0x0, -0x2ac(%rbp)
cmpl $0x1, -0x2ac(%rbp)
jg 0x1332f
movl $0x0, -0x2a8(%rbp)
cmpl $0x3, -0x2a8(%rbp)
jge 0x1331c
movslq -0x2ac(%rbp), %rax
leaq -0x70(%rbp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
movslq -0x2a8(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0xe5f0
movl -0x2a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a8(%rbp)
jmp 0x132dd
jmp 0x1331e
movl -0x2ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ac(%rbp)
jmp 0x132ca
movq -0x2d0(%rbp), %rax
movq %rax, -0x2d8(%rbp)
cmpq $0x0, -0x2d8(%rbp)
je 0x1336a
movq -0x2d8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x40d40
movq -0x2d8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x2d8(%rbp)
jmp 0x1333d
leaq -0x2d0(%rbp), %rdi
callq 0x2ab30
leaq -0x2e8(%rbp), %rdi
callq 0x3dd90
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
nopl (%rax,%rax)