// File: /workspace/github_c_makefile_star2_O2/Cyan4973[P]FiniteStateEntropy/programs/commandline.c
// Function: main
int main(int argc, const char** argv)
{
    int   i,
          forceCompress = 1,  /* default action if no argument */
          decode= 0,
          bench = 0;
    int   indexFileNames = 0;
    const char* input_filename = NULL;
    const char* output_filename= NULL;
    char*  tmpFilenameBuffer   = NULL;
    size_t tmpFilenameSize     = 0;
    const char extension[] = FSE_EXTENSION;
    const char* const programName = argv[0];
    FIO_compressor_t compressor = FIO_fse;

    DISPLAY(WELCOME_MESSAGE);
    if (argc<2) badusage(programName);

    for(i = 1; i <= argc; i++) {
        const char* argument = argv[i];

        if(!argument) continue;   /* Protection if argument empty */

        // Decode command (note : aggregated commands are allowed)
        if (argument[0]=='-') {
            // '-' means stdin/stdout
            if (argument[1]==0) {
                if (!input_filename) input_filename=stdinmark;
                else output_filename=stdoutmark;
            }

            while (argument[1]!=0) {
                argument ++;

                switch(argument[0])
                {
                    // Display help
                case 'V': DISPLAY(WELCOME_MESSAGE); return 0;   // Version
                case 'H': usage(programName); return 0;

                    // Decoding
                case 'd': decode=1; bench=0; break;

                    // Benchmark full mode
                case 'b': bench=1; break;

                    // FSE selection (default)
                case 'e':
                    BMK_SetByteCompressor(1);
                    compressor = FIO_fse;
                    break;

                    // HUF selection
                case 'h':
                    BMK_SetByteCompressor(2);
                    compressor = FIO_huf;
                    break;

                    // zlib mode
                case 'z':
                    BMK_SetByteCompressor(3);
                    compressor = FIO_zlibh;
                    break;

                    // Test
                case 't': decode=1; output_filename=nulmark; break;

                    // Overwrite
                case 'f': FIO_overwriteMode(); break;

                    // Verbose mode
                case 'v': displayLevel++; break;

                    // Quiet mode
                case 'q': displayLevel--; break;

                    // keep source file (default anyway, so useless) (for xz/lzma compatibility)
                case 'k': break;

                    // Modify Block Properties
                case 'B':
                    {   unsigned bSize = 0;
                        while ((argument[1] >='0') && (argument[1] <='9'))
                        {
                            unsigned digit = argument[1] - '0';
                            bSize *= 10;
                            bSize += digit;
                            argument++;
                        }
                        if (argument[1]=='K') bSize<<=10, argument++;  /* allows using KB notation */
                        if (argument[1]=='M') bSize<<=20, argument++;
                        if (argument[1]=='B') argument++;
                        BMK_SetBlocksize(bSize);
                    }
                    break;

                    // Modify Stream properties
                case 'S': break;   // to be completed later

                    // Modify Nb Iterations (benchmark only)
                case 'i':
                    if ((argument[1] >='1') && (argument[1] <='9')) {
                        int iters = argument[1] - '0';
                        BMK_SetNbIterations(iters);
                        argument++;
                    }
                    break;

                    // Pause at the end (hidden option)
                case 'p': fse_pause=1; break;

                    /* Change FSE tableLog size (hidden option) */
                case 'M':
                    if ((argument[1] >='1') && (argument[1] <='9')) {
                        int tableLog = argument[1] - '0';
                        BMK_SetTableLog(tableLog);
                        argument++;
                    }
                    break;

                    /* Unrecognised command */
                default : badusage(programName);
                }
            }
            continue;
        }

        /* first provided filename is input */
        if (!input_filename) { input_filename=argument; indexFileNames=i; continue; }

        /* second provided filename is output */
        if (!output_filename) { output_filename=argument; continue; }
    }

    /* No input filename ==> use stdin */
    if(!input_filename) { input_filename=stdinmark; }

    /* Check if input is defined as console; trigger an error in this case */
    if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) ) badusage(programName);

    /* Check if benchmark is selected */
    if (bench==1) { BMK_benchFiles(argv+indexFileNames, argc-indexFileNames); goto _end; }
    if (bench==3) { BMK_benchCore_Files(argv+indexFileNames, argc-indexFileNames); goto _end; }   /* no longer possible */

    /* No output filename ==> try to select one automatically (when possible) */
    while (!output_filename) {
        if (!IS_CONSOLE(stdout)) { output_filename=stdoutmark; break; }   // Default to stdout whenever possible (i.e. not a console)
        if ((!decode) && !(forceCompress)) {   // auto-determine compression or decompression, based on file extension
            size_t const l = strlen(input_filename);
            if (!strcmp(input_filename+(l-4), FSE_EXTENSION)) decode=1;
        }
        if (!decode) {   /* compression to file */
            size_t const l = strlen(input_filename);
            if (tmpFilenameSize < l+6) tmpFilenameSize = l+6;
            tmpFilenameBuffer = (char*)calloc(1,tmpFilenameSize);
            if (tmpFilenameBuffer==NULL) {
                DISPLAY("Not enough memory, exiting ... \n");
                exit(1);
            }
            strcpy(tmpFilenameBuffer, input_filename);
            strcpy(tmpFilenameBuffer+l, FSE_EXTENSION);
            output_filename = tmpFilenameBuffer;
            DISPLAYLEVEL(2, "Compressed filename will be : %s \n", output_filename);
            break;
        }
        /* decompression to file (automatic name will work only if input filename has correct format extension) */
        {   size_t outl;
            size_t const inl = strlen(input_filename);
            if (tmpFilenameSize < inl+2) tmpFilenameSize = inl+2;
            tmpFilenameBuffer = (char*)calloc(1,tmpFilenameSize);
            strcpy(tmpFilenameBuffer, input_filename);
            outl = inl;
            if (inl>4)
                while ((outl >= inl-4) && (input_filename[outl] ==  extension[outl-inl+4])) tmpFilenameBuffer[outl--]=0;
            if (outl != inl-5) { DISPLAYLEVEL(1, "Cannot determine an output filename\n"); badusage(programName); }
            output_filename = tmpFilenameBuffer;
            DISPLAYLEVEL(2, "Decoding into filename : %s \n", output_filename);
        }
    }   /* (!output_filename) */

    /* No warning message in pure pipe mode (stdin + stdout) */
    if (!strcmp(input_filename, stdinmark) && !strcmp(output_filename,stdoutmark) && (displayLevel==2)) displayLevel=1;

    /* Check if input or output are defined as console; trigger an error in this case */
    if (!strcmp(input_filename, stdinmark)  && IS_CONSOLE(stdin) ) badusage(programName);
    if (!strcmp(output_filename,stdoutmark) && IS_CONSOLE(stdout)) badusage(programName);

    FIO_setDisplayLevel(displayLevel);
    if (decode) FIO_decompressFilename(output_filename, input_filename);
    else {
        FIO_setCompressor(compressor);
        FIO_compressFilename(output_filename, input_filename);
    }

_end:
    if (fse_pause) waitEnter();
    free(tmpFilenameBuffer);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edi, %ebx
movq %rsi, 0x20(%rsp)
movq (%rsi), %rax
movq %rax, 0x8(%rsp)
movq 0x13400(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
leaq 0xca7b(%rip), %rsi      # 0xf67d
leaq 0xca91(%rip), %rdx      # 0xf69a
leaq 0xcaa5(%rip), %r8       # 0xf6b5
leaq 0xcaaa(%rip), %r9       # 0xf6c1
movq $0x0, 0x18(%rsp)
pushq $0x40
popq %rcx
xorl %eax, %eax
callq 0x1110
cmpl $0x2, %ebx
jl 0x31bc
movq %rbx, 0x30(%rsp)
leal 0x1(%rbx), %eax
movq %rax, 0x40(%rsp)
pushq $0x1
popq %rdx
leaq 0xca2c(%rip), %rcx      # 0xf676
leaq 0xc9bb(%rip), %r15      # 0xf60c
pushq $0x1
popq %rbx
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x0, 0x14(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x20(%rsp), %rax
cmpq 0x40(%rsp), %rdx
je 0x2e7d
movq %rdx, 0x28(%rsp)
movq (%rax,%rdx,8), %rbp
testq %rbp, %rbp
je 0x2e20
cmpb $0x2d, (%rbp)
jne 0x2e14
movb 0x1(%rbp), %al
testq %rdi, %rdi
cmoveq %r14, %rcx
movq %rdi, %rsi
leaq 0xc9c9(%rip), %rdx      # 0xf670
cmoveq %rdx, %rsi
testb %al, %al
cmoveq %rcx, %r14
movq %r14, (%rsp)
cmovneq %rdi, %rsi
movq %rsi, 0x38(%rsp)
leaq 0x1(%rbp), %r14
movzbl %al, %eax
leal -0x62(%rax), %ecx
cmpl $0x18, %ecx
ja 0x2cde
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
movl %ebx, %r12d
jmp 0x2e08
cmpl $0x42, %eax
je 0x2d94
cmpl $0x4d, %eax
je 0x2dec
cmpl $0x53, %eax
je 0x2e08
jmp 0x2e25
leaq 0xc9c8(%rip), %rax      # 0xf6cd
movq %rax, (%rsp)
jmp 0x2d70
movb 0x2(%rbp), %al
leal -0x31(%rax), %ecx
cmpb $0x8, %cl
ja 0x2e08
addq $0x2, %rbp
addb $-0x30, %al
movzbl %al, %edi
callq 0x12d0
jmp 0x2e05
pushq $0x2
popq %rdi
callq 0x129c
movl %ebx, %eax
jmp 0x2d44
pushq $0x3
popq %rdi
callq 0x129c
pushq $0x2
popq %rax
movq %rax, 0x18(%rsp)
jmp 0x2e08
callq 0x3344
jmp 0x2e08
movl %ebx, %edi
callq 0x129c
movq $0x0, 0x18(%rsp)
jmp 0x2e08
xorl %r12d, %r12d
movl %ebx, %r13d
jmp 0x2e08
decl 0x13372(%rip)           # 0x160f0
jmp 0x2e08
movb $0x1, 0x133b2(%rip)     # 0x1613c
jmp 0x2e08
incl 0x1335e(%rip)           # 0x160f0
jmp 0x2e08
addq $0x2, %rbp
xorl %eax, %eax
movb (%rbp), %cl
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x2db2
movzbl %dl, %ecx
imull $0xa, %eax, %eax
addl %ecx, %eax
incq %rbp
jmp 0x2d9a
movl %eax, %edx
shll $0xa, %edx
leaq -0x1(%rbp), %rsi
cmpb $0x4b, %cl
cmoveq %rbp, %rsi
cmovnel %eax, %edx
leaq 0x1(%rsi), %rax
movl %edx, %edi
shll $0x14, %edi
cmpb $0x4d, 0x1(%rsi)
cmovneq %rsi, %rax
cmovnel %edx, %edi
leaq 0x1(%rax), %r14
cmpb $0x42, 0x1(%rax)
cmovneq %rax, %r14
callq 0x12a3
jmp 0x2e08
movb 0x2(%rbp), %al
leal -0x31(%rax), %ecx
cmpb $0x8, %cl
ja 0x2e08
addq $0x2, %rbp
addb $-0x30, %al
movzbl %al, %edi
callq 0x12c6
movq %rbp, %r14
movb 0x1(%r14), %al
movq %r14, %rbp
jmp 0x2cbe
testq %rdi, %rdi
je 0x2e40
testq %r14, %r14
cmoveq %rbp, %r14
movq %rdi, %rbp
jmp 0x2e49
testl %eax, %eax
jne 0x2e59
movq 0x38(%rsp), %rbp
movq (%rsp), %r14
leaq 0xc83d(%rip), %rcx      # 0xf676
movq 0x20(%rsp), %rax
jmp 0x2e49
movq 0x28(%rsp), %rdx
movl %edx, 0x14(%rsp)
movq 0x28(%rsp), %rdx
incq %rdx
movq %rbp, %rdi
jmp 0x2c6c
cmpl $0x48, %eax
jne 0x2fd4
movq 0x8(%rsp), %rdi
callq 0x322c
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rdi, %rdi
leaq 0xc7e9(%rip), %rsi      # 0xf670
cmoveq %rsi, %rdi
movq %rdi, (%rsp)
callq 0x10f0
testl %eax, %eax
jne 0x2eb6
movq 0x13139(%rip), %rax     # 0x15fd8
movq (%rax), %rdi
callq 0x1140
movl %eax, %edi
callq 0x1050
testl %eax, %eax
jne 0x31bc
cmpl $0x1, %r12d
jne 0x2edd
movslq 0x14(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
movq 0x30(%rsp), %rsi
subl %eax, %esi
callq 0x1f59
xorl %ebx, %ebx
jmp 0x313e
testl %r13d, %r13d
sete %r13b
xorl %ebx, %ebx
movq %r14, %rax
leaq 0xc7e7(%rip), %r14      # 0xf6d7
xorl %r12d, %r12d
movq (%rsp), %rbp
testq %rax, %rax
jne 0x3012
movq 0x130c9(%rip), %rax     # 0x15fd0
movq (%rax), %rdi
callq 0x1140
movl %eax, %edi
callq 0x1050
testl %eax, %eax
je 0x3017
movq %rbp, %rdi
callq 0x1090
movq %rax, %r15
testb $0x1, %r13b
jne 0x3020
leaq 0x2(%r15), %rax
cmpq %rax, %r12
cmovbeq %rax, %r12
pushq $0x1
popq %rdi
movq %r12, %rsi
callq 0x10e0
movq %rax, %rbx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x1040
cmpq $0x5, %r15
jb 0x3197
leaq -0x4(%r15), %rax
movq (%rsp), %rcx
addq %r15, %rcx
movq %rbx, %rdx
addq %r15, %rdx
xorl %esi, %esi
leaq (%r15,%rsi), %rdi
cmpq %rax, %rdi
jb 0x2f91
movb (%rcx,%rsi), %dil
cmpb 0x4(%rsi,%r14), %dil
jne 0x2f91
movb $0x0, (%rdx,%rsi)
decq %rsi
jmp 0x2f74
cmpq $-0x5, %rsi
jne 0x3197
xorl %r13d, %r13d
cmpl $0x2, 0x1314b(%rip)     # 0x160f0
movq %rbx, %rax
jl 0x2ef7
movq 0x13043(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
xorl %r13d, %r13d
leaq 0xc783(%rip), %rsi      # 0xf745
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1110
movq %rbx, %rax
jmp 0x2ef7
cmpl $0x56, %eax
jne 0x31bc
movq 0x13014(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
leaq 0xc68f(%rip), %rsi      # 0xf67d
leaq 0xc6a5(%rip), %rdx      # 0xf69a
leaq 0xc6b9(%rip), %r8       # 0xf6b5
leaq 0xc6be(%rip), %r9       # 0xf6c1
pushq $0x40
popq %rcx
xorl %eax, %eax
callq 0x1110
jmp 0x2e6c
movq %rax, %r14
jmp 0x306c
leaq 0xc658(%rip), %r14      # 0xf676
jmp 0x306c
leaq 0x6(%r15), %rsi
cmpq %rsi, %r12
cmovaq %r12, %rsi
pushq $0x1
popq %rdi
callq 0x10e0
testq %rax, %rax
je 0x31c6
movq %rax, %rbx
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x1040
movl $0x6573662e, (%rbx,%r15) # imm = 0x6573662E
movb $0x0, 0x4(%rbx,%r15)
movb $0x1, %r13b
cmpl $0x2, 0x1308d(%rip)     # 0x160f0
jge 0x3177
movq %rbx, %r14
movq (%rsp), %rdi
leaq 0xc5f9(%rip), %rsi      # 0xf670
callq 0x10f0
testl %eax, %eax
jne 0x30a6
leaq 0xc5ef(%rip), %rsi      # 0xf676
movq %r14, %rdi
callq 0x10f0
testl %eax, %eax
jne 0x30a6
cmpl $0x2, 0x13056(%rip)     # 0x160f0
jne 0x30a6
movl $0x1, 0x1304a(%rip)     # 0x160f0
leaq 0xc5c3(%rip), %rsi      # 0xf670
movq (%rsp), %rdi
callq 0x10f0
testl %eax, %eax
jne 0x30d8
movq 0x12f17(%rip), %rax     # 0x15fd8
movq (%rax), %rdi
callq 0x1140
movl %eax, %edi
callq 0x1050
testl %eax, %eax
jne 0x31bc
leaq 0xc597(%rip), %rsi      # 0xf676
movq %r14, %rdi
callq 0x10f0
testl %eax, %eax
jne 0x3109
movq 0x12ede(%rip), %rax     # 0x15fd0
movq (%rax), %rdi
callq 0x1140
movl %eax, %edi
callq 0x1050
testl %eax, %eax
jne 0x31bc
movl 0x12fe1(%rip), %edi     # 0x160f0
callq 0x3353
testb $0x1, %r13b
je 0x3132
movq 0x18(%rsp), %rdi
callq 0x334c
movq %r14, %rdi
movq (%rsp), %rsi
callq 0x3369
jmp 0x313e
movq %r14, %rdi
movq (%rsp), %rsi
callq 0x3fa2
cmpb $0x1, 0x12ff7(%rip)     # 0x1613c
je 0x3154
movq %rbx, %rdi
callq 0x1030
jmp 0x2e6c
movq 0x12e9d(%rip), %rax     # 0x15ff8
movq (%rax), %rcx
leaq 0xc797(%rip), %rdi      # 0xf8fc
pushq $0x1b
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
callq 0x1100
jmp 0x3147
movq 0x12e7a(%rip), %rax     # 0x15ff8
movq (%rax), %rdi
leaq 0xc575(%rip), %rsi      # 0xf6fd
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1110
jmp 0x3069
cmpl $0x0, 0x12f52(%rip)     # 0x160f0
jle 0x31bc
movq 0x12e51(%rip), %rax     # 0x15ff8
movq (%rax), %rcx
leaq 0xc56f(%rip), %rdi      # 0xf720
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
movq 0x8(%rsp), %rdi
callq 0x31ea
movq 0x12e2b(%rip), %rax     # 0x15ff8
movq (%rax), %rcx
leaq 0xc505(%rip), %rdi      # 0xf6dc
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
pushq $0x1
popq %rdi
callq 0x1180