// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/jkOwnLib/patSpace.c
// Function: patSpaceFindOne
struct patClump *patSpaceFindOne(struct patSpace *ps, DNA *dna, int dnaSize)
/* Find occurrences of DNA in patSpace. */
{
int lastStart = dnaSize - ps->seedSize;
int i,j;
int pat;
int hitBlockCount = 0;
int totalSigHits = 0;
DNA *tile = dna;
int blocksUsed = ps->blocksUsed;
int *posBuf = ps->posBuf;
int *hitBlocks = ps->hitBlocks;
int minMatch = ps->minMatch;

memset(ps->posBuf, 0, sizeof(ps->posBuf[0]) * blocksUsed);
for (i=0; i<=lastStart; i += ps->seedSize)
    {
    psBits *list;
    psBits count;

    pat = 0;
    for (j=0; j<ps->seedSize; ++j)
        {
        int bVal = ntValNoN[(int)tile[j]];
        pat <<= 2;
        pat += bVal;
        }
    list = ps->lists[pat];
    if ((count = ps->listSizes[pat]) > 0)
        {
        for (j=0; j<count; ++j)
            posBuf[list[j]] += 1;            
        }
    tile += ps->seedSize;
    }

/* Scan through array that records counts of hits at positions. */
for (i=0; i<blocksUsed-1; ++i)
    {
    /* Save significant hits in a more compact array */
    int a = posBuf[i], b = posBuf[i+1];
    int sum = a + b;
    if (sum >= minMatch)
        {
        if (a > 0)
            {
            if (hitBlockCount == 0 || hitBlocks[hitBlockCount-1] != i)
                {
                hitBlocks[hitBlockCount++] = i;
                totalSigHits += a;
                }
            }
        if (b > 0)
            {
            hitBlocks[hitBlockCount++] = i+1;
            totalSigHits += b;
            }
        }
    }

/* Output data with significant hits. */
if (hitBlockCount > 0 && totalSigHits*ps->seedSize*8 > dnaSize)
    {
    return clumpHits(ps, hitBlocks, hitBlockCount, posBuf, dna, 
        dnaSize);
    }        
else
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl %edx, 0xc(%rsp)
subl 0xe6000c(%rdi), %ebp
movslq 0x18(%rdi), %rdx
leaq 0x1c(%rdi), %r15
movl 0xe60004(%rdi), %r12d
movq %rdx, (%rsp)
shlq $0x2, %rdx
xorl %r13d, %r13d
movq %r15, %rdi
xorl %esi, %esi
callq 0x63b0
leaq 0xa01bd(%rip), %rax     # 0xb5c90
cmpl %ebp, %r13d
jg 0x15b3f
movl 0xe6000c(%rbx), %ecx
xorl %edx, %edx
testl %ecx, %ecx
movl $0x0, %esi
cmovgl %ecx, %esi
xorl %edi, %edi
cmpq %rdx, %rsi
je 0x15b02
movsbq (%r14,%rdx), %r8
shll $0x2, %edi
addl (%rax,%r8,4), %edi
incq %rdx
jmp 0x15aec
movslq %edi, %rsi
movq 0x8(%rbx), %rdx
movl (%rdx,%rsi,4), %edx
testq %rdx, %rdx
je 0x15b31
movq (%rbx), %rcx
movq (%rcx,%rsi,8), %rcx
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x15b2b
movl (%rcx,%rsi,4), %edi
incl (%r15,%rdi,4)
incq %rsi
jmp 0x15b1a
movl 0xe6000c(%rbx), %ecx
movslq %ecx, %rcx
addq %rcx, %r14
addl %r13d, %ecx
movl %ecx, %r13d
jmp 0x15ad3
movq (%rsp), %rcx
cmpl $0x2, %ecx
pushq $0x1
popq %rax
cmovgel %ecx, %eax
decl %eax
negq %rax
leaq 0x20(%rbx), %rdx
xorl %r9d, %r9d
xorl %ecx, %ecx
xorl %r13d, %r13d
movq %r9, %rsi
leaq (%rax,%r9), %r10
leaq (%rdx,%r9,4), %r11
xorl %edi, %edi
movq %r10, %r8
addq %rdi, %r8
je 0x15be9
movl -0x4(%r11,%rdi,4), %r9d
movl (%r11,%rdi,4), %r8d
leal (%r8,%r9), %ebp
incq %rdi
cmpl %r12d, %ebp
jl 0x15b6a
testl %r9d, %r9d
jle 0x15bc8
testl %r13d, %r13d
je 0x15bad
movslq %r13d, %r10
movl 0x1cc014(%rbx,%r10,4), %r11d
movq %rsi, %r14
subq %r11, %r14
addq %rdi, %r14
cmpq $0x1, %r14
jne 0x15bb0
jmp 0x15bc8
xorl %r10d, %r10d
incl %r13d
leal (%rsi,%rdi), %r11d
decl %r11d
movl %r11d, 0x1cc018(%rbx,%r10,4)
addl %ecx, %r9d
movl %r9d, %ecx
leaq (%rsi,%rdi), %r9
testl %r8d, %r8d
jle 0x15b5d
movslq %r13d, %r10
incl %r13d
addl %edi, %esi
movl %esi, 0x1cc018(%rbx,%r10,4)
addl %r8d, %ecx
jmp 0x15b5d
testl %r13d, %r13d
jle 0x15cc5
imull 0xe6000c(%rbx), %ecx
shll $0x3, %ecx
cmpl 0xc(%rsp), %ecx
jle 0x15cc5
movl 0xe60008(%rbx), %eax
movl %eax, (%rsp)
movl 0x1cc018(%rbx), %esi
leaq 0x50(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x15a42
movq 0x10(%r14), %rax
leaq 0x10(%rsp), %r15
movq %rax, 0x10(%r15)
movups (%r14), %xmm0
movaps %xmm0, (%r15)
movl %r13d, %r13d
decq %r13
xorl %ebp, %ebp
leaq 0x30(%rsp), %r12
xorl %r14d, %r14d
cmpq %rbp, %r13
je 0x15cc9
movl 0x1cc01c(%rbx,%rbp,4), %esi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x15a42
movq 0x38(%rsp), %rax
cmpq 0x18(%rsp), %rax
jne 0x15c80
movl 0x40(%rsp), %eax
movl 0x20(%rsp), %ecx
addl 0x24(%rsp), %ecx
subl %ecx, %eax
cmpl (%rsp), %eax
jle 0x15cac
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x15cfd
movq %r14, (%rax)
movq %rax, 0x48(%rsp)
movq 0x40(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movups 0x30(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
movq %rax, %r14
movq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x30(%rsp), %xmm0
movaps %xmm0, 0x10(%rsp)
incq %rbp
jmp 0x15c4a
xorl %eax, %eax
jmp 0x15cee
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x15cfd
movq %r14, (%rax)
leaq 0x48(%rsp), %rbx
movq %rax, (%rbx)
movq %rbx, %rdi
callq 0x1c567
movq (%rbx), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq