// File: /workspace/github_c_makefile_star2_O3/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 $0xa8, %rsp
movq %r9, 0x48(%rsp)
movq %r8, 0x88(%rsp)
movl %ecx, %ebx
movq %rdx, 0x10(%rsp)
movl %esi, %r15d
movq %rdi, %r13
movq 0x8(%rdi), %rdi
movslq %ecx, %r14
xorl %ebp, %ebp
movq %r14, %rsi
xorl %edx, %edx
callq 0x549a
movl %eax, %r12d
movq 0x18dbd(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0x11f00(%rip), %rsi     # 0x13145
leaq 0x12319(%rip), %rdx     # 0x13565
xorl %eax, %eax
callq 0x1110
cmpl $0x0, 0x18e92(%rip)     # 0x1a0ec
movl %ebx, 0x8(%rsp)
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x38(%rsp)
jg 0x12cc
movsd 0x11d96(%rip), %xmm3    # 0x13008
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
xorl %r15d, %r15d
movq 0x48(%rsp), %r14
cmpl %ebp, %r12d
je 0x1619
movq 0x88(%rsp), %rax
addq %r15, (%rax)
addsd (%r14), %xmm3
movsd %xmm3, (%r14)
movq 0xe0(%rsp), %rax
movsd (%rax), %xmm0
addsd 0x11d52(%rip), %xmm0    # 0x13008
movsd %xmm0, (%rax)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, 0x78(%rsp)
movl %r12d, 0x1c(%rsp)
movsd 0x11d2a(%rip), %xmm3    # 0x13008
movsd 0x38(%rsp), %xmm0
divsd %xmm3, %xmm0
divsd 0x11d20(%rip), %xmm0    # 0x13010
movsd %xmm0, 0x70(%rsp)
movl 0xe8(%rsp), %r12d
movl 0x8(%rsp), %eax
movq %rax, 0x68(%rsp)
movl %r15d, 0xc(%rsp)
movl %r15d, %eax
imulq $0x38, %rax, %rbx
pushq $0x1
popq %rdx
movapd %xmm3, 0x20(%rsp)
movq 0x18cd5(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0x11e1f(%rip), %rsi     # 0x1314c
movq %rdx, 0x40(%rsp)
movq 0x10(%rsp), %rcx
movl 0x8(%rsp), %ebp
movl %ebp, %r8d
xorl %eax, %eax
callq 0x1110
testl %ebp, %ebp
movq 0x68(%rsp), %rdx
jle 0x135f
xorl %eax, %eax
movq 0x18(%r13), %rcx
movb %al, (%rcx,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x1350
callq 0x1070
movq %rax, %r15
callq 0x1070
cmpq %r15, %rax
je 0x1367
callq 0x1070
movq %rax, %rbp
callq 0x1070
subq %rbp, %rax
xorpd %xmm0, %xmm0
cmpq $0x1e847f, %rax         # imm = 0x1E847F
jg 0x13e0
xorl %r15d, %r15d
cmpl $0x0, 0xc(%rsp)
jle 0x13c8
xorl %r14d, %r14d
movq 0x18(%r13,%r14), %rdi
movq 0x8(%r13,%r14), %rdx
movq 0x10(%r13,%r14), %rsi
movq %rsi, %rcx
shrq %rcx
xorl %r8d, %r8d
movl %r12d, %r9d
callq 0xa48d
movq %rax, 0x20(%r13,%r14)
addq $0x38, %r14
cmpq %r14, %rbx
jne 0x139a
incl %r15d
callq 0x1070
subq %rbp, %rax
cmpq $0x1e8480, %rax         # imm = 0x1E8480
jl 0x1390
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x50(%rsp)
callq 0x1070
cmpl $0x0, 0xc(%rsp)
jle 0x1412
xorl %ecx, %ecx
xorl %r15d, %r15d
movapd 0x20(%rsp), %xmm2
movq 0x40(%rsp), %rdx
addq 0x20(%r13,%rcx), %r15
addq $0x38, %rcx
cmpq %rcx, %rbx
jne 0x1402
jmp 0x1420
xorl %r15d, %r15d
movapd 0x20(%rsp), %xmm2
movq 0x40(%rsp), %rdx
subq %rbp, %rax
cvtsi2sd %rax, %xmm3
movapd %xmm2, %xmm0
movsd 0x50(%rsp), %xmm4
mulsd %xmm4, %xmm0
movapd %xmm3, %xmm1
divsd %xmm4, %xmm1
cmpltsd %xmm0, %xmm3
andpd %xmm3, %xmm1
andnpd %xmm2, %xmm3
orpd %xmm1, %xmm3
movq %r15, %xmm1
punpckldq 0x11be4(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x11bec(%rip), %xmm1    # 0x13050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x38(%rsp), %xmm1
divsd %xmm1, %xmm0
mulsd 0x11b96(%rip), %xmm0    # 0x13018
movq 0x18b6f(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
movapd %xmm3, 0x90(%rsp)
divsd %xmm3, %xmm1
divsd 0x11b6f(%rip), %xmm1    # 0x13010
leaq 0x11cbb(%rip), %rsi     # 0x13163
movq 0x10(%rsp), %rcx
movl 0x8(%rsp), %r8d
movl %r15d, %r9d
movapd %xmm0, 0x50(%rsp)
movb $0x2, %al
callq 0x1110
callq 0x1070
movq %rax, %rbp
callq 0x1070
cmpq %rbp, %rax
je 0x14ca
callq 0x1070
movq %rax, %rbp
callq 0x1070
movq %rbp, 0x20(%rsp)
subq %rbp, %rax
xorpd %xmm0, %xmm0
cmpq $0x1e847f, %rax         # imm = 0x1E847F
jg 0x1545
xorl %r14d, %r14d
cmpl $0x0, 0xc(%rsp)
jle 0x152b
xorl %ebp, %ebp
movq 0x28(%r13,%rbp), %rdi
movq 0x10(%r13,%rbp), %rsi
movq 0x18(%r13,%rbp), %rdx
shrq %rsi
movq 0x20(%r13,%rbp), %rcx
callq 0xa8d6
movq %rax, 0x20(%r13,%rbp)
addq $0x38, %rbp
cmpq %rbp, %rbx
jne 0x1501
incl %r14d
callq 0x1070
subq 0x20(%rsp), %rax
cmpq $0x1e8480, %rax         # imm = 0x1E8480
jl 0x14f8
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x80(%rsp)
callq 0x1070
subq 0x20(%rsp), %rax
cvtsi2sd %rax, %xmm2
movapd 0x90(%rsp), %xmm3
movapd %xmm3, %xmm0
movsd 0x80(%rsp), %xmm4
mulsd %xmm4, %xmm0
movapd %xmm2, %xmm1
divsd %xmm4, %xmm1
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm2
orpd %xmm1, %xmm2
movq 0x18a61(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
movsd 0x38(%rsp), %xmm1
movapd %xmm2, 0x20(%rsp)
divsd %xmm2, %xmm1
divsd 0x11a5e(%rip), %xmm1    # 0x13010
leaq 0x11bda(%rip), %rsi     # 0x13193
movq 0x40(%rsp), %r14
movl %r14d, %edx
movq 0x10(%rsp), %rcx
movl 0x8(%rsp), %r8d
movl %r15d, %r9d
movapd 0x50(%rsp), %xmm0
movsd 0x70(%rsp), %xmm2
movb $0x3, %al
callq 0x1110
movq 0x28(%r13), %rdi
movq 0x78(%rsp), %rsi
xorl %edx, %edx
callq 0x549a
cmpl %eax, 0x1c(%rsp)
jne 0x1691
leal 0x1(%r14), %eax
cmpl 0x18ae6(%rip), %r14d    # 0x1a0ec
movl %eax, %edx
movapd 0x20(%rsp), %xmm3
movq 0x48(%rsp), %r14
jl 0x1316
movapd %xmm3, 0x20(%rsp)
movsd 0x119f1(%rip), %xmm1    # 0x13018
movapd 0x50(%rsp), %xmm0
ucomisd %xmm0, %xmm1
movq 0x189c0(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
movsd 0x38(%rsp), %xmm2
movapd %xmm2, %xmm1
divsd %xmm3, %xmm1
movsd 0x119bf(%rip), %xmm3    # 0x13010
divsd %xmm3, %xmm1
divsd 0x119ab(%rip), %xmm2    # 0x13008
divsd %xmm3, %xmm2
leaq 0x11b93(%rip), %rax     # 0x131fb
leaq 0x11bc4(%rip), %rsi     # 0x13233
cmovaq %rax, %rsi
movq 0x10(%rsp), %rdx
movl 0x8(%rsp), %ecx
movl %r15d, %r8d
movb $0x3, %al
callq 0x1110
movapd 0x20(%rsp), %xmm3
jmp 0x128d
movl %eax, %ebp
movq 0x8(%r13), %rax
movq 0x28(%r13), %rdx
movb (%rax), %sil
movq %rax, %rcx
cmpb (%rdx), %sil
jne 0x16bf
incq %rdx
movq %rax, %rcx
movb 0x1(%rcx), %sil
incq %rcx
leaq 0x1(%rdx), %rdi
cmpb (%rdx), %sil
movq %rdi, %rdx
je 0x16ac
movq 0x18932(%rip), %rdx     # 0x19ff8
movq (%rdx), %rdi
subl %eax, %ecx
leaq 0x11afd(%rip), %rsi     # 0x131cf
movq 0x10(%rsp), %rdx
movl 0x8(%rsp), %r8d
xorl %eax, %eax
callq 0x1110
movl 0x1c(%rsp), %r12d
movaps 0x20(%rsp), %xmm3
jmp 0x127f