// File: /workspace/github_c_makefile_star2_O1/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 0x7857
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 0x786f
leaq -0xf(,%rbp), %rax
addq %r13, %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 0x774d
jmp 0x787e
xorl %r15d, %r15d
xorl %esi, %esi
movq %r14, %rdx
callq 0x10c0
movl $0x0, (%rbx)
jmp 0x78fa
movq %r13, %rdi
jmp 0x787e
movzbl (%rdi), %eax
incq %rdi
incl (%r15,%rax,4)
cmpq %r12, %rdi
jb 0x7874
xorl %eax, %eax
xorl %ebp, %ebp
movl 0xc(%rsp), %edx
movl %ebp, %ecx
movl 0x800(%r15,%rax,4), %ebp
addl 0x400(%r15,%rax,4), %ebp
addl 0xc00(%r15,%rax,4), %ebp
addl (%r15,%rax,4), %ebp
movl %ebp, (%r15,%rax,4)
cmpl %ecx, %ebp
cmovbel %ecx, %ebp
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x788b
movl $0x100, %eax            # imm = 0x100
decl %eax
cmpl $0x0, (%r15,%rax,4)
je 0x78c2
testl %edx, %edx
je 0x78d7
cmpl (%rbx), %eax
jbe 0x78d7
xorl %eax, %eax
jmp 0x78eb
movl %eax, (%rbx)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1170
movb $0x1, %al
movl %ebp, %ecx
testb %al, %al
movq $-0x7, %r15
cmovneq %rcx, %r15
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq