// File: /workspace/github_c_makefile_star2_O2/Cyan4973[P]FiniteStateEntropy/programs/bench.c
// Function: BMK_benchFiles
int BMK_benchFiles(const char** fileNamesTable, int nbFiles)
{
    int fileIdx=0;
    U64 totalSourceSize = 0;
    U64 totalCompressedSize = 0;
    double totalc = 0.;
    double totald = 0.;

    while (fileIdx<nbFiles) {
        const char* const inFileName = fileNamesTable[fileIdx++];
        FILE* const inFile = fopen( inFileName, "rb" );
        U64    inFileSize;
        size_t benchedSize;
        char* orig_buff;
        int nbChunks;
        int maxCompressedChunkSize;
        size_t readSize;
        char* compressedBuffer; int compressedBuffSize;
        char* destBuffer;
        chunkParameters_t* chunkP;

        /* Check file existence */
        if (inFile==NULL) { DISPLAY( "Pb opening %s\n", inFileName); return 11; }

        /* Memory size evaluation */
        inFileSize = BMK_GetFileSize(inFileName);
        if (inFileSize==0) { DISPLAY( "file is empty\n"); fclose(inFile); return 11; }
        benchedSize = (size_t) BMK_findMaxMem(inFileSize * 3) / 3;
        if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize;
        if (benchedSize < inFileSize)
            DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n",
                    inFileName, (int)(benchedSize>>20));

        /* Allocation */
        chunkP = (chunkParameters_t*) malloc(((benchedSize / chunkSize)+1) * sizeof(chunkParameters_t));
        orig_buff = (char*)malloc((size_t )benchedSize);
        nbChunks = (int) (benchedSize / chunkSize) + 1;
        maxCompressedChunkSize = (int)FSE_compressBound(chunkSize);
        compressedBuffSize = nbChunks * maxCompressedChunkSize;
        compressedBuffer = (char*)malloc((size_t )compressedBuffSize);
        destBuffer = (char*)malloc((size_t )benchedSize);

        if (!orig_buff || !compressedBuffer || !destBuffer || !chunkP) {
            DISPLAY("\nError: not enough memory!\n");
            free(orig_buff);
            free(compressedBuffer);
            free(destBuffer);
            free(chunkP);
            fclose(inFile);
            return 12;
        }

        /* Init chunks */
        {   int i;
            size_t remaining = benchedSize;
            char* in = orig_buff;
            char* out = compressedBuffer;
            char* dst = destBuffer;
            for (i=0; i<nbChunks; i++) {
                chunkP[i].id = i;
                chunkP[i].origBuffer = in; in += chunkSize;
                if (remaining > chunkSize) {
                    chunkP[i].origSize = chunkSize;
                    remaining -= chunkSize;
                } else {
                    chunkP[i].origSize = (int)remaining;
                    remaining = 0;
                }
                chunkP[i].compressedBuffer = out; out += maxCompressedChunkSize;
                chunkP[i].compressedSize = 0;
                chunkP[i].destBuffer = dst; dst += chunkSize;
        }   }

        /* Fill input buffer */
        DISPLAY("Loading %s...       \r", inFileName);
        readSize = fread(orig_buff, 1, benchedSize, inFile);
        fclose(inFile);

        if (readSize != benchedSize) {
            DISPLAY("\nError: problem reading file '%s' (%i read, should be %i) !!    \n",
                    inFileName, (int)readSize, (int)benchedSize);
            free(orig_buff);
            free(compressedBuffer);
            free(destBuffer);
            free(chunkP);
            return 13;
        }

        /* Bench */
        BMK_benchMem(chunkP, nbChunks,
                     inFileName, (int)benchedSize,
                     &totalCompressedSize, &totalc, &totald,
                     255, BMK_tableLog);
        totalSourceSize += benchedSize;

        free(orig_buff);
        free(compressedBuffer);
        free(destBuffer);
        free(chunkP);
    }

    if (nbFiles > 1)
        DISPLAY("%-17.17s :%10llu ->%10llu (%5.2f%%), %6.1f MB/s , %6.1f MB/s\n", "  TOTAL",
                (long long unsigned int)totalSourceSize, (long long unsigned int)totalCompressedSize,
                (double)totalCompressedSize/(double)totalSourceSize*100.,
                (double)totalSourceSize/totalc/CLOCKS_PER_SEC,
                (double)totalSourceSize/totald/CLOCKS_PER_SEC);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
leaq 0x38(%rsp), %rax
andq $0x0, (%rax)
leaq 0x30(%rsp), %rax
andq $0x0, (%rax)
leaq 0x28(%rsp), %rax
andq $0x0, (%rax)
movq %rdi, 0x48(%rsp)
testl %esi, %esi
movl $0x0, %ebx
movl %esi, (%rsp)
cmovgl %esi, %ebx
movq 0x1405d(%rip), %rbp     # 0x15ff8
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rbx, 0x40(%rsp)
cmpq %rbx, %r12
je 0x2267
movq 0x48(%rsp), %rax
movq (%rax,%r12,8), %r15
movq %r15, %rdi
leaq 0xd412(%rip), %rsi      # 0xf3d4
callq 0x1120
testq %rax, %rax
je 0x2280
movq %rax, %r13
movq %r15, 0x20(%rsp)
movq %r15, %rdi
callq 0x23ea
testq %rax, %rax
je 0x232e
movq %rax, %r15
incq %r12
leaq (%rax,%rax,2), %rbx
andq $-0x4000000, %rbx       # imm = 0xFC000000
addq $0xc000000, %rbx        # imm = 0xC000000
movabsq $0x240000000, %rax      # imm = 0x240000000
cmpq %rax, %rbx
cmovaeq %rax, %rbx
xorl %eax, %eax
testq %rax, %rax
jne 0x2038
addq $-0x4000000, %rbx       # imm = 0xFC000000
cmpq $0x4000001, %rbx        # imm = 0x4000001
jb 0x2033
movq %rbx, %rdi
callq 0x1150
jmp 0x2014
movl $0x4000040, %ebx        # imm = 0x4000040
movq %r13, 0x18(%rsp)
movq %r12, 0x50(%rsp)
movq %r14, 0x58(%rsp)
movq %rax, %rdi
callq 0x1030
addq $-0x4000000, %rbx       # imm = 0xFC000000
movq %rbx, %rax
xorl %edx, %edx
pushq $0x3
popq %rcx
divq %rcx
cmpq %r15, %rax
cmovbq %rax, %r15
jae 0x2088
movq (%rbp), %rdi
movq %r15, %rcx
shrq $0x14, %rcx
leaq 0xd379(%rip), %rsi      # 0xf3f5
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x1110
movl 0x14055(%rip), %r13d    # 0x160e4
movq %r15, %rax
xorl %edx, %edx
divq %r13
movq %rax, %r12
imulq $0x38, %rax, %rdi
addq $0x38, %rdi
callq 0x1150
movq %rax, %r14
movq %r15, %rdi
callq 0x1150
movq %rax, 0x60(%rsp)
leal 0x1(%r12), %ebx
movq %r13, %rdi
movq %r14, %r13
callq 0x816f
movq %rax, %rbp
movl %ebx, 0x4(%rsp)
imull %ebx, %eax
movq 0x60(%rsp), %rbx
movslq %eax, %rdi
callq 0x1150
movq %rax, %r14
movq %r15, %rdi
callq 0x1150
movq %r14, %r9
movq %rax, %r14
movq %r13, %xmm0
movq %rax, %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movq %r9, %xmm0
movq %rbx, %xmm2
punpcklqdq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0]
pxor %xmm0, %xmm0
pcmpeqd %xmm0, %xmm2
pcmpeqd %xmm0, %xmm1
movdqa %xmm2, %xmm0
shufps $0xdd, %xmm1, %xmm0     # xmm0 = xmm0[1,3],xmm1[1,3]
shufps $0x88, %xmm1, %xmm2     # xmm2 = xmm2[0,2],xmm1[0,2]
andps %xmm0, %xmm2
movmskps %xmm2, %eax
testl %eax, %eax
jne 0x2350
movl 0x13fad(%rip), %eax     # 0x160e4
movslq %ebp, %rcx
movslq %r12d, %rdx
movq %r13, %rsi
addq $0x28, %rsi
xorl %edi, %edi
movq %r15, %r11
movq %rbx, %r8
movq %r9, 0x8(%rsp)
movq %r14, %r10
cmpq %rdx, %rdi
jg 0x2199
movl %edi, -0x28(%rsi)
movq %r8, -0x20(%rsi)
addq %rax, %r8
movq %r11, %r12
subq %rax, %r12
movslq %r11d, %rbp
cmovaq %rax, %rbp
movl $0x0, %r11d
cmovaeq %r12, %r11
movq %rbp, -0x18(%rsi)
movq %r9, -0x10(%rsi)
addq %rcx, %r9
andq $0x0, -0x8(%rsi)
movq %r10, (%rsi)
addq %rax, %r10
incq %rdi
addq $0x38, %rsi
jmp 0x2154
movq %r14, 0x10(%rsp)
movq %r13, %r14
movq 0x13e50(%rip), %rbp     # 0x15ff8
movq (%rbp), %rdi
leaq 0xd29b(%rip), %rsi      # 0xf44e
movq 0x20(%rsp), %rbp
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1110
movq %rbx, %rdi
pushq $0x1
popq %rsi
movq %r15, %rdx
movq 0x18(%rsp), %r13
movq %r13, %rcx
callq 0x1060
movq %rax, %r12
movq %r13, %rdi
callq 0x1080
cmpq %r15, %r12
jne 0x23a1
movl 0x13ef6(%rip), %eax     # 0x160e8
subq $0x8, %rsp
movq %r14, %r12
movq %r14, %rdi
movl 0xc(%rsp), %esi
movq %rbp, %rdx
movl %r15d, %ecx
leaq 0x40(%rsp), %r8
leaq 0x38(%rsp), %r9
pushq %rax
pushq $0xff
leaq 0x40(%rsp), %rax
pushq %rax
callq 0x1755
addq $0x20, %rsp
movq 0x58(%rsp), %r14
addq %r15, %r14
movq %rbx, %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq %r12, %rdi
callq 0x1030
movq 0x40(%rsp), %rbx
movq 0x50(%rsp), %r12
movq 0x13d96(%rip), %rbp     # 0x15ff8
jmp 0x1fa6
xorl %ebx, %ebx
cmpl $0x2, (%rsp)
jge 0x229a
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbp), %rdi
leaq 0xd14c(%rip), %rsi      # 0xf3d7
movq %r15, %rdx
xorl %eax, %eax
callq 0x1110
jmp 0x234c
movq (%rbp), %rdi
movq 0x38(%rsp), %r8
movq %r8, %xmm1
movq 0xcd90(%rip), %xmm2     # 0xf040
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xcd94(%rip), %xmm3     # 0xf050
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %r14, %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
mulsd 0xcd27(%rip), %xmm0     # 0xf018
movapd %xmm2, %xmm1
divsd 0x30(%rsp), %xmm1
movsd 0xcd25(%rip), %xmm3     # 0xf028
divsd %xmm3, %xmm1
divsd 0x28(%rsp), %xmm2
divsd %xmm3, %xmm2
leaq 0xd18e(%rip), %rsi      # 0xf4a6
leaq 0xd1c5(%rip), %rdx      # 0xf4e4
movq %r14, %rcx
movb $0x3, %al
callq 0x1110
jmp 0x226f
movq (%rbp), %rcx
leaq 0xd0ad(%rip), %rdi      # 0xf3e6
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
movq %r13, %rdi
callq 0x1080
pushq $0xb
jmp 0x239b
movq 0x13ca1(%rip), %rax     # 0x15ff8
movq (%rax), %rcx
leaq 0xd0d1(%rip), %rdi      # 0xf432
pushq $0x1b
popq %rsi
pushq $0x1
popq %rdx
movq %r9, %r15
callq 0x1190
movq %rbx, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
movq 0x18(%rsp), %rdi
callq 0x1080
pushq $0xc
popq %rbx
jmp 0x226f
movq 0x13c50(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
leaq 0xd0b2(%rip), %rsi      # 0xf464
movq %rbp, %rdx
movl %r12d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x1110
movq %rbx, %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
pushq $0xd
jmp 0x239b