// File: /workspace/github_c_makefile_star2_O1/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 $0x98, %rsp
movq %r9, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movl %ecx, %r13d
movq %rdx, 0x20(%rsp)
movl %esi, %ebx
movq %rdi, %r14
movq 0x8(%rdi), %rdi
movslq %ecx, %rsi
xorl %ebp, %ebp
movq %rsi, 0x70(%rsp)
xorl %edx, %edx
callq 0x51ce
movl %eax, 0x10(%rsp)
movq 0x17dbd(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
leaq 0x10e40(%rip), %rsi     # 0x12085
leaq 0x11259(%rip), %rdx     # 0x124a5
xorl %eax, %eax
callq 0x1110
cmpl $0x0, 0x17e92(%rip)     # 0x190ec
cvtsi2sd %r13d, %xmm2
jle 0x161a
movl 0xd8(%rsp), %r12d
movsd 0x10d93(%rip), %xmm1    # 0x12008
movapd %xmm2, %xmm0
movapd %xmm1, 0x30(%rsp)
divsd %xmm1, %xmm0
divsd 0x10d85(%rip), %xmm0    # 0x12010
movsd %xmm0, 0x68(%rsp)
movl %r13d, %eax
movq %rax, 0x60(%rsp)
movl %ebx, 0x14(%rsp)
movl %ebx, %eax
imulq $0x38, %rax, %rbx
pushq $0x1
popq %rdx
movl %r13d, 0xc(%rsp)
movsd %xmm2, 0x18(%rsp)
movq 0x17d40(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
leaq 0x10dca(%rip), %rsi     # 0x1208c
movq %rdx, 0x28(%rsp)
movq 0x20(%rsp), %rcx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x1110
testl %r13d, %r13d
movq 0x60(%rsp), %rdx
jle 0x12f1
xorl %eax, %eax
movq 0x18(%r14), %rcx
movb %al, (%rcx,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x12e2
callq 0x1070
movq %rax, %r15
callq 0x1070
cmpq %r15, %rax
je 0x12f9
callq 0x1070
movq %rax, %rbp
callq 0x1070
subq %rbp, %rax
xorpd %xmm0, %xmm0
cmpq $0x1e847f, %rax         # imm = 0x1E847F
jg 0x1377
xorl %r15d, %r15d
cmpl $0x0, 0x14(%rsp)
jle 0x135a
xorl %r13d, %r13d
movq 0x18(%r14,%r13), %rdi
movq 0x8(%r14,%r13), %rdx
movq 0x10(%r14,%r13), %rsi
movq %rsi, %rcx
shrq %rcx
xorl %r8d, %r8d
movl %r12d, %r9d
callq 0x9c8a
movq %rax, 0x20(%r14,%r13)
addq $0x38, %r13
cmpq %r13, %rbx
jne 0x132c
incl %r15d
callq 0x1070
subq %rbp, %rax
cmpq $0x1e8480, %rax         # imm = 0x1E8480
jl 0x1322
cvtsi2sd %r15d, %xmm0
movl 0xc(%rsp), %r13d
movsd %xmm0, 0x40(%rsp)
callq 0x1070
cmpl $0x0, 0x14(%rsp)
jle 0x13a9
xorl %ecx, %ecx
xorl %r15d, %r15d
movsd 0x18(%rsp), %xmm2
movq 0x28(%rsp), %rdx
addq 0x20(%r14,%rcx), %r15
addq $0x38, %rcx
cmpq %rcx, %rbx
jne 0x1399
jmp 0x13b7
xorl %r15d, %r15d
movsd 0x18(%rsp), %xmm2
movq 0x28(%rsp), %rdx
subq %rbp, %rax
cvtsi2sd %rax, %xmm4
movapd 0x30(%rsp), %xmm3
movapd %xmm3, %xmm0
movsd 0x40(%rsp), %xmm5
mulsd %xmm5, %xmm0
movapd %xmm4, %xmm1
divsd %xmm5, %xmm1
cmpltsd %xmm0, %xmm4
andpd %xmm4, %xmm1
andnpd %xmm3, %xmm4
orpd %xmm1, %xmm4
movq %r15, %xmm1
punpckldq 0x10c47(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x10c4f(%rip), %xmm1    # 0x12050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd %xmm2, %xmm0
mulsd 0x10bff(%rip), %xmm0    # 0x12018
movq 0x17bd8(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
movapd %xmm2, %xmm1
movapd %xmm4, 0x80(%rsp)
divsd %xmm4, %xmm1
divsd 0x10bd4(%rip), %xmm1    # 0x12010
leaq 0x10c60(%rip), %rsi     # 0x120a3
movq 0x20(%rsp), %rcx
movl %r13d, %r8d
movl %r15d, %r9d
movapd %xmm0, 0x40(%rsp)
movb $0x2, %al
callq 0x1110
callq 0x1070
movq %rax, %rbp
callq 0x1070
cmpq %rbp, %rax
je 0x1463
callq 0x1070
movq %rax, %rbp
callq 0x1070
movq %rbp, 0x30(%rsp)
subq %rbp, %rax
xorpd %xmm0, %xmm0
cmpq $0x1e847f, %rax         # imm = 0x1E847F
jg 0x14e3
xorl %r13d, %r13d
cmpl $0x0, 0x14(%rsp)
jle 0x14c4
xorl %ebp, %ebp
movq 0x28(%r14,%rbp), %rdi
movq 0x10(%r14,%rbp), %rsi
movq 0x18(%r14,%rbp), %rdx
shrq %rsi
movq 0x20(%r14,%rbp), %rcx
callq 0xa0f4
movq %rax, 0x20(%r14,%rbp)
addq $0x38, %rbp
cmpq %rbp, %rbx
jne 0x149a
incl %r13d
callq 0x1070
subq 0x30(%rsp), %rax
cmpq $0x1e8480, %rax         # imm = 0x1E8480
jl 0x1491
cvtsi2sd %r13d, %xmm0
movl 0xc(%rsp), %r13d
movsd %xmm0, 0x78(%rsp)
callq 0x1070
subq 0x30(%rsp), %rax
cvtsi2sd %rax, %xmm2
movapd 0x80(%rsp), %xmm3
movapd %xmm3, %xmm0
movsd 0x78(%rsp), %xmm4
mulsd %xmm4, %xmm0
movapd %xmm2, %xmm1
divsd %xmm4, %xmm1
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm2
orpd %xmm1, %xmm2
movq 0x17ac9(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
movsd 0x18(%rsp), %xmm1
movapd %xmm2, 0x30(%rsp)
divsd %xmm2, %xmm1
divsd 0x10ac6(%rip), %xmm1    # 0x12010
leaq 0x10b82(%rip), %rsi     # 0x120d3
movl %r13d, %r8d
movq 0x28(%rsp), %r13
movl %r13d, %edx
movq 0x20(%rsp), %rcx
movl %r15d, %r9d
movapd 0x40(%rsp), %xmm0
movsd 0x68(%rsp), %xmm2
movb $0x3, %al
callq 0x1110
movq 0x28(%r14), %rdi
movq 0x70(%rsp), %rsi
xorl %edx, %edx
callq 0x51ce
movl %eax, %ebp
cmpl %eax, 0x10(%rsp)
jne 0x15b2
leal 0x1(%r13), %eax
cmpl 0x17b52(%rip), %r13d    # 0x190ec
movl %eax, %edx
movsd 0x18(%rsp), %xmm2
movl 0xc(%rsp), %r13d
jl 0x12b1
jmp 0x1635
movq 0x8(%r14), %rax
movq 0x28(%r14), %rdx
movb (%rax), %sil
movq %rax, %rcx
cmpb (%rdx), %sil
jne 0x15de
incq %rdx
movq %rax, %rcx
movb 0x1(%rcx), %sil
incq %rcx
leaq 0x1(%rdx), %rdi
cmpb (%rdx), %sil
movq %rdi, %rdx
je 0x15cb
movq 0x17a13(%rip), %rdx     # 0x18ff8
movq (%rdx), %rdi
subl %eax, %ecx
leaq 0x10b1e(%rip), %rsi     # 0x1210f
movq 0x20(%rsp), %rdx
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x1110
cmpl %ebp, 0x10(%rsp)
movq 0x28(%rsp), %r13
je 0x158f
movsd 0x18(%rsp), %xmm2
movl 0xc(%rsp), %r13d
jmp 0x1635
movsd 0x109e6(%rip), %xmm0    # 0x12008
movapd %xmm0, 0x30(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
xorl %r15d, %r15d
movq 0xd0(%rsp), %rbx
cmpl %ebp, 0x10(%rsp)
je 0x1680
movq 0x50(%rsp), %rax
addq %r15, (%rax)
movq 0x58(%rsp), %rax
movapd 0x30(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movsd (%rbx), %xmm0
addsd 0x1099e(%rip), %xmm0    # 0x12008
movsd %xmm0, (%rbx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x10990(%rip), %xmm1    # 0x12018
movapd 0x40(%rsp), %xmm0
ucomisd %xmm0, %xmm1
movq 0x1795f(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
movapd %xmm2, %xmm1
divsd 0x30(%rsp), %xmm1
movsd 0x10962(%rip), %xmm3    # 0x12010
divsd %xmm3, %xmm1
divsd 0x1094e(%rip), %xmm2    # 0x12008
divsd %xmm3, %xmm2
leaq 0x10a76(%rip), %rax     # 0x1213b
leaq 0x10aa7(%rip), %rsi     # 0x12173
cmovaq %rax, %rsi
movq 0x20(%rsp), %rdx
movl %r13d, %ecx
movl %r15d, %r8d
movb $0x3, %al
callq 0x1110
jmp 0x1643