// File: /workspace/github_c_makefile_star2_O3/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 $0x108, %rsp            # imm = 0x108
movq %rdi, 0x58(%rsp)
xorl %ebx, %ebx
movq %rbx, 0x48(%rsp)
movq %rbx, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
testl %esi, %esi
jle 0x391f
movl %esi, 0x28(%rsp)
movl %esi, %eax
movq %rax, 0x50(%rsp)
xorl %r15d, %r15d
movq 0x16a21(%rip), %rbp     # 0x19ff8
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x58(%rsp), %rax
movq (%rax,%rbx,8), %r13
movq %r13, %rdi
leaq 0xfea5(%rip), %rsi      # 0x13494
callq 0x1120
testq %rax, %rax
je 0x3905
movq %rax, 0x20(%rsp)
movq %r13, %rdi
leaq 0x78(%rsp), %rsi
callq 0x10a0
testl %eax, %eax
jne 0x38f9
movl 0x90(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x38f9
movq 0xa8(%rsp), %r12
testq %r12, %r12
je 0x38f9
incq %rbx
movq %rbx, 0x60(%rsp)
leaq (%r12,%r12,2), %rbx
andq $-0x4000000, %rbx       # imm = 0xFC000000
addq $0xc000000, %rbx        # imm = 0xC000000
movabsq $0x240000000, %rax      # imm = 0x240000000
cmpq %rax, %rbx
cmovaeq %rax, %rbx
movq %r14, 0x68(%rsp)
addq $-0x4000000, %rbx       # imm = 0xFC000000
cmpq $0x4000001, %rbx        # imm = 0x4000001
jb 0x3690
movq %rbx, %rdi
callq 0x1150
testq %rax, %rax
je 0x3671
jmp 0x3697
movl $0x4000040, %ebx        # imm = 0x4000040
xorl %eax, %eax
movq %rax, %rdi
callq 0x1030
addq $-0x4000000, %rbx       # imm = 0xFC000000
movq %rbx, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
movq %rdx, %r14
shrq %r14
cmpq %r12, %r14
cmovaeq %r12, %r14
jae 0x36e1
movq (%rbp), %rdi
movq %r14, %rcx
shrq $0x14, %rcx
leaq 0xfdde(%rip), %rsi      # 0x134b5
movq %r13, %rdx
xorl %eax, %eax
callq 0x1110
movq %r13, 0x70(%rsp)
movl 0x169f7(%rip), %r12d    # 0x1a0e4
movq %r14, %rax
xorl %edx, %edx
divq %r12
movq %rax, %r13
imulq $0x38, %rax, %rdi
addq $0x38, %rdi
callq 0x1150
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0x1150
movq %rax, 0x8(%rsp)
leal 0x1(%r13), %ebx
movq %r12, %rdi
callq 0x9aca
movq %rax, %rbp
movl %ebx, 0x2c(%rsp)
imull %ebx, %eax
movslq %eax, %rdi
callq 0x1150
movq %rax, %r12
movq %r14, %rdi
callq 0x1150
movq 0x10(%rsp), %xmm0
movq %rax, %rbx
movq %rax, %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movq %r12, 0x18(%rsp)
movq %r12, %xmm0
movq 0x8(%rsp), %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 0x3933
testl %r13d, %r13d
js 0x3800
movl 0x1694d(%rip), %eax     # 0x1a0e4
movslq %ebp, %rcx
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq 0x10(%rsp), %rdx
addq $0x28, %rdx
movq $-0x1, %rsi
movq %rbx, %rdi
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
movq %r14, %r11
movq %r14, %r10
incq %rsi
movl %esi, -0x28(%rdx)
movq %r9, -0x20(%rdx)
addq %rax, %r9
subq %rax, %r10
movslq %r11d, %r11
cmovaq %rax, %r11
cmovbq %r15, %r10
movq %r11, -0x18(%rdx)
movq %r8, -0x10(%rdx)
addq %rcx, %r8
movq %r15, -0x8(%rdx)
movq %rdi, (%rdx)
addq %rax, %rdi
addq $0x38, %rdx
movq %r10, %r11
cmpq %r13, %rsi
jb 0x37c4
movq %rbx, 0x30(%rsp)
movq 0x167ec(%rip), %rbp     # 0x19ff8
movq (%rbp), %rdi
leaq 0xfcf7(%rip), %rsi      # 0x1350e
movq 0x70(%rsp), %r12
movq %r12, %rdx
xorl %eax, %eax
callq 0x1110
movl $0x1, %esi
movq 0x8(%rsp), %rdi
movq %r14, %rdx
movq 0x20(%rsp), %rbp
movq %rbp, %rcx
callq 0x1060
movq %rax, %r13
movq %rbp, %rdi
callq 0x1080
cmpq %r14, %r13
jne 0x398a
movl 0x1688e(%rip), %eax     # 0x1a0e8
subq $0x8, %rsp
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movl 0x34(%rsp), %esi
movq %r12, %rdx
movl %r14d, %ecx
leaq 0x50(%rsp), %r8
leaq 0x48(%rsp), %r9
pushq %rax
pushq $0xff
leaq 0x50(%rsp), %rax
pushq %rax
callq 0x2d3d
addq $0x20, %rsp
movq 0x68(%rsp), %rax
addq %r14, %rax
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x1030
movq 0x18(%rsp), %rdi
callq 0x1030
movq 0x30(%rsp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movq 0x60(%rsp), %rbx
cmpq 0x50(%rsp), %rbx
movq 0x16727(%rip), %rbp     # 0x19ff8
jne 0x35dc
xorl %ebx, %ebx
cmpl $0x1, 0x28(%rsp)
je 0x391f
leaq 0x48(%rsp), %rdi
leaq 0x40(%rsp), %rdx
leaq 0x38(%rsp), %rcx
movq %r14, %rsi
callq 0x1739
jmp 0x391f
movq 0x20(%rsp), %rdi
callq 0x17cb
jmp 0x391a
movq (%rbp), %rdi
leaq 0xfb87(%rip), %rsi      # 0x13497
movq %r13, %rdx
xorl %eax, %eax
callq 0x1110
movl $0xb, %ebx
movl %ebx, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x166be(%rip), %rax     # 0x19ff8
movq (%rax), %rcx
leaq 0xfbae(%rip), %rdi      # 0x134f2
movl $0x1b, %esi
movl $0x1, %edx
callq 0x1190
movq 0x8(%rsp), %rdi
callq 0x1030
movq 0x18(%rsp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq 0x20(%rsp), %rdi
callq 0x1080
movl $0xc, %ebx
jmp 0x391f
movq 0x16667(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0xfb89(%rip), %rsi      # 0x13524
movq %r12, %rdx
movl %r13d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x1110
movq 0x8(%rsp), %rdi
callq 0x1030
movq 0x18(%rsp), %rdi
callq 0x1030
movq 0x30(%rsp), %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movl $0xd, %ebx
jmp 0x391f