// File: /workspace/github_c_makefile_star2_O2/Cyan4973[P]FiniteStateEntropy/programs/bench.c
// Function: BMK_benchMem285
void BMK_benchMem285(chunkParameters_t* chunkP, int nbChunks, const char* inFileName, int benchedSize,
                  U64* totalCompressedSize, double* totalCompressionTime, double* totalDecompressionTime,
                  int memLog)
{
    int loopNb, chunkNb;
    size_t cSize=0;
    double fastestC = 100000000., fastestD = 100000000.;
    double ratio=0.;
    U32 crcCheck=0;
    U32 crcOrig;

    /* Init */
    crcOrig = XXH32(chunkP[0].origBuffer, benchedSize,0);

    DISPLAY("\r%79s\r", "");
    for (loopNb = 1; loopNb <= nbIterations; loopNb++) {
        int nbLoops;
        clock_t clockStart, clockDuration;

        /* Compression benchmark */
        DISPLAY("%1i-%-14.14s : %9i ->\r", loopNb, inFileName, benchedSize);
        { int i; for (i=0; i<benchedSize; i++) chunkP[0].compressedBuffer[i]=(char)i; }     /* warming up memory */

        nbLoops = 0;
        clockStart = clock();
        while(clock() == clockStart);
        clockStart = clock();
        while(BMK_clockSpan(clockStart) < TIMELOOP) {
            for (chunkNb=0; chunkNb<nbChunks; chunkNb++) {
                const void* rawPtr = chunkP[chunkNb].origBuffer;
                const U16* U16chunkPtr = (const U16*) rawPtr;
                chunkP[chunkNb].compressedSize = FSE_compressU16(chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].origSize, U16chunkPtr, chunkP[chunkNb].origSize/2, 0, memLog);
            }
            nbLoops++;
        }
        clockDuration = BMK_clockSpan(clockStart);

        if ((double)clockDuration < fastestC*nbLoops) fastestC = (double)clockDuration/nbLoops;
        cSize=0; for (chunkNb=0; chunkNb<nbChunks; chunkNb++) cSize += chunkP[chunkNb].compressedSize;
        ratio = (double)cSize/(double)benchedSize*100.;

        DISPLAY("%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s\r",
                loopNb, inFileName, (int)benchedSize,
                (int)cSize, ratio,
                (double)benchedSize / fastestC / 1000.);

        //DISPLAY("\n"); continue;   // skip decompression
        // Decompression
        //{ size_t i; for (i=0; i<benchedSize; i++) orig_buff[i]=0; }     // zeroing area, for CRC checking

        nbLoops = 0;
        clockStart = clock();
        while(clock() == clockStart);
        clockStart = clock();
        while(BMK_clockSpan(clockStart) < TIMELOOP) {
            for (chunkNb=0; chunkNb<nbChunks; chunkNb++) {
                void* rawPtr = chunkP[chunkNb].destBuffer;
                U16* U16dstPtr = (U16*)rawPtr;
                chunkP[chunkNb].compressedSize = FSE_decompressU16(U16dstPtr, chunkP[chunkNb].origSize/2, chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].compressedSize);
            }
            nbLoops++;
        }
        clockDuration = BMK_clockSpan(clockStart);

        if ((double)clockDuration < fastestC*nbLoops) fastestC = (double)clockDuration/nbLoops;
        DISPLAY("%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s\r",
                loopNb, inFileName, (int)benchedSize,
                (int)cSize, ratio,
                (double)benchedSize / fastestC / 1000.,
                (double)benchedSize / fastestD / 1000.);

        /* CRC Checking */
        crcCheck = XXH32(chunkP[0].destBuffer, benchedSize,0);
        if (crcOrig!=crcCheck) {
            const char* src = chunkP[0].origBuffer;
            const char* fin = chunkP[0].destBuffer;
            const char* const srcStart = src;
            while (*src==*fin) src++, fin++;
            DISPLAY("\n!!! %14s : Invalid Checksum !!! pos %i/%i\n", inFileName, (int)(src-srcStart), benchedSize);
            break;
    }   }

    if (crcOrig==crcCheck) {
        if (ratio<100.)
            DISPLAY("%-16.16s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s\n",
                    inFileName, (int)benchedSize,
                    (int)cSize, ratio,
                    (double)benchedSize / fastestC / 1000.,
                    (double)benchedSize / fastestD / 1000.);
        else
            DISPLAY("%-16.16s : %9i -> %9i (%5.1f%%),%7.1f MB/s ,%7.1f MB/s \n",
                    inFileName, (int)benchedSize,
                    (int)cSize, ratio,
                    (double)benchedSize / fastestC / 1000.,
                    (double)benchedSize / fastestD / 1000.);
    }
    *totalCompressedSize    += cSize;
    *totalCompressionTime   += fastestC;
    *totalDecompressionTime += fastestD;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movl %ecx, %ebp
movq %rdx, 0x10(%rsp)
movl %esi, %ebx
movq %rdi, %r13
movl 0xb8(%rsp), %r14d
movq 0x8(%rdi), %rdi
movslq %ecx, %r12
xorl %r15d, %r15d
movq %r12, %rsi
xorl %edx, %edx
callq 0x4968
movl %eax, 0x18(%rsp)
movq 0x14cbd(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
leaq 0xdd40(%rip), %rsi      # 0xf085
leaq 0xe159(%rip), %rdx      # 0xf4a5
xorl %eax, %eax
callq 0x1110
cvtsi2sd %r12d, %xmm0
movsd 0xdca8(%rip), %xmm3     # 0xf008
movsd %xmm0, 0x30(%rsp)
divsd %xmm3, %xmm0
divsd 0xdc9e(%rip), %xmm0     # 0xf010
movsd %xmm0, 0x38(%rsp)
movq %r12, 0x68(%rsp)
testl %r12d, %r12d
movl $0x0, %eax
movl %ebp, 0xc(%rsp)
cmovgl %ebp, %eax
movq %rax, 0x60(%rsp)
testl %ebx, %ebx
cmovlel %r15d, %ebx
imulq $0x38, %rbx, %r12
pushq $0x1
popq %rdx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
xorl %eax, %eax
xorl %r15d, %r15d
cmpl 0x14d39(%rip), %edx     # 0x160ec
jg 0x1657
movapd %xmm3, 0x20(%rsp)
movq 0x14c32(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
leaq 0xdcbc(%rip), %rsi      # 0xf08c
movl %edx, 0x1c(%rsp)
movq 0x10(%rsp), %rcx
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x1110
xorl %eax, %eax
movq 0x60(%rsp), %rdx
cmpq %rax, %rdx
je 0x13fd
movq 0x18(%r13), %rcx
movb %al, (%rcx,%rax)
incq %rax
jmp 0x13ec
callq 0x1070
movq %rax, %rbx
callq 0x1070
cmpq %rbx, %rax
je 0x1405
xorl %r15d, %r15d
callq 0x1070
movq %rax, %rbx
callq 0x1070
subq %rbx, %rax
cmpq $0x1e847f, %rax         # imm = 0x1E847F
jg 0x1461
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0x145c
movq 0x18(%r13,%rbp), %rdi
movq 0x8(%r13,%rbp), %rdx
movq 0x10(%r13,%rbp), %rsi
movq %rsi, %rcx
shrq %rcx
xorl %r8d, %r8d
movl %r14d, %r9d
callq 0x8b3b
movq %rax, 0x20(%r13,%rbp)
addq $0x38, %rbp
jmp 0x142c
incl %r15d
jmp 0x141a
callq 0x1070
subq %rbx, %rax
cvtsi2sd %rax, %xmm4
cvtsi2sd %r15d, %xmm2
movapd 0x20(%rsp), %xmm3
movapd %xmm3, %xmm1
mulsd %xmm2, %xmm1
movapd %xmm4, %xmm0
divsd %xmm2, %xmm0
xorl %eax, %eax
xorl %r9d, %r9d
movl 0x1c(%rsp), %edx
cmpq %rax, %r12
je 0x14a2
addq 0x20(%r13,%rax), %r9
addq $0x38, %rax
jmp 0x1492
cmpltsd %xmm1, %xmm4
andpd %xmm4, %xmm0
andnpd %xmm3, %xmm4
orpd %xmm0, %xmm4
movq %r9, %xmm1
punpckldq 0xdb80(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xdb88(%rip), %xmm1     # 0xf050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x30(%rsp), %xmm1
divsd %xmm1, %xmm0
mulsd 0xdb32(%rip), %xmm0     # 0xf018
movq 0x14b0b(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
movapd %xmm4, 0x20(%rsp)
divsd %xmm4, %xmm1
divsd 0xdb0e(%rip), %xmm1     # 0xf010
leaq 0xdb9a(%rip), %rsi      # 0xf0a3
movq 0x10(%rsp), %rcx
movl 0xc(%rsp), %r8d
movq %r9, 0x70(%rsp)
movapd %xmm0, 0x40(%rsp)
movb $0x2, %al
callq 0x1110
callq 0x1070
movq %rax, %rbx
callq 0x1070
cmpq %rbx, %rax
je 0x152d
xorl %ebp, %ebp
callq 0x1070
movq %rax, %rbx
callq 0x1070
subq %rbx, %rax
cmpq $0x1e847f, %rax         # imm = 0x1E847F
jg 0x1584
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x1580
movq 0x28(%r13,%r15), %rdi
movq 0x10(%r13,%r15), %rsi
movq 0x18(%r13,%r15), %rdx
shrq %rsi
movq 0x20(%r13,%r15), %rcx
callq 0x8f4c
movq %rax, 0x20(%r13,%r15)
addq $0x38, %r15
jmp 0x1554
incl %ebp
jmp 0x1541
callq 0x1070
subq %rbx, %rax
cvtsi2sd %rax, %xmm4
cvtsi2sd %ebp, %xmm0
movapd 0x20(%rsp), %xmm3
movapd %xmm3, %xmm1
mulsd %xmm0, %xmm1
movapd %xmm4, %xmm2
divsd %xmm0, %xmm2
cmpltsd %xmm1, %xmm4
andpd %xmm4, %xmm2
andnpd %xmm3, %xmm4
orpd %xmm2, %xmm4
movapd %xmm4, 0x20(%rsp)
movq 0x14a2f(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
movsd 0x30(%rsp), %xmm1
divsd %xmm4, %xmm1
divsd 0xda32(%rip), %xmm1     # 0xf010
leaq 0xdaee(%rip), %rsi      # 0xf0d3
movl 0x1c(%rsp), %ebx
movl %ebx, %edx
movq 0x10(%rsp), %rcx
movl 0xc(%rsp), %r8d
movq 0x70(%rsp), %r15
movl %r15d, %r9d
movapd 0x40(%rsp), %xmm0
movsd 0x38(%rsp), %xmm2
movb $0x3, %al
callq 0x1110
movq 0x28(%r13), %rdi
movq 0x68(%rsp), %rsi
xorl %edx, %edx
callq 0x4968
movapd 0x20(%rsp), %xmm3
movl %ebx, %edx
movl %eax, %ebx
incl %edx
movl 0x18(%rsp), %ecx
movl %ecx, %eax
cmpl %ebx, %ecx
je 0x13ad
movq 0x8(%r13), %rax
movq 0x28(%r13), %rdx
xorl %ecx, %ecx
movb (%rax,%rcx), %sil
cmpb (%rdx,%rcx), %sil
jne 0x1709
incq %rcx
jmp 0x1644
movl %eax, %ebx
cmpl %ebx, 0x18(%rsp)
je 0x169b
movq 0x50(%rsp), %rax
addq %r15, (%rax)
movq 0x58(%rsp), %rax
addsd (%rax), %xmm3
movsd %xmm3, (%rax)
movq 0xb0(%rsp), %rax
movsd (%rax), %xmm0
addsd 0xd980(%rip), %xmm0     # 0xf008
movsd %xmm0, (%rax)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0xd975(%rip), %xmm0     # 0xf018
movapd 0x40(%rsp), %xmm2
ucomisd %xmm2, %xmm0
movq 0x14944(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
movsd 0x30(%rsp), %xmm1
divsd %xmm3, %xmm1
divsd 0xd947(%rip), %xmm1     # 0xf010
leaq 0xda6b(%rip), %rax      # 0xf13b
leaq 0xda9c(%rip), %rsi      # 0xf173
cmovaq %rax, %rsi
movq 0x10(%rsp), %rdx
movl 0xc(%rsp), %ecx
movl %r15d, %r8d
movapd %xmm2, %xmm0
movsd 0x38(%rsp), %xmm2
movb $0x3, %al
movapd %xmm3, 0x20(%rsp)
callq 0x1110
movapd 0x20(%rsp), %xmm3
jmp 0x165f
movq 0x148e8(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
leaq 0xd9f5(%rip), %rsi      # 0xf10f
movq 0x10(%rsp), %rdx
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x1110
movaps 0x20(%rsp), %xmm3
jmp 0x1659