// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/jkOwnLib/genoFind.c
// Function: gfIndexTransNibsAndTwoBits
void gfIndexTransNibsAndTwoBits(struct genoFind *transGf[2][3], 
    int fileCount, char *fileNames[], 
    int minMatch, int maxGap, int tileSize, int maxPat, char *oocFile,
    boolean allowOneMismatch, boolean doMask, int stepSize)
/* Make translated (6 frame) index for all .nib and .2bit files. */
{
struct genoFind *gf;
int i,isRc, frame;
bits32 offset[2][3];
char *fileName;
struct dnaSeq *seq;
int sourceCount = 0;
long long totalBases = 0, warnAt = maxTotalBases();

if (allowOneMismatch)
    errAbort("Don't currently support allowOneMismatch in gfIndexTransNibsAndTwoBits");
/* Allocate indices for all reading frames. */
for (isRc=0; isRc <= 1; ++isRc)
    {
    for (frame = 0; frame < 3; ++frame)
	{
	transGf[isRc][frame] = gf = gfNewEmpty(minMatch, maxGap, 
		tileSize, stepSize, maxPat, oocFile, TRUE, allowOneMismatch);
	}
    }

/* Mask simple AA repeats (of period 1 and 2). */
for (isRc = 0; isRc <= 1; ++isRc)
    for (frame = 0; frame < 3; ++frame)
	maskSimplePepRepeat(transGf[isRc][frame]);

/* Scan through .nib and .2bit files once counting tiles. */
for (i=0; i<fileCount; ++i)
    {
    fileName = fileNames[i];
    printf("Counting %s\n", fileName);
    if (nibIsFile(fileName))
	{
	seq = readMaskedNib(fileName, doMask);
	transCountBothStrands(seq, transGf);
	sourceCount += 1;
	totalBases += seq->size;
	freeDnaSeq(&seq);
	}
    else if (twoBitIsFile(fileName))
        {
	struct twoBitFile *tbf = twoBitOpen(fileName);
	struct twoBitIndex *index;
	totalBases += twoBitCheckTotalSize(tbf);

	for (index = tbf->indexList; index != NULL; index = index->next)
	    {
	    seq = readMaskedTwoBit(tbf, index->name, doMask);
	    transCountBothStrands(seq, transGf);
	    sourceCount += 1;
	    freeDnaSeq(&seq);
	    }
	twoBitClose(&tbf);
	}
    else 
	errAbort("Unrecognized file type %s", fileName);
    if (totalBases >= warnAt)
	errAbort("Exceeding 4 billion bases, sorry gfServer can't handle that.");
    }

/* Get space for entries in indexed of all reading frames. */
for (isRc=0; isRc <= 1; ++isRc)
    {
    for (frame = 0; frame < 3; ++frame)
	{
	gf = transGf[isRc][frame];
	gfAllocLists(gf);
	gfZeroNonOverused(gf);
	AllocArray(gf->sources, sourceCount);
	gf->sourceCount = sourceCount;
	offset[isRc][frame] = 0;
	}
    }

/* Scan through nibs a second time building index. */
sourceCount = 0;
for (i=0; i<fileCount; ++i)
    {
    fileName = fileNames[i];
    printf("Indexing %s\n", fileName);
    if (nibIsFile(fileName))
	{
	seq = readMaskedNib(fileName, doMask);
	transIndexBothStrands(seq, transGf, offset, sourceCount, fileName);
	freeDnaSeq(&seq);
	sourceCount += 1;
	}
    else	/* .2bit file */
        {
	struct twoBitFile *tbf = twoBitOpen(fileName);
	struct twoBitIndex *index;
	for (index = tbf->indexList; index != NULL; index = index->next)
	    {
	    char nameBuf[PATH_LEN+256];
	    safef(nameBuf, sizeof(nameBuf), "%s:%s", fileName, index->name);
	    seq = readMaskedTwoBit(tbf, index->name, doMask);
	    transIndexBothStrands(seq, transGf, offset, sourceCount, nameBuf);
	    sourceCount += 1;
	    freeDnaSeq(&seq);
	    }
	twoBitClose(&tbf);
	}
    }

for (isRc=0; isRc <= 1; ++isRc)
    {
    for (frame = 0; frame < 3; ++frame)
	{
	gf = transGf[isRc][frame];
	gf->totalSeqSize = offset[isRc][frame];
	gfZeroOverused(gf);
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x378, %rsp            # imm = 0x378
movl %r9d, %r11d
movl %r8d, %r14d
movl %ecx, %r15d
movq %rdx, 0x30(%rsp)
movl %esi, 0x24(%rsp)
movq %rdi, %r12
movl 0x3c0(%rsp), %ebx
testl %ebx, %ebx
je 0xd0d8
leaq 0x80a08(%rip), %rdi     # 0x8dad3
xorl %eax, %eax
movl %r11d, %ebp
callq 0x26e94
movl %ebp, %r11d
movl 0x3d0(%rsp), %ebp
movq 0x3b8(%rsp), %r9
movl 0x3b0(%rsp), %r8d
movb $0x1, %cl
xorl %eax, %eax
movq %r12, 0x10(%rsp)
movl %r15d, 0x28(%rsp)
movl %r14d, 0x38(%rsp)
movl %ecx, 0x44(%rsp)
leaq (%rax,%rax,2), %rax
leaq (%r12,%rax,8), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
movl %r15d, %edi
movl %r14d, %esi
movl %r11d, %edx
movl %ebp, %ecx
movl %r8d, %r15d
movl %r11d, %r14d
pushq %rbx
pushq $0x1
movq %r9, %r12
callq 0xcc67
movl %r15d, %r8d
movq %r12, %r9
movl %r14d, %r11d
movl 0x48(%rsp), %r14d
movl 0x38(%rsp), %r15d
addq $0x10, %rsp
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
cmpq $0x3, %r13
jne 0xd116
movl $0x1, %eax
testb $0x1, 0x44(%rsp)
movl $0x0, %ecx
movq 0x10(%rsp), %r12
jne 0xd102
movb $0x1, %bl
xorl %eax, %eax
xorl %ebp, %ebp
leaq (%rax,%rax,2), %rax
leaq (%r12,%rax,8), %r14
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
callq 0xd544
incq %r15
cmpq $0x3, %r15
jne 0xd182
movl $0x1, %eax
testb $0x1, %bl
movl $0x0, %ebx
jne 0xd177
movl 0x24(%rsp), %ecx
movl %ecx, %eax
movq %rax, 0x28(%rsp)
testl %ecx, %ecx
movq 0x30(%rsp), %r14
jle 0xd30c
leaq 0x80958(%rip), %r15     # 0x8db1a
leaq 0x18(%rsp), %r12
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %ebp, %ebp
movq %rbx, 0x8(%rsp)
movq (%r14,%r13,8), %rbx
movq %r15, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6070
movq %rbx, %rdi
callq 0x324f7
testl %eax, %eax
je 0xd231
movq %rbx, %rdi
movl 0x3c8(%rsp), %esi
callq 0xd01f
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0xd58c
incl %ebp
movq 0x18(%rsp), %rax
movslq 0x18(%rax), %rax
movq 0x8(%rsp), %rbx
addq %rax, %rbx
movq %r12, %rdi
callq 0x24db1
jmp 0xd2e1
movq %rbx, %rdi
callq 0x3efc9
testl %eax, %eax
je 0xd2cb
movq %rbx, %rdi
callq 0x3e405
movq %rax, 0x70(%rsp)
movq %rax, %rdi
callq 0xd61a
movq %rax, 0x38(%rsp)
movq 0x70(%rsp), %rax
movq 0x28(%rax), %r14
testq %r14, %r14
je 0xd2a9
movq 0x10(%rsp), %rbx
movl 0x3c8(%rsp), %r15d
movq 0x70(%rsp), %rdi
movq 0x8(%r14), %rsi
movl %r15d, %edx
callq 0xd05c
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
callq 0xd58c
incl %ebp
movq %r12, %rdi
callq 0x24db1
movq (%r14), %r14
testq %r14, %r14
jne 0xd276
movq 0x8(%rsp), %rbx
addq 0x38(%rsp), %rbx
leaq 0x70(%rsp), %rdi
callq 0x3e30e
movq 0x30(%rsp), %r14
leaq 0x80851(%rip), %r15     # 0x8db1a
jmp 0xd2e1
leaq 0x807aa(%rip), %rdi     # 0x8da7c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x26e94
movq 0x8(%rsp), %rbx
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, %rbx
jl 0xd2fe
leaq 0x8079f(%rip), %rdi     # 0x8da96
xorl %eax, %eax
callq 0x26e94
incq %r13
cmpq 0x28(%rsp), %r13
jne 0xd1ce
movslq %ebp, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %r14
movb $0x1, %cl
xorl %eax, %eax
movl %ecx, 0x8(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
leaq (%rsp,%rax,4), %r13
addq $0x50, %r13
xorl %r15d, %r15d
movq (%r12,%r15,8), %rbx
movq %rbx, %rdi
callq 0xcec3
movslq 0x14(%rbx), %rax
testq %rax, %rax
jle 0xd368
movq 0x38(%rbx), %rcx
movl (%rbx), %edx
xorl %esi, %esi
cmpl %edx, (%rcx,%rsi,4)
jae 0xd360
movl $0x0, (%rcx,%rsi,4)
incq %rsi
cmpq %rsi, %rax
jne 0xd354
movq %r14, %rdi
callq 0x2de63
movq %rax, 0x20(%rbx)
movl %ebp, 0x1c(%rbx)
movl $0x0, (%r13,%r15,4)
incq %r15
cmpq $0x3, %r15
jne 0xd337
movl $0x1, %eax
testb $0x1, 0x8(%rsp)
movl $0x0, %ecx
jne 0xd31b
cmpl $0x0, 0x24(%rsp)
movl 0x3c8(%rsp), %r15d
jle 0xd4cc
leaq 0x80773(%rip), %r12     # 0x8db27
leaq 0x50(%rsp), %rbx
leaq 0x18(%rsp), %r13
xorl %eax, %eax
xorl %ebp, %ebp
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rcx
movq (%rcx,%rax,8), %r14
movq %r12, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x6070
movq %r14, %rdi
callq 0x324f7
movq %r14, %rdi
testl %eax, %eax
je 0xd41d
movl %r15d, %esi
callq 0xd01f
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
movl %ebp, %ecx
movq %r14, %r8
callq 0xd662
movq %r13, %rdi
callq 0x24db1
incl %ebp
jmp 0xd4b9
callq 0x3e405
movq %rax, 0x48(%rsp)
movq 0x28(%rax), %r15
testq %r15, %r15
je 0xd49b
movq %r14, %r12
movq 0x10(%rsp), %r14
leaq 0x70(%rsp), %rbx
movq 0x8(%r15), %r8
movq %rbx, %rdi
movl $0x300, %esi            # imm = 0x300
leaq 0x85669(%rip), %rdx     # 0x92ab9
movq %r12, %rcx
xorl %eax, %eax
callq 0x23f33
movq 0x48(%rsp), %rdi
movq 0x8(%r15), %rsi
movl 0x3c8(%rsp), %edx
callq 0xd05c
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq %r14, %rsi
leaq 0x50(%rsp), %rdx
movl %ebp, %ecx
movq %rbx, %r8
callq 0xd662
incl %ebp
movq %r13, %rdi
callq 0x24db1
movq (%r15), %r15
testq %r15, %r15
jne 0xd43d
leaq 0x48(%rsp), %rdi
callq 0x3e30e
movl 0x3c8(%rsp), %r15d
leaq 0x80673(%rip), %r12     # 0x8db27
leaq 0x50(%rsp), %rbx
movq 0x8(%rsp), %rax
incq %rax
cmpq 0x28(%rsp), %rax
jne 0xd3c2
movb $0x1, %al
xorl %ecx, %ecx
movq 0x10(%rsp), %r11
leaq (%rcx,%rcx,2), %rdx
leaq (%r11,%rdx,8), %rcx
leaq (%rsp,%rdx,4), %rdx
addq $0x50, %rdx
xorl %esi, %esi
movq (%rcx,%rsi,8), %r9
movl (%rdx,%rsi,4), %edi
movl %edi, 0x30(%r9)
movslq 0x14(%r9), %rdi
testq %rdi, %rdi
jle 0xd51b
movq 0x38(%r9), %r8
movl (%r9), %r9d
xorl %r10d, %r10d
cmpl %r9d, (%r8,%r10,4)
jb 0xd513
movl $0x0, (%r8,%r10,4)
incq %r10
cmpq %r10, %rdi
jne 0xd505
incq %rsi
cmpq $0x3, %rsi
jne 0xd4e7
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0xd4d5
addq $0x378, %rsp            # imm = 0x378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq