// File: /workspace/github_c_makefile_star2_O3/Cyan4973[P]FiniteStateEntropy/programs/../lib/hist.c
// Function: HIST_count_parallel_wksp
static size_t HIST_count_parallel_wksp(
                                unsigned* count, unsigned* maxSymbolValuePtr,
                                const void* source, size_t sourceSize,
                                HIST_checkInput_e check,
                                U32* const workSpace)
{
    const BYTE* ip = (const BYTE*)source;
    const BYTE* const iend = ip+sourceSize;
    size_t const countSize = (*maxSymbolValuePtr + 1) * sizeof(*count);
    unsigned max=0;
    U32* const Counting1 = workSpace;
    U32* const Counting2 = Counting1 + 256;
    U32* const Counting3 = Counting2 + 256;
    U32* const Counting4 = Counting3 + 256;

    /* safety checks */
    assert(*maxSymbolValuePtr <= 255);
    if (!sourceSize) {
        memset(count, 0, countSize);
        *maxSymbolValuePtr = 0;
        return 0;
    }
    memset(workSpace, 0, 4*256*sizeof(unsigned));

    /* by stripes of 16 bytes */
    {   U32 cached = MEM_read32(ip); ip += 4;
        while (ip < iend-15) {
            U32 c = cached; cached = MEM_read32(ip); ip += 4;
            Counting1[(BYTE) c     ]++;
            Counting2[(BYTE)(c>>8) ]++;
            Counting3[(BYTE)(c>>16)]++;
            Counting4[       c>>24 ]++;
            c = cached; cached = MEM_read32(ip); ip += 4;
            Counting1[(BYTE) c     ]++;
            Counting2[(BYTE)(c>>8) ]++;
            Counting3[(BYTE)(c>>16)]++;
            Counting4[       c>>24 ]++;
            c = cached; cached = MEM_read32(ip); ip += 4;
            Counting1[(BYTE) c     ]++;
            Counting2[(BYTE)(c>>8) ]++;
            Counting3[(BYTE)(c>>16)]++;
            Counting4[       c>>24 ]++;
            c = cached; cached = MEM_read32(ip); ip += 4;
            Counting1[(BYTE) c     ]++;
            Counting2[(BYTE)(c>>8) ]++;
            Counting3[(BYTE)(c>>16)]++;
            Counting4[       c>>24 ]++;
        }
        ip-=4;
    }

    /* finish last symbols */
    while (ip<iend) Counting1[*ip++]++;

    {   U32 s;
        for (s=0; s<256; s++) {
            Counting1[s] += Counting2[s] + Counting3[s] + Counting4[s];
            if (Counting1[s] > max) max = Counting1[s];
    }   }

    {   unsigned maxSymbolValue = 255;
        while (!Counting1[maxSymbolValue]) maxSymbolValue--;
        if (check && maxSymbolValue > *maxSymbolValuePtr) return ERROR(maxSymbolValue_tooSmall);
        *maxSymbolValuePtr = maxSymbolValue;
        memmove(count, Counting1, countSize);   /* in case count & Counting1 are overlapping */
    }
    return (size_t)max;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movl (%rsi), %r14d
incl %r14d
shlq $0x2, %r14
testq %rcx, %rcx
je 0x7e35
movq %r9, %r15
movq %rcx, %rbp
movq %rdx, %r13
movl %r8d, 0xc(%rsp)
movq %rdi, 0x10(%rsp)
leaq (%rdx,%rcx), %r12
movl $0x1000, %edx           # imm = 0x1000
movq %r9, %rdi
xorl %esi, %esi
callq 0x10c0
cmpq $0x14, %rbp
jl 0x7e4d
leaq -0xf(%r12), %rax
movl (%r13), %esi
movl $0xff, %ecx
movl $0x3fc, %edx            # imm = 0x3FC
movl 0x4(%r13), %edi
movl %esi, %r8d
andl %ecx, %r8d
incl (%r15,%r8,4)
movl %esi, %r8d
shrl $0x8, %r8d
andl %ecx, %r8d
incl 0x400(%r15,%r8,4)
movl %esi, %r8d
shrl $0xe, %r8d
andl %edx, %r8d
incl 0x800(%r15,%r8)
shrl $0x18, %esi
incl 0xc00(%r15,%rsi,4)
movl 0x8(%r13), %esi
movl %edi, %r8d
andl %ecx, %r8d
incl (%r15,%r8,4)
movl %edi, %r8d
shrl $0x8, %r8d
andl %ecx, %r8d
incl 0x400(%r15,%r8,4)
movl %edi, %r8d
shrl $0xe, %r8d
andl %edx, %r8d
incl 0x800(%r15,%r8)
shrl $0x18, %edi
incl 0xc00(%r15,%rdi,4)
movl 0xc(%r13), %edi
movl %esi, %r8d
andl %ecx, %r8d
incl (%r15,%r8,4)
movl %esi, %r8d
shrl $0x8, %r8d
andl %ecx, %r8d
incl 0x400(%r15,%r8,4)
movl %esi, %r8d
shrl $0xe, %r8d
andl %edx, %r8d
incl 0x800(%r15,%r8)
shrl $0x18, %esi
incl 0xc00(%r15,%rsi,4)
movl 0x10(%r13), %esi
movl %edi, %r8d
andl %ecx, %r8d
incl (%r15,%r8,4)
movl %edi, %r8d
shrl $0x8, %r8d
andl %ecx, %r8d
incl 0x400(%r15,%r8,4)
movl %edi, %r8d
shrl $0xe, %r8d
andl %edx, %r8d
incl 0x800(%r15,%r8)
shrl $0x18, %edi
incl 0xc00(%r15,%rdi,4)
leaq 0x10(%r13), %rdi
addq $0x14, %r13
cmpq %rax, %r13
movq %rdi, %r13
jb 0x7d2b
jmp 0x7e5c
xorl %r13d, %r13d
xorl %esi, %esi
movq %r14, %rdx
callq 0x10c0
movl $0x0, (%rbx)
jmp 0x7f55
movq %r13, %rdi
jmp 0x7e5c
movzbl (%rdi), %eax
incq %rdi
incl (%r15,%rax,4)
cmpq %r12, %rdi
jb 0x7e52
pxor %xmm1, %xmm1
xorl %eax, %eax
movdqa 0xb281(%rip), %xmm0     # 0x130f0
movl 0xc(%rsp), %ecx
movdqu 0x400(%r15,%rax,4), %xmm2
movdqu 0x800(%r15,%rax,4), %xmm3
paddd %xmm2, %xmm3
movdqu 0xc00(%r15,%rax,4), %xmm2
movdqu (%r15,%rax,4), %xmm4
paddd %xmm2, %xmm4
paddd %xmm3, %xmm4
movdqu %xmm4, (%r15,%rax,4)
movdqa %xmm4, %xmm2
pxor %xmm0, %xmm2
movdqa %xmm1, %xmm3
pxor %xmm0, %xmm3
pcmpgtd %xmm3, %xmm2
pand %xmm2, %xmm4
pandn %xmm1, %xmm2
movdqa %xmm2, %xmm1
por %xmm4, %xmm1
addq $0x4, %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x7e73
pshufd $0xee, %xmm1, %xmm2     # xmm2 = xmm1[2,3,2,3]
movdqa %xmm1, %xmm3
pxor %xmm0, %xmm3
movdqa %xmm2, %xmm4
pxor %xmm0, %xmm4
pcmpgtd %xmm4, %xmm3
pand %xmm3, %xmm1
pandn %xmm2, %xmm3
por %xmm1, %xmm3
pshufd $0x55, %xmm3, %xmm1     # xmm1 = xmm3[1,1,1,1]
movdqa %xmm3, %xmm2
pxor %xmm0, %xmm2
pxor %xmm1, %xmm0
pcmpgtd %xmm0, %xmm2
pand %xmm2, %xmm3
pandn %xmm1, %xmm2
por %xmm3, %xmm2
movd %xmm2, %ebp
movl $0x100, %eax            # imm = 0x100
decl %eax
cmpl $0x0, (%r15,%rax,4)
je 0x7f28
testl %ecx, %ecx
je 0x7f40
movq $-0x7, %r13
cmpl (%rbx), %eax
ja 0x7f55
movl %eax, (%rbx)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1170
movl %ebp, %r13d
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq