// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/jkOwnLib/genoFind.c
// Function: gfMakeOoc
void gfMakeOoc(char *outName, char *files[], int fileCount, 
	int tileSize, bits32 maxPat, enum gfType tType)
/* Count occurences of tiles in seqList and make a .ooc file. */
{
boolean dbIsPep = (tType == gftProt || tType == gftDnaX || tType == gftRnaX);
struct genoFind *gf = gfNewEmpty(gfMinMatch, gfMaxGap, tileSize, tileSize,
	maxPat, NULL, dbIsPep, FALSE);
bits32 *sizes = gf->listSizes;
int tileSpaceSize = gf->tileSpaceSize;
bioSeq *seq, *seqList;
bits32 sig = oocSig, psz = tileSize;
bits32 i;
int oocCount = 0;
char *inName;
FILE *f = mustOpen(outName, "w");


unsigned faFastBufSize = 0;
DNA     *faFastBuf = NULL;


if (gf->segSize > 0)
    errAbort("Don't yet know how to make ooc files for large tile sizes.");
for (i=0; i<fileCount; ++i)
    {
    inName = files[i];
    printf("Loading %s\n", inName);
    if (nibIsFile(inName))
        {
	seqList = nibLoadAll(inName);
	}
    else if (twoBitIsFile(inName))
        {
	seqList = twoBitLoadAll(inName);
	for (seq = seqList; seq != NULL; seq = seq->next)
	    toLowerN(seq->dna, seq->size);
	}
    else
        {
	seqList = faReadAllSeq(inName, tType != gftProt, &faFastBuf, &faFastBufSize);
    faFreeFastBuf(&faFastBuf, &faFastBufSize);
	}
    printf("Counting %s\n", inName);
    for (seq = seqList; seq != NULL; seq = seq->next)
	{
	int isRc;
	for (isRc = 0; isRc <= 1; ++isRc)
	    {
	    if (tType == gftDnaX || tType == gftRnaX)
		{
		struct trans3 *t3 = trans3New(seq);
		int frame;
		for (frame=0; frame<3; ++frame)
		    {
		    gfCountSeq(gf, t3->trans[frame]);
		    }
		trans3Free(&t3);
		}
	    else
		{
		gfCountSeq(gf, seq);
		}
	    if (tType == gftProt || tType == gftRnaX)
	        break;
	    else 
	        {
		reverseComplement(seq->dna, seq->size);
		}
	    }
	}
    freeDnaSeqList(&seqList);
    }
printf("Writing %s\n", outName);
writeOne(f, sig);
writeOne(f, psz);
for (i=0; i<tileSpaceSize; ++i)
    {
    if (sizes[i] >= maxPat)
	{
	writeOne(f, i);
	++oocCount;
	}
    }
carefulClose(&f);
genoFindFree(&gf);
printf("Wrote %d overused %d-mers to %s\n", oocCount, tileSize, outName);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, %r12d
movl %ecx, %ebp
movl %edx, 0x14(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdi, %r15
movl %r9d, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
sete %al
cmpl $0x4, %r9d
sete %cl
orb %al, %cl
movzbl %cl, %eax
xorl %r14d, %r14d
movl $0x2, %edi
movl $0x2, %esi
movl %ebp, %edx
movl %ebp, %ecx
movl %r8d, 0x24(%rsp)
xorl %r9d, %r9d
pushq %r14
pushq %rax
callq 0xcc67
addq $0x10, %rsp
movq %rax, %rbx
movq %rax, 0x70(%rsp)
movq 0x38(%rax), %rax
movq %rax, 0x48(%rsp)
movl 0x14(%rbx), %eax
movl %eax, 0x20(%rsp)
movl $0x584155f2, 0x3c(%rsp) # imm = 0x584155F2
movl %ebp, 0x28(%rsp)
movl %ebp, 0x38(%rsp)
leaq 0x7fcf7(%rip), %rsi     # 0x8ed49
movq %r15, 0x50(%rsp)
movq %r15, %rdi
callq 0x23072
movq %rax, 0x40(%rsp)
movq %rax, 0x68(%rsp)
movl %r14d, 0x34(%rsp)
movq $0x0, 0x60(%rsp)
cmpl %r14d, 0x2c(%rbx)
jle 0xf08b
leaq 0x7eac9(%rip), %rdi     # 0x8db4d
xorl %eax, %eax
callq 0x26e94
cmpl $0x0, 0x14(%rsp)
je 0xf210
xorl %eax, %eax
cmpl $0x2, %r12d
setne %al
movl %eax, 0x2c(%rsp)
leal -0x3(%r12), %r13d
xorl %eax, %eax
movl %eax, 0x30(%rsp)
movl %eax, %eax
movq 0x58(%rsp), %rcx
movq (%rcx,%rax,8), %rbp
leaq 0x7eac8(%rip), %rdi     # 0x8db88
movq %rbp, %rsi
xorl %eax, %eax
callq 0x6070
movq %rbp, %rdi
callq 0x324f7
movq %rbp, %rdi
testl %eax, %eax
je 0xf1a6
callq 0x321b6
movq %rax, 0x18(%rsp)
leaq 0x7ea2c(%rip), %rdi     # 0x8db1a
movq %rbp, %rsi
xorl %eax, %eax
callq 0x6070
movq 0x18(%rsp), %rbp
testq %rbp, %rbp
je 0xf18a
movb $0x1, %r14b
cmpl $0x1, %r13d
ja 0xf14d
movq %rbp, %rdi
callq 0x15dc0
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
movq 0x8(%rsp), %rax
movq 0x18(%rax,%r15,8), %rax
movq 0x10(%rax), %rsi
movl 0x18(%rax), %edx
movq %rbx, %rdi
callq 0xf2da
incq %r15
cmpq $0x3, %r15
jne 0xf11f
leaq 0x8(%rsp), %rdi
callq 0x15e23
jmp 0xf15c
movq 0x10(%rbp), %rsi
movl 0x18(%rbp), %edx
movq %rbx, %rdi
callq 0xf2da
cmpl $0x2, %r12d
je 0xf181
cmpl $0x4, %r12d
je 0xf181
movq 0x10(%rbp), %rdi
movslq 0x18(%rbp), %rsi
callq 0x25423
testb $0x1, %r14b
movl $0x0, %r14d
jne 0xf109
movq (%rbp), %rbp
jmp 0xf0fd
leaq 0x18(%rsp), %rdi
callq 0x24df5
movl 0x30(%rsp), %eax
incl %eax
cmpl 0x14(%rsp), %eax
jb 0xf0aa
jmp 0xf210
callq 0x3efc9
movq %rbp, %rdi
testl %eax, %eax
je 0xf1e2
callq 0x3ed1c
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0xf0e7
movq %rax, %r14
movq 0x10(%r14), %rdi
movl 0x18(%r14), %esi
callq 0x21fca
movq (%r14), %r14
testq %r14, %r14
jne 0xf1c8
jmp 0xf0e7
movl 0x2c(%rsp), %esi
leaq 0x60(%rsp), %r14
movq %r14, %rdx
leaq 0x34(%rsp), %r15
movq %r15, %rcx
callq 0x280b8
movq %rax, 0x18(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x27927
jmp 0xf0e7
leaq 0x7e97d(%rip), %rdi     # 0x8db94
xorl %ebx, %ebx
movq 0x50(%rsp), %r15
movq %r15, %rsi
xorl %eax, %eax
callq 0x6070
leaq 0x3c(%rsp), %rsi
movl $0x4, %edx
movq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x23138
leaq 0x38(%rsp), %rsi
movl $0x4, %edx
movq %r14, %rdi
callq 0x23138
movl $0x0, 0x8(%rsp)
movl 0x20(%rsp), %r13d
testl %r13d, %r13d
movl 0x24(%rsp), %ebp
movq 0x48(%rsp), %r12
je 0xf2a0
xorl %ebx, %ebx
leaq 0x8(%rsp), %r14
xorl %eax, %eax
movl %eax, %ecx
cmpl %ebp, (%r12,%rcx,4)
jb 0xf295
movl $0x4, %edx
movq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x23138
incl %ebx
movl 0x8(%rsp), %eax
incl %eax
movl %eax, 0x8(%rsp)
cmpl %r13d, %eax
jb 0xf275
leaq 0x68(%rsp), %rdi
callq 0x2371e
leaq 0x70(%rsp), %rdi
callq 0xc5cc
leaq 0x7e8e5(%rip), %rdi     # 0x8dba0
movl %ebx, %esi
movl 0x28(%rsp), %edx
movq %r15, %rcx
xorl %eax, %eax
callq 0x6070
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq