// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rsi, %rbx
movl (%rsi), %r14d
incl %r14d
shlq $0x2, %r14
testq %rcx, %rcx
je 0x6ec1
movq %r9, %r15
movq %rcx, %r13
movq %rdx, %rbp
movq %rdi, (%rsp)
movl %r8d, %r12d
addq %rdx, %r13
movl $0x1000, %edx           # imm = 0x1000
movq %r9, %rdi
xorl %esi, %esi
callq 0x10c0
movl (%rbp), %esi
leaq -0xf(%r13), %rax
movl $0xff, %ecx
movl $0x3fc, %edx            # imm = 0x3FC
leaq 0x4(%rbp), %rdi
cmpq %rax, %rdi
jae 0x6e53
movl 0x4(%rbp), %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(%rbp), %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(%rbp), %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(%rbp), %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)
addq $0x10, %rbp
movl %edi, %r8d
shrl $0xe, %r8d
andl %edx, %r8d
incl 0x800(%r15,%r8)
shrl $0x18, %edi
incl 0xc00(%r15,%rdi,4)
jmp 0x6d42
movzbl (%rbp), %eax
incq %rbp
incl (%r15,%rax,4)
cmpq %r13, %rbp
jb 0x6e48
xorl %eax, %eax
xorl %ebp, %ebp
cmpq $0x100, %rax            # imm = 0x100
je 0x6e8e
movl 0x800(%r15,%rax,4), %ecx
addl 0x400(%r15,%rax,4), %ecx
addl 0xc00(%r15,%rax,4), %ecx
addl (%r15,%rax,4), %ecx
movl %ecx, (%r15,%rax,4)
cmpl %ebp, %ecx
cmoval %ecx, %ebp
incq %rax
jmp 0x6e5c
movl $0x100, %eax            # imm = 0x100
decl %eax
cmpl $0x0, (%r15,%rax,4)
je 0x6e93
testl %r12d, %r12d
je 0x6eab
cmpl (%rbx), %eax
jbe 0x6eab
pushq $-0x7
popq %r15
jmp 0x6ed1
movl %eax, (%rbx)
movq (%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1170
movl %ebp, %r15d
jmp 0x6ed1
xorl %r15d, %r15d
xorl %esi, %esi
movq %r14, %rdx
callq 0x10c0
andl $0x0, (%rbx)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq