// File: /workspace/github_c_makefile_star2_O2/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 $0x88, %rsp
movl %r9d, %r12d
movl %ecx, %ebp
movl %edx, 0x3c(%rsp)
movq %rsi, 0x60(%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
movl %eax, (%rsp)
andl $0x0, 0x8(%rsp)
xorl %r14d, %r14d
pushq $0x2
popq %rdi
movl %edi, %esi
movl %ebp, %edx
movl %ebp, %ecx
movl %r8d, 0x38(%rsp)
xorl %r9d, %r9d
callq 0xae1c
movq %rax, %rbx
movq %rax, 0x80(%rsp)
movq 0x38(%rax), %rax
movq %rax, 0x68(%rsp)
movl 0x14(%rbx), %eax
movl %eax, 0x24(%rsp)
movl $0x584155f2, 0x4c(%rsp) # imm = 0x584155F2
movl %ebp, 0x30(%rsp)
movl %ebp, 0x48(%rsp)
leaq 0x70fac(%rip), %rsi     # 0x7dc79
movq %r15, 0x58(%rsp)
movq %r15, %rdi
callq 0x1ec79
andl $0x0, 0x44(%rsp)
andq $0x0, 0x70(%rsp)
movq %rax, 0x50(%rsp)
movq %rax, 0x78(%rsp)
cmpl %r14d, 0x2c(%rbx)
jle 0xcd03
leaq 0x6fde1(%rip), %rdi     # 0x7cadd
xorl %eax, %eax
callq 0x223fb
xorl %eax, %eax
cmpl $0x2, %r12d
setne %al
movl %eax, 0x34(%rsp)
leal -0x3(%r12), %r14d
xorl %ebp, %ebp
cmpl 0x3c(%rsp), %ebp
jae 0xce64
movl %ebp, %eax
movq 0x60(%rsp), %rcx
movq (%rcx,%rax,8), %r15
leaq 0x6fde5(%rip), %rdi     # 0x7cb18
movq %r15, %rsi
xorl %eax, %eax
callq 0x6070
movq %r15, %rdi
callq 0x2ce73
testl %eax, %eax
movl %ebp, 0x40(%rsp)
movq %r15, %rdi
je 0xce01
callq 0x2cb36
movq %rax, 0x28(%rsp)
leaq 0x6fd45(%rip), %rdi     # 0x7caaa
movq %r15, %rsi
xorl %eax, %eax
callq 0x6070
leaq 0x28(%rsp), %r15
movq (%r15), %r15
testq %r15, %r15
je 0xcdec
xorl %r13d, %r13d
cmpl $0x2, %r13d
je 0xcd74
cmpl $0x1, %r14d
ja 0xcdb7
movq %r15, %rdi
callq 0x12f80
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
cmpq $0x3, %rbp
je 0xcdc4
movq 0x18(%rsp), %rax
movq 0x18(%rax,%rbp,8), %rsi
movq %rbx, %rdi
callq 0xcf26
incq %rbp
jmp 0xcd9a
movq %rbx, %rdi
movq %r15, %rsi
callq 0xcf26
jmp 0xcdce
leaq 0x18(%rsp), %rdi
callq 0x12fe3
cmpl $0x2, %r12d
je 0xcd74
cmpl $0x4, %r12d
je 0xcd74
movq 0x10(%r15), %rdi
movslq 0x18(%r15), %rsi
callq 0x20d38
incl %r13d
jmp 0xcd7f
leaq 0x28(%rsp), %rdi
callq 0x2077b
movl 0x40(%rsp), %ebp
incl %ebp
jmp 0xcd17
callq 0x38f60
movq %r15, %rdi
testl %eax, %eax
je 0xce36
callq 0x38ce1
movq %rax, %r13
movq %rax, 0x28(%rsp)
testq %r13, %r13
je 0xcd5e
movq 0x10(%r13), %rdi
movl 0x18(%r13), %esi
callq 0x1df8a
movq (%r13), %r13
jmp 0xce1a
movl 0x34(%rsp), %esi
leaq 0x70(%rsp), %r13
movq %r13, %rdx
leaq 0x44(%rsp), %rbp
movq %rbp, %rcx
callq 0x234ef
movq %rax, 0x28(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x22e09
jmp 0xcd5e
leaq 0x6fcb9(%rip), %rdi     # 0x7cb24
xorl %ebp, %ebp
movq 0x58(%rsp), %r12
movq %r12, %rsi
xorl %eax, %eax
callq 0x6070
leaq 0x4c(%rsp), %rsi
pushq $0x4
popq %r14
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1ed3f
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1ed3f
leaq 0x18(%rsp), %r15
xorl %ebx, %ebx
movl 0x24(%rsp), %esi
movl %ebp, 0x18(%rsp)
cmpl %esi, %ebp
jae 0xcee6
movl %ebp, %eax
movl 0x38(%rsp), %ecx
movq 0x68(%rsp), %rdx
cmpl %ecx, (%rdx,%rax,4)
jb 0xcee2
movq 0x50(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1ed3f
movl 0x24(%rsp), %esi
incl %ebx
movl 0x18(%rsp), %ebp
incl %ebp
jmp 0xceb0
leaq 0x78(%rsp), %rdi
callq 0x1f2ea
leaq 0x80(%rsp), %rdi
callq 0xa8f7
leaq 0x6fc2c(%rip), %rdi     # 0x7cb30
movl %ebx, %esi
movl 0x30(%rsp), %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0x6070
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq