// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x29db
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq 0x22e9a(%rip), %rsi     # 0x253d4
callq 0x1110
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x2572
movq 0x29aa7(%rip), %rax     # 0x2bff8
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
leaq 0x22e78(%rip), %rsi     # 0x253d7
movb $0x0, %al
callq 0x1100
movl $0xb, -0x4(%rbp)
jmp 0x2a8b
movq -0x40(%rbp), %rdi
callq 0x2aa0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x25b3
movq 0x29a6b(%rip), %rax     # 0x2bff8
movq (%rax), %rdi
leaq 0x22e4f(%rip), %rsi     # 0x253e6
movb $0x0, %al
callq 0x1100
movq -0x48(%rbp), %rdi
callq 0x1080
movl $0xb, -0x4(%rbp)
jmp 0x2a8b
imulq $0x3, -0x50(%rbp), %rdi
callq 0x2b00
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0x25dd
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x260d
movq 0x29a0a(%rip), %rax     # 0x2bff8
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
movq -0x58(%rbp), %rax
shrq $0x14, %rax
movl %eax, %ecx
leaq 0x22def(%rip), %rsi     # 0x253f5
movb $0x0, %al
callq 0x1100
movq -0x58(%rbp), %rax
movl 0x29ac5(%rip), %ecx     # 0x2c0dc
xorl %edx, %edx
divq %rcx
addq $0x1, %rax
imulq $0x38, %rax, %rdi
callq 0x1140
movq %rax, -0x90(%rbp)
movq -0x58(%rbp), %rdi
callq 0x1140
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movl 0x29a95(%rip), %ecx     # 0x2c0dc
xorl %edx, %edx
divq %rcx
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movl 0x29a84(%rip), %eax     # 0x2c0dc
movl %eax, %edi
callq 0x12490
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
imull -0x68(%rbp), %eax
movl %eax, -0x7c(%rbp)
movslq -0x7c(%rbp), %rdi
callq 0x1140
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rdi
callq 0x1140
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x26ab
cmpq $0x0, -0x78(%rbp)
je 0x26ab
cmpq $0x0, -0x88(%rbp)
je 0x26ab
cmpq $0x0, -0x90(%rbp)
jne 0x2702
movq 0x29946(%rip), %rax     # 0x2bff8
movq (%rax), %rdi
leaq 0x22d76(%rip), %rsi     # 0x25432
movb $0x0, %al
callq 0x1100
movq -0x60(%rbp), %rdi
callq 0x1030
movq -0x78(%rbp), %rdi
callq 0x1030
movq -0x88(%rbp), %rdi
callq 0x1030
movq -0x90(%rbp), %rdi
callq 0x1030
movq -0x48(%rbp), %rdi
callq 0x1080
movl $0xc, -0x4(%rbp)
jmp 0x2a8b
movq -0x58(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0x28bd
movl -0x94(%rbp), %ecx
movq -0x90(%rbp), %rax
movslq -0x94(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0xa8(%rbp), %rcx
movq -0x90(%rbp), %rax
movslq -0x94(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl 0x2994f(%rip), %ecx     # 0x2c0dc
movq -0xa8(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
movl 0x2992f(%rip), %ecx     # 0x2c0dc
cmpq %rcx, %rax
jbe 0x27ee
movl 0x29924(%rip), %eax     # 0x2c0dc
movl %eax, %ecx
movq -0x90(%rbp), %rax
movslq -0x94(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movl 0x29903(%rip), %eax     # 0x2c0dc
movl %eax, %ecx
movq -0xa0(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xa0(%rbp)
jmp 0x281c
movq -0xa0(%rbp), %rax
movslq %eax, %rcx
movq -0x90(%rbp), %rax
movslq -0x94(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq $0x0, -0xa0(%rbp)
movq -0xb0(%rbp), %rcx
movq -0x90(%rbp), %rax
movslq -0x94(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movl -0x68(%rbp), %ecx
movq -0xb0(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x90(%rbp), %rax
movslq -0x94(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movq -0xb8(%rbp), %rcx
movq -0x90(%rbp), %rax
movslq -0x94(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x28(%rax)
movl 0x29846(%rip), %ecx     # 0x2c0dc
movq -0xb8(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x273b
movq 0x29734(%rip), %rax     # 0x2bff8
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
leaq 0x22b7c(%rip), %rsi     # 0x2544e
movb $0x0, %al
callq 0x1100
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq -0x48(%rbp), %rcx
movl $0x1, %esi
callq 0x1060
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1080
movq -0x70(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x2965
movq 0x296eb(%rip), %rax     # 0x2bff8
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
movq -0x70(%rbp), %rax
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %eax, %r8d
leaq 0x22b3c(%rip), %rsi     # 0x25464
movb $0x0, %al
callq 0x1100
movq -0x60(%rbp), %rdi
callq 0x1030
movq -0x78(%rbp), %rdi
callq 0x1030
movq -0x88(%rbp), %rdi
callq 0x1030
movq -0x90(%rbp), %rdi
callq 0x1030
movl $0xd, -0x4(%rbp)
jmp 0x2a8b
movq -0x90(%rbp), %rdi
movl -0x64(%rbp), %esi
movq -0x40(%rbp), %rdx
movq -0x58(%rbp), %rax
movl %eax, %ecx
movl 0x29761(%rip), %eax     # 0x2c0e0
leaq -0x28(%rbp), %r8
leaq -0x30(%rbp), %r9
leaq -0x38(%rbp), %r10
movq %r10, (%rsp)
movl $0xff, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x1a30
movq -0x58(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x60(%rbp), %rdi
callq 0x1030
movq -0x78(%rbp), %rdi
callq 0x1030
movq -0x88(%rbp), %rdi
callq 0x1030
movq -0x90(%rbp), %rdi
callq 0x1030
jmp 0x2509
cmpl $0x1, -0x14(%rbp)
jle 0x2a84
movq 0x2960c(%rip), %rax     # 0x2bff8
movq (%rax), %rdi
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq %r8, %xmm0
movaps 0x2263d(%rip), %xmm3    # 0x25040
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x22641(%rip), %xmm1    # 0x25050
subpd %xmm1, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
movq %rcx, %xmm2
punpckldq %xmm3, %xmm2    # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
subpd %xmm1, %xmm2
movaps %xmm2, %xmm1
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd 0x225d6(%rip), %xmm1    # 0x25018
mulsd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm3
movaps %xmm2, %xmm1
divsd %xmm3, %xmm1
movsd 0x225c6(%rip), %xmm3    # 0x25020
divsd %xmm3, %xmm1
divsd -0x38(%rbp), %xmm2
movsd 0x225b5(%rip), %xmm3    # 0x25020
divsd %xmm3, %xmm2
leaq 0x22a30(%rip), %rsi     # 0x254a6
leaq 0x22a67(%rip), %rdx     # 0x254e4
movb $0x3, %al
callq 0x1100
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)