// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/jkOwnLib/patSpace.c
// Function: makePatSpace
struct patSpace *makePatSpace(
    struct dnaSeq **seqArray,       /* Array of sequence lists. */
    int seqArrayCount,              /* Size of above array. */
    int seedSize,	            /* Alignment seed size - 10 or 11. Must match oocFileName */
    char *oocFileName,              /* File with tiles to filter out, may be NULL. */
    int minMatch,                   /* Minimum # of matching tiles.  4 is good. */
    int maxGap                      /* Maximum gap size - 32k is good for 
                                       cDNA (introns), 500 is good for DNA assembly. */
    )
/* Allocate a pattern space and fill from sequences.  (Each element of
   seqArray is a list of sequences. */
{
struct patSpace *ps = newPatSpace(minMatch, maxGap,seedSize);
int i;
int startIx = 0;
int total = 0;
struct dnaSeq *seq;
psBits maxPat;
psBits *listSizes;
int seedSpaceSize = ps->seedSpaceSize;

maxPat = ps->maxPat = maxPatCount;
for (i=0; i<seqArrayCount; ++i)
    {
    for (seq = seqArray[i]; seq != NULL; seq = seq->next)
        {
        total += seq->size;
        countPatSpace(ps, seq);
        }
    }

listSizes = ps->listSizes;

/* Scan through over-popular patterns and set their count to value 
 * where they won't be added to pat space. */
oocMaskCounts(oocFileName, listSizes, ps->seedSize, maxPat);

/* Get rid of simple repeats as well. */
oocMaskSimpleRepeats(listSizes, ps->seedSize, maxPat);


allocPatSpaceLists(ps);

/* Zero out pattern counts that aren't oversubscribed. */
for (i=0; i<ps->seedSpaceSize; ++i)
    {
    if (listSizes[i] < maxPat)
        listSizes[i] = 0;
    }
for (i=0; i<seqArrayCount; ++i)
    {
	int j;
    for (seq = seqArray[i], j=0; seq != NULL; seq = seq->next, ++j)
        {
        startIx = addToPatSpace(ps, i, j, seq, startIx);
        if (startIx >= maxBlockCount)
	    tooManyBlocks();
        }
    }
ps->blocksUsed = startIx;

/* Zero local over-popular patterns. */
for (i=0; i<seedSpaceSize; ++i)
    {
    if (listSizes[i] >= maxPat)
        listSizes[i] = 0;
    }

return ps;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, 0x4(%rsp)
movl %r8d, %r12d
movq %rcx, 0x18(%rsp)
movl %edx, %r15d
movl %esi, %r13d
movq %rdi, 0x48(%rsp)
leal (%r15,%r15), %ebx
movl $0xe60018, %edi         # imm = 0xE60018
callq 0x2dff4
movl $0x1, %ebp
movl %ebx, %ecx
shll %cl, %ebp
movq %rax, %rbx
movl %r15d, 0xe6000c(%rax)
movl %ebp, 0xe60010(%rax)
leaq (,%rbp,8), %rdi
callq 0x2de63
movq %rax, (%rbx)
shlq $0x2, %rbp
movq %rbp, %rdi
callq 0x2de63
movq %rax, %r14
movq %rax, 0x8(%rbx)
movl %r12d, 0xe60004(%rbx)
movq %rbx, %r15
movl 0x4(%rsp), %eax
movl %eax, 0xe60008(%rbx)
movl 0xe60010(%rbx), %eax
movq %rax, 0x58(%rsp)
movl $0x4000, 0xe60000(%rbx) # imm = 0x4000
movl %r13d, %eax
movq %rax, 0x40(%rsp)
testl %r13d, %r13d
jle 0x187de
xorl %eax, %eax
leaq 0xa953f(%rip), %rcx     # 0xc1c70
movq 0x48(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
testq %rdx, %rdx
je 0x187d0
movq 0x10(%rdx), %rsi
movl 0xe6000c(%r15), %r10d
leal -0x1(%r10), %r11d
xorl %edi, %edi
cmpl $0x2, %r10d
jl 0x18775
movl %r11d, %r8d
xorl %r9d, %r9d
xorl %edi, %edi
movsbq (%rsi,%r9), %rbx
shll $0x2, %edi
addl (%rcx,%rbx,4), %edi
incq %r9
cmpq %r9, %r8
jne 0x18762
movl 0x18(%rdx), %r8d
cmpl %r8d, %r10d
jg 0x187c8
movslq 0xe60010(%r15), %r9
decq %r9
movslq %r11d, %r11
subl %r10d, %r8d
incl %r8d
addq %r11, %rsi
xorl %r10d, %r10d
movsbq (%rsi,%r10), %r11
movslq (%rcx,%r11,4), %r11
shll $0x2, %edi
movslq %edi, %rdi
addq %r11, %rdi
andq %r9, %rdi
movl (%r14,%rdi,4), %r11d
cmpl $0x3fff, %r11d          # imm = 0x3FFF
jg 0x187c0
incl %r11d
movl %r11d, (%r14,%rdi,4)
incq %r10
cmpl %r10d, %r8d
jne 0x18797
movq (%rdx), %rdx
jmp 0x1873a
incq %rax
cmpq 0x40(%rsp), %rax
jne 0x18731
movl 0xe6000c(%r15), %edx
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x147f8
movl 0xe6000c(%r15), %esi
movq %r14, 0x38(%rsp)
movq %r14, %rdi
movl $0x4000, %edx           # imm = 0x4000
callq 0x1493d
movslq 0xe60010(%r15), %rbx
testq %rbx, %rbx
jle 0x18879
movq (%r15), %r14
movq %r15, %rax
movq 0x8(%r15), %r15
movq %rax, %r12
movl 0xe60000(%rax), %ebp
xorl %eax, %eax
xorl %edx, %edx
xorl %ecx, %ecx
movl (%r15,%rdx,4), %esi
cmpl %ebp, %esi
cmovael %eax, %esi
addl %esi, %ecx
incq %rdx
cmpq %rdx, %rbx
jne 0x18835
movslq %ecx, %rdi
shlq $0x2, %rdi
callq 0x2ddfc
movq %rax, 0x10(%r12)
testl %ebx, %ebx
jle 0x18887
xorl %ecx, %ecx
movslq (%r15,%rcx,4), %rdx
cmpl %ebp, %edx
jae 0x1886f
movq %rax, (%r14,%rcx,8)
leaq (%rax,%rdx,4), %rax
incq %rcx
cmpq %rcx, %rbx
jne 0x1885f
jmp 0x18887
xorl %edi, %edi
callq 0x2ddfc
movq %r15, %r12
movq %rax, 0x10(%r15)
movq %r12, %r15
movl 0xe60010(%r12), %eax
testl %eax, %eax
movq 0x38(%rsp), %rsi
jle 0x188bf
xorl %ecx, %ecx
cmpl $0x3fff, (%rsi,%rcx,4)  # imm = 0x3FFF
ja 0x188b4
movl $0x0, (%rsi,%rcx,4)
movl 0xe60010(%r15), %eax
incq %rcx
movslq %eax, %rdx
cmpq %rdx, %rcx
jl 0x1889d
testl %r13d, %r13d
jle 0x18bc7
movq %r15, %rax
addq $0x398018, %rax         # imm = 0x398018
movq %rax, 0x50(%rsp)
leaq 0xa9393(%rip), %r8      # 0xc1c70
movq $0x0, 0x8(%rsp)
xorl %r14d, %r14d
movq %r15, 0x20(%rsp)
movq 0x48(%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %r10
testq %r10, %r10
je 0x18bad
xorl %r11d, %r11d
movl 0x18(%r10), %esi
movslq 0xe60010(%r15), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%r10), %rbp
movl 0xe60000(%r15), %eax
movl %eax, 0x4(%rsp)
movq (%r15), %rax
movq %rax, 0x70(%rsp)
movq 0x8(%r15), %rax
movq %rax, 0x18(%rsp)
movslq %r14d, %rax
leaq (%rax,%rax,2), %rax
movq 0x50(%rsp), %rdx
movq 0x8(%rsp), %rcx
movw %cx, (%rdx,%rax,8)
movw %r11w, 0x2(%rdx,%rax,8)
movq %r10, 0x8(%rdx,%rax,8)
movl $0x0, 0x10(%rdx,%rax,8)
movl $0x100, %ecx            # imm = 0x100
cmpl %ecx, %esi
movl %esi, %r12d
cmovll %esi, %ecx
movl %ecx, 0x14(%rdx,%rax,8)
movl 0xe6000c(%r15), %edx
leal -0x1(%rdx), %ecx
movl $0x0, %r15d
movq %rdx, %rbx
cmpl $0x2, %edx
jl 0x189a6
movl %ecx, %edx
xorl %esi, %esi
xorl %r15d, %r15d
movsbq (%rbp,%rsi), %rdi
shll $0x2, %r15d
addl (%r8,%rdi,4), %r15d
incq %rsi
cmpq %rsi, %rdx
jne 0x18990
movl $0x100, %r13d           # imm = 0x100
movq %rbx, %rsi
cmpl %r12d, %esi
movq %r10, 0x28(%rsp)
movl %r11d, (%rsp)
jle 0x189c7
movq 0x20(%rsp), %r15
jmp 0x18b02
movl %r12d, %edi
movq 0x10(%rsp), %rbx
decq %rbx
movq 0x50(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
addq $0x18, %rax
movq %rax, 0x10(%rsp)
movq %rbx, %rdx
movslq %ecx, %rax
movl %esi, %ecx
negl %ecx
movq %rcx, 0x68(%rsp)
subl %esi, %edi
incl %esi
incl %edi
addq %rax, %rbp
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movl %edi, 0x34(%rsp)
movq %rsi, 0x60(%rsp)
movsbq (%rbp), %rax
movslq (%r8,%rax,4), %rax
shll $0x2, %r15d
movslq %r15d, %r15
addq %rax, %r15
andq %rdx, %r15
movq 0x18(%rsp), %rax
movslq (%rax,%r15,4), %rax
cmpl 0x4(%rsp), %eax
jae 0x18a4b
leal 0x1(%rax), %ecx
movq 0x18(%rsp), %r9
movl %ecx, (%r9,%r15,4)
movq 0x70(%rsp), %rcx
movq (%rcx,%r15,8), %rcx
movl %r14d, (%rcx,%rax,4)
decl %r13d
jne 0x18ae5
cmpl $0x72ffe, %r14d         # imm = 0x72FFE
jl 0x18a8f
leaq 0x75b7c(%rip), %rdi     # 0x8e5e0
movl $0x72fff, %esi          # imm = 0x72FFF
xorl %eax, %eax
movq %rdx, %r13
callq 0x26e94
movq %r13, %rdx
movl 0x34(%rsp), %edi
movq 0x60(%rsp), %rsi
movl (%rsp), %r11d
movq 0x28(%rsp), %r10
leaq 0xa91e1(%rip), %r8      # 0xc1c70
incl %r14d
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %r9
movw %ax, (%r9)
movw %r11w, 0x2(%r9)
movq %r10, 0x8(%r9)
movq 0x20(%rsp), %rax
movl 0xe6000c(%rax), %eax
leal (%rsi,%r12), %ecx
subl %eax, %ecx
movl %ecx, 0x10(%r9)
addl 0x18(%r10), %eax
movq 0x68(%rsp), %rcx
addl %ebx, %ecx
addl %ecx, %eax
movl $0x100, %r13d           # imm = 0x100
cmpl %r13d, %eax
cmovgel %r13d, %eax
movl %eax, 0x14(%r9)
addq $0x18, %r9
movq %r9, 0x10(%rsp)
decl %ebx
incl %r12d
incq %rbp
cmpl %r12d, %edi
jne 0x18a0d
movq 0x20(%rsp), %r15
movl 0xe6000c(%r15), %esi
cmpl $0x2, %esi
jl 0x18b5e
xorl %ebx, %ebx
decl %r13d
je 0x18b1f
movl %r14d, %ebp
incl %ebx
leal -0x1(%rsi), %eax
movl %ebp, %r14d
cmpl %eax, %ebx
jl 0x18b09
jmp 0x18b61
leal 0x1(%r14), %ebp
movl $0x100, %r13d           # imm = 0x100
cmpl $0x72ffe, %r14d         # imm = 0x72FFE
jl 0x18b11
leaq 0x75aa7(%rip), %rdi     # 0x8e5e0
movl $0x72fff, %esi          # imm = 0x72FFF
xorl %eax, %eax
callq 0x26e94
movl (%rsp), %r11d
movq 0x28(%rsp), %r10
leaq 0xa911b(%rip), %r8      # 0xc1c70
movl 0xe6000c(%r15), %esi
jmp 0x18b11
movl %r14d, %ebp
xorl %r14d, %r14d
cmpl $0x100, %r13d           # imm = 0x100
setne %r14b
addl %ebp, %r14d
cmpl $0x72fff, %r14d         # imm = 0x72FFF
jl 0x18b9e
leaq 0x75a5e(%rip), %rdi     # 0x8e5e0
movl $0x72fff, %esi          # imm = 0x72FFF
xorl %eax, %eax
callq 0x26e94
movl (%rsp), %r11d
movq 0x28(%rsp), %r10
leaq 0xa90d2(%rip), %r8      # 0xc1c70
incl %r11d
movq (%r10), %r10
testq %r10, %r10
jne 0x18908
movq 0x8(%rsp), %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
cmpq 0x40(%rsp), %rcx
jne 0x188ee
jmp 0x18bca
xorl %r14d, %r14d
movl %r14d, 0x18(%r15)
movq 0x58(%rsp), %rdx
testl %edx, %edx
movq 0x38(%rsp), %rcx
jle 0x18bf6
xorl %eax, %eax
cmpl $0x4000, (%rcx,%rax,4)  # imm = 0x4000
jb 0x18bee
movl $0x0, (%rcx,%rax,4)
incq %rax
cmpq %rax, %rdx
jne 0x18bde
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq