// File: /workspace/github_c_makefile_star2_O1/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
movl %esi, %ebx
movq %rdi, %rbp
xorl %eax, %eax
leaq 0x60(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x58(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x50(%rsp), %rcx
movq %rax, (%rcx)
testl %esi, %esi
movl $0x0, %eax
cmovgl %esi, %eax
xorl %r15d, %r15d
movq $0x0, 0x48(%rsp)
movq %rax, 0x18(%rsp)
cmpq %rax, %r15
je 0x37b8
movl %r12d, 0x3c(%rsp)
movq (%rbp,%r15,8), %r12
movq %r12, %rdi
leaq 0xf003(%rip), %rsi      # 0x123d4
callq 0x1120
testq %rax, %rax
jne 0x3404
movq 0x15c16(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
xorl %r14d, %r14d
leaq 0xefe8(%rip), %rsi      # 0x123d7
movq %r12, %rdx
xorl %eax, %eax
callq 0x1110
movl $0xb, %r12d
jmp 0x3754
movq %rax, %r14
movq %r12, %rdi
leaq 0x78(%rsp), %rsi
callq 0x10a0
testl %eax, %eax
movq %rbp, 0x28(%rsp)
jne 0x343c
movl 0x90(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x343c
movq 0xa8(%rsp), %rbp
jmp 0x343e
xorl %ebp, %ebp
testq %rbp, %rbp
jne 0x3459
movq %r14, %rdi
callq 0x172e
movl $0xb, %r12d
xorl %r14d, %r14d
jmp 0x374f
movl %ebx, 0xc(%rsp)
leaq (,%rbp,2), %rbx
addq %rbp, %rbx
movq $-0x4000000, %rax       # imm = 0xFC000000
andq %rax, %rbx
addq $0xc000000, %rbx        # imm = 0xC000000
movabsq $0x240000000, %rcx      # imm = 0x240000000
cmpq %rcx, %rbx
cmovaeq %rcx, %rbx
addq %rax, %rbx
cmpq $0x4000001, %rbx        # imm = 0x4000001
jae 0x349f
movl $0x15, %ebx
xorl %edi, %edi
jmp 0x34e1
movq %rbx, %rdi
callq 0x1150
movq %rax, %rdi
testq %rax, %rax
jne 0x34c4
addq $-0x4000000, %rbx       # imm = 0xFC000000
cmpq $0x4000001, %rbx        # imm = 0x4000001
jae 0x349f
movl $0x4000040, %ebx        # imm = 0x4000040
addq $-0x4000000, %rbx       # imm = 0xFC000000
movq %rbx, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
movq %rdx, %rbx
shrq %rbx
movq %r14, 0x40(%rsp)
callq 0x1030
cmpq %rbp, %rbx
cmovbq %rbx, %rbp
jae 0x3516
movq 0x15afd(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
movq %rbp, %rcx
shrq $0x14, %rcx
leaq 0xeee9(%rip), %rsi      # 0x123f5
movq %r12, %rdx
xorl %eax, %eax
callq 0x1110
movq %r12, 0x68(%rsp)
movl 0x15bc3(%rip), %ebx     # 0x190e4
movq %rbp, %rax
xorl %edx, %edx
divq %rbx
movq %rax, %r14
imulq $0x38, %rax, %rdi
addq $0x38, %rdi
callq 0x1150
movq %rax, %r13
movq %rbp, %rdi
callq 0x1150
movq %rax, 0x70(%rsp)
leal 0x1(%r14), %r12d
movq %rbx, %rdi
callq 0x92a2
movq %rax, %rbx
movl %r12d, 0x38(%rsp)
imull %r12d, %eax
movslq %eax, %rdi
callq 0x1150
movq %rax, 0x10(%rsp)
movq %rbp, %rdi
callq 0x1150
movq %r13, 0x20(%rsp)
testq %r13, %r13
movq 0x70(%rsp), %r13
je 0x36f1
testq %r13, %r13
je 0x36f1
cmpq $0x0, 0x10(%rsp)
je 0x36f1
testq %rax, %rax
je 0x36f1
movq %rax, 0x30(%rsp)
testl %r14d, %r14d
movq 0x68(%rsp), %r12
js 0x362f
movl 0x15b28(%rip), %eax     # 0x190e4
movslq %ebx, %rcx
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq 0x20(%rsp), %rdx
addq $0x28, %rdx
movq $-0x1, %rsi
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %r8
movq %r13, %r9
movq %rbp, %r11
movq %rbp, %r10
leal 0x1(%rsi), %ebx
movl %ebx, -0x28(%rdx)
movq %r9, -0x20(%rdx)
subq %rax, %r10
jbe 0x35fe
movq %rax, -0x18(%rdx)
jmp 0x3608
movslq %r11d, %r10
movq %r10, -0x18(%rdx)
xorl %r10d, %r10d
addq %rax, %r9
movq %r8, -0x10(%rdx)
addq %rcx, %r8
movq $0x0, -0x8(%rdx)
movq %rdi, (%rdx)
addq %rax, %rdi
incq %rsi
addq $0x38, %rdx
movq %r10, %r11
cmpq %r14, %rsi
jb 0x35e9
movq 0x159c2(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
leaq 0xee0e(%rip), %rsi      # 0x1244e
movq %r12, %rdx
xorl %eax, %eax
callq 0x1110
movl $0x1, %esi
movq %r13, %rdi
movq %rbp, %rdx
movq 0x40(%rsp), %r14
movq %r14, %rcx
callq 0x1060
movq %rax, %rbx
movq %r14, %rdi
callq 0x1080
cmpq %rbp, %rbx
jne 0x3767
movl 0x15a6c(%rip), %eax     # 0x190e8
subq $0x8, %rsp
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movl 0x40(%rsp), %esi
movq %r12, %rdx
movl %ebp, %ecx
leaq 0x68(%rsp), %r8
leaq 0x60(%rsp), %r9
pushq %rax
pushq $0xff
leaq 0x68(%rsp), %rax
pushq %rax
callq 0x2aed
addq $0x20, %rsp
addq %rbp, 0x48(%rsp)
movq %r13, %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq 0x30(%rsp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movb $0x1, %r14b
movl 0xc(%rsp), %ebx
movq 0x28(%rsp), %rbp
movq 0x18(%rsp), %rax
movl 0x3c(%rsp), %r12d
jmp 0x3759
movq %rax, %rbx
movq 0x158fd(%rip), %rax     # 0x18ff8
movq (%rax), %rcx
movl $0x1b, %esi
movl $0x1, %edx
leaq 0xed23(%rip), %rdi      # 0x12432
callq 0x1190
movq %r13, %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movq 0x20(%rsp), %rdi
callq 0x1030
movq 0x40(%rsp), %rdi
callq 0x1080
movl $0xc, %r12d
xorl %r14d, %r14d
movl 0xc(%rsp), %ebx
movq 0x28(%rsp), %rbp
movq 0x18(%rsp), %rax
incq %r15
testb %r14b, %r14b
jne 0x33b4
jmp 0x37c0
movq 0x1588a(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
xorl %r14d, %r14d
leaq 0xece9(%rip), %rsi      # 0x12464
movq %r12, %rdx
movl %ebx, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x1110
movq %r13, %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq 0x30(%rsp), %rdi
callq 0x1030
movq 0x20(%rsp), %rdi
callq 0x1030
movl $0xd, %r12d
jmp 0x374b
xorl %r12d, %r12d
cmpl $0x2, %ebx
jge 0x37d5
movl %r12d, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq 0x48(%rsp), %rsi
callq 0x1757
jmp 0x37c0