// File: /workspace/github_c_makefile_star2_O1/Cyan4973[P]FiniteStateEntropy/programs/fileio.c
// Function: FIO_compressFilename
unsigned long long FIO_compressFilename(const char* output_filename, const char* input_filename)
{
    U64 filesize = 0;
    U64 compressedfilesize = 0;
    FILE* finput;
    FILE* foutput;
    size_t const inputBlockSize = FIO_blockID_to_blockSize(g_blockSizeId);
    char* const in_buff = (char*)malloc(inputBlockSize);
    char* const out_buff = (char*)malloc(FSE_compressBound(inputBlockSize) + 5);
    XXH32_state_t xxhState;
    typedef size_t (*compressor_t) (void* dst, size_t dstSize, const void* src, size_t srcSize);
    compressor_t compressor;
    unsigned magicNumber;


    /* Init */
    if (!in_buff || !out_buff) EXM_THROW(21, "Allocation error : not enough memory");
    XXH32_reset (&xxhState, FSE_CHECKSUM_SEED);
    get_fileHandle(input_filename, output_filename, &finput, &foutput);
    switch (g_compressor)
    {
    case FIO_fse:
        compressor = FSE_compress;
        magicNumber = FIO_magicNumber_fse;
        break;
    case FIO_huf:
        compressor = HUF_compress;
        magicNumber = FIO_magicNumber_huf;
        break;
    case FIO_zlibh:
        compressor = FIO_ZLIBH_compress;
        magicNumber = FIO_magicNumber_zlibh;
        break;
    default :
        EXM_THROW(20, "unknown compressor selection");
    }

    /* Write Frame Header */
    FIO_writeLE32(out_buff, magicNumber);
    out_buff[4] = (char)g_blockSizeId;          /* Max Block Size descriptor */
    { size_t const sizeCheck = fwrite(out_buff, 1, FIO_FRAMEHEADERSIZE, foutput);
      if (sizeCheck!=FIO_FRAMEHEADERSIZE) EXM_THROW(22, "Write error : cannot write header"); }
    compressedfilesize += FIO_FRAMEHEADERSIZE;

    /* Main compression loop */
    while (1) {
        /* Fill input Buffer */
        size_t cSize;
        size_t const inSize = fread(in_buff, (size_t)1, (size_t)inputBlockSize, finput);
        DISPLAYLEVEL(6, "reading %zu bytes from input (%s)\n",
                        inSize, input_filename);
        if (inSize==0) break;
        filesize += inSize;
        XXH32_update(&xxhState, in_buff, inSize);
        DISPLAYUPDATE(2, "\rRead : %u MB   ", (U32)(filesize>>20));

        /* Compress Block */
        cSize = compressor(out_buff + FIO_maxBlockHeaderSize, FSE_compressBound(inputBlockSize), in_buff, inSize);
        if (FSE_isError(cSize)) EXM_THROW(23, "Compression error : %s ", FSE_getErrorName(cSize));

        /* Write cBlock */
        switch(cSize)
        {
        size_t headerSize;
        case 0: /* raw */
            DISPLAYLEVEL(6, "packing uncompressed block, of size %zu \n", inSize);
            if (inSize == inputBlockSize) {
                out_buff[0] = (BYTE)((bt_raw << 6) + BIT5);
                headerSize = 1;
            } else {
                out_buff[0] = (BYTE)(bt_raw << 6);
                out_buff[1] = (BYTE)(inSize >> 8);
                out_buff[2] = (BYTE)inSize;
                headerSize = 3;
            }
            { size_t const sizeCheck = fwrite(out_buff, 1, headerSize, foutput);
              if (sizeCheck!=headerSize) EXM_THROW(24, "Write error : cannot write block header"); }
            { size_t const sizeCheck = fwrite(in_buff, 1, inSize, foutput);
              if (sizeCheck!=(size_t)(inSize)) EXM_THROW(25, "Write error : cannot write block"); }
            compressedfilesize += inSize + headerSize;
            break;
        case 1: /* rle */
            DISPLAYLEVEL(6, "packing RLE block, of size %zu \n", inSize);
            if (inSize == inputBlockSize) {
                out_buff[0] = (BYTE)((bt_rle << 6) + BIT5);
                headerSize = 1;
            } else {
                out_buff[0] = (BYTE)(bt_rle << 6);
                out_buff[1] = (BYTE)(inSize >> 8);
                out_buff[2] = (BYTE)inSize;
                headerSize = 3;
            }
            out_buff[headerSize] = in_buff[0];
            { size_t const sizeCheck = fwrite(out_buff, 1, headerSize+1, foutput);
              if (sizeCheck!=(headerSize+1)) EXM_THROW(26, "Write error : cannot write rle block"); }
            compressedfilesize += headerSize + 1;
            break;
        default : /* compressed */
            DISPLAYLEVEL(6, "packing compressed block, of size %zu, into %zu bytes \n",
                            inSize, cSize);
            if (inSize == inputBlockSize) {
                out_buff[2] = (BYTE)((bt_compressed << 6) + BIT5);
                DISPLAYLEVEL(7, "generated block descriptor : %u \n", out_buff[2]);
                out_buff[3] = (BYTE)(cSize >> 8);
                out_buff[4] = (BYTE)cSize;
                headerSize = 3;
            } else {
                out_buff[0] = (BYTE)(bt_compressed << 6);
                out_buff[1] = (BYTE)(inSize >> 8);
                out_buff[2] = (BYTE)inSize;
                out_buff[3] = (BYTE)(cSize >> 8);
                out_buff[4] = (BYTE)cSize;
                headerSize = FIO_maxBlockHeaderSize;
            }
            { size_t const sizeCheck = fwrite(out_buff+(FIO_maxBlockHeaderSize-headerSize), 1, headerSize+cSize, foutput);
              if (sizeCheck!=(headerSize+cSize)) EXM_THROW(27, "Write error : cannot write rle block"); }
            compressedfilesize += headerSize + cSize;
            break;
        }

        DISPLAYUPDATE(2, "\rRead : %u MB  ==> %.2f%%   ", (U32)(filesize>>20), (double)(compressedfilesize/filesize)*100);
    }

    /* Checksum */
    {   U32 checksum = XXH32_digest(&xxhState);
        checksum = (checksum >> 5) & ((1U<<22)-1);
        out_buff[2] = (BYTE)checksum;
        out_buff[1] = (BYTE)(checksum >> 8);
        out_buff[0] = (BYTE)((checksum >> 16) + (bt_crc << 6));
        { size_t const sizeCheck = fwrite(out_buff, 1, 3, foutput);
          if (sizeCheck!=3) EXM_THROW(28, "Write error : cannot write checksum"); }
        compressedfilesize += 3;
    }

    /* Status */
    DISPLAYLEVEL(2, "\r%79s\r", "");
    DISPLAYLEVEL(2,"Compressed %llu bytes into %llu bytes ==> %.2f%%\n",
        (unsigned long long) filesize, (unsigned long long) compressedfilesize, (double)(compressedfilesize/filesize)*100);

    /* clean */
    free(in_buff);
    free(out_buff);
    fclose(finput);
    fclose(foutput);

    return compressedfilesize;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
movl $0x8000, %edi           # imm = 0x8000
callq 0x1150
movq %rax, %r14
movl $0x8000, %edi           # imm = 0x8000
callq 0x92a2
leaq 0x5(%rax), %rdi
callq 0x1150
testq %r14, %r14
je 0x471a
testq %rax, %rax
je 0x471a
movq %rax, 0x8(%rsp)
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0x5525
leaq 0x40(%rsp), %rdx
leaq 0x38(%rsp), %rcx
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x4826
movl 0x14fce(%rip), %eax     # 0x19140
cmpq $0x3, %rax
jae 0x475d
movl %eax, %ecx
shlb $0x4, %cl
addb $0x23, %cl
leaq 0x14c25(%rip), %rdx     # 0x18db0
movq (%rdx,%rax,8), %rax
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rbx
movb $0x9, (%rbx)
movb %cl, 0x1(%rbx)
movw $0x183e, 0x2(%rbx)      # imm = 0x183E
movb $0x5, 0x4(%rbx)
movq 0x38(%rsp), %r15
movl $0x5, %r12d
movl $0x1, %esi
movl $0x5, %edx
movq %rbx, %rdi
movq %r15, %rcx
callq 0x1190
cmpq $0x5, %rax
jne 0x47a0
movq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x5(%rbx), %rax
movq %rax, 0x28(%rsp)
xorl %ebp, %ebp
movq %r15, 0x10(%rsp)
movl $0x1, %esi
movl $0x8000, %edx           # imm = 0x8000
movq %r14, %rdi
movq 0x20(%rsp), %rcx
callq 0x1060
movq %rax, %rbx
cmpl $0x6, 0x14ee6(%rip)     # 0x190f4
jge 0x4472
testq %rbx, %rbx
je 0x4464
addq %rbx, %rbp
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x55b1
cmpl $0x2, 0x14ebd(%rip)     # 0x190f4
jl 0x4280
movq 0x14f08(%rip), %r15     # 0x19148
callq 0x1070
subq %r15, %rax
movq 0x10(%rsp), %r15
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %eax, %edx
cmpl $0x96, %edx
ja 0x4497
cmpl $0x4, 0x14e7a(%rip)     # 0x190f4
jge 0x4497
movl $0x8000, %edi           # imm = 0x8000
callq 0x92a2
movq 0x28(%rsp), %rdi
movq %rax, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq *0x30(%rsp)
movq %rax, %r13
movq %rax, %rdi
callq 0x70ca
movl 0x14e47(%rip), %ecx     # 0x190f4
testl %eax, %eax
jne 0x45cd
cmpq $0x1, %r13
je 0x42e2
testq %r13, %r13
jne 0x430b
cmpl $0x6, %ecx
jge 0x44c5
cmpq $0x8000, %rbx           # imm = 0x8000
jne 0x434c
movq 0x8(%rsp), %rdi
movb $0x60, (%rdi)
movl $0x1, %r13d
jmp 0x4360
cmpl $0x6, %ecx
jge 0x44e5
cmpq $0x8000, %rbx           # imm = 0x8000
jne 0x439a
movq 0x8(%rsp), %rdi
movb $-0x60, (%rdi)
movl $0x1, %r13d
jmp 0x43ae
cmpl $0x6, %ecx
jge 0x4505
cmpq $0x8000, %rbx           # imm = 0x8000
jne 0x43d2
movq 0x8(%rsp), %rdi
movb $0x20, 0x2(%rdi)
movl $0x3, %r15d
cmpl $0x7, 0x14dbd(%rip)     # 0x190f4
jl 0x43e6
callq 0x226c
movq 0x8(%rsp), %rdi
jmp 0x43e6
movq 0x8(%rsp), %rdi
movb $0x40, (%rdi)
movb %bh, 0x1(%rdi)
movb %bl, 0x2(%rdi)
movl $0x3, %r13d
movl $0x1, %esi
movq %r13, %rdx
movq %r15, %rcx
callq 0x1190
cmpq %r13, %rax
jne 0x4651
movl $0x1, %esi
movq %r14, %rdi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x1190
cmpq %rbx, %rax
jne 0x4694
addq %rbx, %r13
jmp 0x4419
movq 0x8(%rsp), %rdi
movb $-0x80, (%rdi)
movb %bh, 0x1(%rdi)
movb %bl, 0x2(%rdi)
movl $0x3, %r13d
movb (%r14), %al
movb %al, (%rdi,%r13)
incq %r13
movl $0x1, %esi
movq %r13, %rdx
movq %r15, %rcx
callq 0x1190
cmpq %r13, %rax
je 0x4419
jmp 0x46d7
movq 0x8(%rsp), %rdi
movb $0x0, (%rdi)
movb %bh, 0x1(%rdi)
movb %bl, 0x2(%rdi)
movl $0x5, %r15d
movl %r13d, %eax
rolw $0x8, %ax
movw %ax, 0x3(%rdi)
subq %r15, %rdi
addq $0x5, %rdi
addq %r15, %r13
movl $0x1, %esi
movq %r13, %rdx
movq 0x10(%rsp), %r15
movq %r15, %rcx
callq 0x1190
cmpq %r13, %rax
jne 0x460e
addq %r13, %r12
cmpl $0x2, 0x14cd1(%rip)     # 0x190f4
jl 0x4464
movq 0x14d1c(%rip), %r15     # 0x19148
callq 0x1070
subq %r15, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x7, %rdx
addl %eax, %edx
cmpl $0x96, %edx
ja 0x44a4
cmpl $0x4, 0x14c97(%rip)     # 0x190f4
jge 0x44a4
movq 0x10(%rsp), %r15
testq %rbx, %rbx
jne 0x41ed
jmp 0x4528
movq 0x14b7f(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
leaq 0xe505(%rip), %rsi      # 0x12988
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x1110
jmp 0x4214
movq %rbp, %rdi
callq 0x2114
jmp 0x4280
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x48(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq 0x22d0
movq 0x48(%rsp), %r12
movq 0x50(%rsp), %rbp
jmp 0x445f
movq 0x14b2c(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
leaq 0xe4fe(%rip), %rsi      # 0x129d4
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1110
jmp 0x42c9
movq 0x14b0c(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
leaq 0xe551(%rip), %rsi      # 0x12a47
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1110
jmp 0x42eb
movq 0x14aec(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
leaq 0xe577(%rip), %rsi      # 0x12a8d
movq %rbx, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x1110
jmp 0x4314
leaq 0x58(%rsp), %rdi
callq 0x5740
movl %eax, %ecx
shrl $0x5, %ecx
movq 0x8(%rsp), %rdi
movb %cl, 0x2(%rdi)
movl %eax, %ecx
shrl $0xd, %ecx
movb %cl, 0x1(%rdi)
shrl $0x15, %eax
orb $-0x40, %al
movb %al, (%rdi)
movl $0x1, %esi
movl $0x3, %edx
movq %r15, %rcx
callq 0x1190
cmpq $0x3, %rax
jne 0x47e3
cmpl $0x2, 0x14b83(%rip)     # 0x190f4
jge 0x45b9
addq $0x3, %r12
cmpl $0x2, 0x14b76(%rip)     # 0x190f4
jge 0x45c0
movq %r14, %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
movq 0x20(%rsp), %rdi
callq 0x1080
movq %r15, %rdi
callq 0x1080
movq %r12, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x23af
jmp 0x4573
movq %r12, %rdi
movq %rbp, %rsi
callq 0x23d4
jmp 0x4580
testl %ecx, %ecx
jle 0x45d6
callq 0x215c
cmpl $0x0, 0x14b17(%rip)     # 0x190f4
jle 0x45e7
movq %r13, %rdi
callq 0x217d
cmpl $0x0, 0x14b06(%rip)     # 0x190f4
jle 0x4604
movq 0x14a01(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10d0
movl $0x17, %edi
callq 0x1180
cmpl $0x0, 0x14adf(%rip)     # 0x190f4
jle 0x461c
callq 0x228d
cmpl $0x0, 0x14ad1(%rip)     # 0x190f4
jle 0x462a
callq 0x22ae
cmpl $0x0, 0x14ac3(%rip)     # 0x190f4
jle 0x4647
movq 0x149be(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10d0
movl $0x1b, %edi
callq 0x1180
cmpl $0x0, 0x14a9c(%rip)     # 0x190f4
jle 0x465f
callq 0x21e6
cmpl $0x0, 0x14a8e(%rip)     # 0x190f4
jle 0x466d
callq 0x2207
cmpl $0x0, 0x14a80(%rip)     # 0x190f4
jle 0x468a
movq 0x1497b(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10d0
movl $0x18, %edi
callq 0x1180
cmpl $0x0, 0x14a59(%rip)     # 0x190f4
jle 0x46a2
callq 0x2229
cmpl $0x0, 0x14a4b(%rip)     # 0x190f4
jle 0x46b0
callq 0x224a
cmpl $0x0, 0x14a3d(%rip)     # 0x190f4
jle 0x46cd
movq 0x14938(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10d0
movl $0x19, %edi
callq 0x1180
cmpl $0x0, 0x14a16(%rip)     # 0x190f4
jle 0x46e5
callq 0x21a3
cmpl $0x0, 0x14a08(%rip)     # 0x190f4
jle 0x46f3
callq 0x21c4
cmpl $0x0, 0x149fa(%rip)     # 0x190f4
jle 0x4710
movq 0x148f5(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10d0
movl $0x1a, %edi
callq 0x1180
cmpl $0x0, 0x149d3(%rip)     # 0x190f4
jle 0x4728
callq 0x2057
cmpl $0x0, 0x149c5(%rip)     # 0x190f4
jle 0x4736
callq 0x2072
cmpl $0x0, 0x149b7(%rip)     # 0x190f4
jle 0x4753
movq 0x148b2(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10d0
movl $0x15, %edi
callq 0x1180
cmpl $0x0, 0x14990(%rip)     # 0x190f4
jle 0x476b
callq 0x208e
cmpl $0x0, 0x14982(%rip)     # 0x190f4
jle 0x4779
callq 0x20af
cmpl $0x0, 0x14974(%rip)     # 0x190f4
jle 0x4796
movq 0x1486f(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10d0
movl $0x14, %edi
callq 0x1180
cmpl $0x0, 0x1494d(%rip)     # 0x190f4
jle 0x47ae
callq 0x20d1
cmpl $0x0, 0x1493f(%rip)     # 0x190f4
jle 0x47bc
callq 0x20f2
cmpl $0x0, 0x14931(%rip)     # 0x190f4
jle 0x47d9
movq 0x1482c(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10d0
movl $0x16, %edi
callq 0x1180
cmpl $0x0, 0x1490a(%rip)     # 0x190f4
jle 0x47f1
callq 0x236c
cmpl $0x0, 0x148fc(%rip)     # 0x190f4
jle 0x47ff
callq 0x238d
cmpl $0x0, 0x148ee(%rip)     # 0x190f4
jle 0x481c
movq 0x147e9(%rip), %rax     # 0x18ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10d0
movl $0x1c, %edi
callq 0x1180