// File: /workspace/github_cpp_makefile_star2_O2/adamiaonr[P]rid-analytics/src/run-analysis.cpp
// Function: main
int main (int argc, char **argv) {

    // parse the arguments with an ArgvParser
    ArgvParser * cmds = create_argv_parser();

    // .scn config file path
    char scn_file[MAX_ARRAY_SIZE];
    // dir where all .csv files with output data will be saved
    char data_dir[MAX_ARRAY_SIZE];
    // output file name for this run
    char output_label[MAX_ARRAY_SIZE];
    // // verbose mode (no verbosity by default)
    // bool verbose = false;
    // evaluation parameters
    // request size (also largest possible |F|) in # of URL parameters
    int request_size = 0;       
    // bloom filter size (in bit)
    int bf_size = 0;
    // codes for mode:
    //  - bits 0 and 1 : resolution type:
    //      - 0 (00) : AML forwarding or flood
    //      - 1 (01) : RML forwarding or 'random link'
    //      - 2 (10) : 'hard fallback'
    //      - 3 (11) : 'soft fallback'
    //  - bit 2 : resolution on/off:
    //      - 0 : OFF
    //      - 1 : ON
    //
    // note : if mode is 00 and resolution is on, we 
    //        use feedback resolution (i.e. go back to source, then origin server)
    int mode = 0;
    // origin server location. default is '1'
    char origin_server[MAX_ARRAY_SIZE];
    strncpy(origin_server, "1", MAX_ARRAY_SIZE);
    // start router id. default is '0'
    char start_router[MAX_ARRAY_SIZE];
    strncpy(start_router, "0", MAX_ARRAY_SIZE);

    // parse() takes the arguments to main() and parses them according to 
    // ArgvParser rules
    int result = cmds->parse(argc, argv);

    // if something went wrong: show help option
    if (result != ArgvParser::NoParserError) {

        fprintf(stderr, "%s\n", cmds->parseErrorDescription(result).c_str());

        if (result != ArgvParser::ParserHelpRequested) {
            fprintf(stderr, "use option -h for help.\n");
        }

        delete cmds;
        return -1;

    } else {

        // otherwise, check for the different OPTION_
        if (cmds->foundOption(OPTION_SCN_FILE)) {

            strncpy(scn_file, (char *) cmds->optionValue(OPTION_SCN_FILE).c_str(), MAX_ARRAY_SIZE);
            
        } else {

            fprintf(stderr, "no .scn file path specified. use "\
                "option -h for help.\n");

            delete cmds;
            return -1;
        }

        if (cmds->foundOption(OPTION_DATA_DIR)) {

            strncpy(data_dir, (char *) cmds->optionValue(OPTION_DATA_DIR).c_str(), MAX_ARRAY_SIZE);
        
        } else {

            fprintf(stderr, "no data directory path specified. use "\
                "option -h for help.\n");

            delete cmds;
            return -1;
        }

        if (cmds->foundOption(OPTION_OUTPUT_LABEL)) {

            strncpy(output_label, (char *) cmds->optionValue(OPTION_OUTPUT_LABEL).c_str(), MAX_ARRAY_SIZE);

        } else {

            fprintf(stderr, "no output .csv file name specified. use "\
                "option -h for help.\n");

            delete cmds;
            return -1;
        }

        if (cmds->foundOption(OPTION_BF_SIZE)) {

            bf_size = std::stoi(cmds->optionValue(OPTION_BF_SIZE));   
        }

        if (cmds->foundOption(OPTION_REQUEST_SIZE)) {

            request_size = std::stoi(cmds->optionValue(OPTION_REQUEST_SIZE));
        }

        if (cmds->foundOption(OPTION_MM_MODE)) {

            mode = std::stoi(cmds->optionValue(OPTION_MM_MODE));
        }

        // incorrect delivery resolution mode
        if (cmds->foundOption(OPTION_RESOLV_MODE)) {
            int resolv = std::stoi(cmds->optionValue(OPTION_RESOLV_MODE));
            // left-shift the resolv bits by 3 and OR-it to mode
            mode |= (resolv << 2);
        }

        if (cmds->foundOption(OPTION_ORIGIN_SERVER)) {

            strncpy(origin_server, (char *) cmds->optionValue(OPTION_ORIGIN_SERVER).c_str(), MAX_ARRAY_SIZE);
        }

        if (cmds->foundOption(OPTION_START_ROUTER)) {

            strncpy(start_router, (char *) cmds->optionValue(OPTION_START_ROUTER).c_str(), MAX_ARRAY_SIZE);
        }

        // if (cmds->foundOption(OPTION_VERBOSE)) {
        //     verbose = true;
        // }
    }

    printf("rid-analytics : request_size = %d, bf_size = %d\n", request_size, bf_size);

    if (result == ArgvParser::ParserHelpRequested) {

        delete cmds;
        return -1;
    }

    // create an rid model environment (according to the specs on nw_filename)
    RID_Analytics * rid_analytics_env = 
        new RID_Analytics(
            std::string(scn_file),          // .scn file w/ topology info
            request_size, bf_size,          // parameters for FP rate calculation
            std::string(origin_server),     // origin server location: useful for latency
            mode,                           // how to handle (1) multiple matches; and (2) wrong deliveries
            std::string(data_dir), std::string(output_label));

    // ... and run the model
    rid_analytics_env->run(std::string(scn_file), std::string(start_router));
    printf("rid-analytics : output dir = %s, output label = %s\n", data_dir, output_label);

    // clean up after yourself...
    delete rid_analytics_env;
    delete cmds;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x618, %rsp            # imm = 0x618
movq %rsi, %r14
movl %edi, %ebp
callq 0x15f68
movq %rax, %rbx
leaq 0x12c29(%rip), %rsi     # 0x29002
leaq 0x210(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x4230
leaq 0x10e7c(%rip), %rsi     # 0x2726e
leaq 0x110(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x4230
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x1b01c
testl %eax, %eax
jne 0x16a8a
leaq 0x13e24(%rip), %rsi     # 0x2a244
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1af68
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x41c0
testb %bpl, %bpl
je 0x16aeb
leaq 0x13dec(%rip), %rsi     # 0x2a244
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
callq 0x1afa4
leaq 0x8(%rsp), %r14
movq (%r14), %rsi
leaq 0x510(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x4230
movq %r14, %rdi
callq 0x41c0
leaq 0x28(%rsp), %rdi
callq 0x41c0
leaq 0x13dd3(%rip), %rsi     # 0x2a27f
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1af68
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x41c0
testb %bpl, %bpl
je 0x16b00
leaq 0x13d9b(%rip), %rsi     # 0x2a27f
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
callq 0x1afa4
leaq 0x8(%rsp), %r14
movq (%r14), %rsi
leaq 0x410(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x4230
movq %r14, %rdi
callq 0x41c0
leaq 0x28(%rsp), %rdi
callq 0x41c0
leaq 0x13d89(%rip), %rsi     # 0x2a2c1
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1af68
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x41c0
testb %bpl, %bpl
je 0x16b15
leaq 0x13d51(%rip), %rsi     # 0x2a2c1
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
callq 0x1afa4
leaq 0x8(%rsp), %r14
movq (%r14), %rsi
leaq 0x310(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x4230
movq %r14, %rdi
callq 0x41c0
leaq 0x28(%rsp), %rdi
callq 0x41c0
leaq 0x13d4c(%rip), %rsi     # 0x2a310
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1af68
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x41c0
movl $0x0, 0x48(%rsp)
testb %bpl, %bpl
je 0x16648
leaq 0x13d10(%rip), %rsi     # 0x2a310
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
callq 0x1afa4
leaq 0x8(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x16ca1
movl %eax, 0x48(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x41c0
leaq 0x28(%rsp), %rdi
callq 0x41c0
leaq 0x13ce8(%rip), %rsi     # 0x2a337
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1af68
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x41c0
xorl %r14d, %r14d
testb %bpl, %bpl
je 0x166cd
leaq 0x13cb1(%rip), %rsi     # 0x2a337
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
callq 0x1afa4
leaq 0x8(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x16ca1
movl %eax, %r14d
leaq 0x8(%rsp), %rdi
callq 0x41c0
leaq 0x28(%rsp), %rdi
callq 0x41c0
leaq 0x13c98(%rip), %rsi     # 0x2a36c
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1af68
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x41c0
xorl %r15d, %r15d
testb %bpl, %bpl
je 0x16752
leaq 0x13c61(%rip), %rsi     # 0x2a36c
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
callq 0x1afa4
leaq 0x8(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x16ca1
movl %eax, %r15d
leaq 0x8(%rsp), %rdi
callq 0x41c0
leaq 0x28(%rsp), %rdi
callq 0x41c0
leaq 0x13c9e(%rip), %rsi     # 0x2a3f7
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1af68
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x41c0
testb %bpl, %bpl
je 0x167d9
leaq 0x13c6a(%rip), %rsi     # 0x2a3f7
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
callq 0x1afa4
leaq 0x8(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x16ca1
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x41c0
leaq 0x28(%rsp), %rdi
callq 0x41c0
shll $0x2, %ebp
orl %ebp, %r15d
leaq 0x13c80(%rip), %rsi     # 0x2a460
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1af68
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x41c0
testb %bpl, %bpl
je 0x16862
leaq 0x13c4c(%rip), %rsi     # 0x2a460
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
callq 0x1afa4
leaq 0x8(%rsp), %r12
movq (%r12), %rsi
leaq 0x210(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x4230
movq %r12, %rdi
callq 0x41c0
leaq 0x28(%rsp), %rdi
callq 0x41c0
leaq 0x13c2a(%rip), %rsi     # 0x2a493
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1af68
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x41c0
testb %bpl, %bpl
je 0x168eb
leaq 0x13bf6(%rip), %rsi     # 0x2a493
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x16c66
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
callq 0x1afa4
leaq 0x8(%rsp), %r12
movq (%r12), %rsi
leaq 0x110(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x4230
movq %r12, %rdi
callq 0x41c0
leaq 0x28(%rsp), %rdi
callq 0x41c0
leaq 0x13c83(%rip), %rdi     # 0x2a575
movl %r14d, %esi
movl 0x48(%rsp), %edx
xorl %eax, %eax
callq 0x4060
movl $0xb0, %edi
callq 0x43c0
movq %rax, %r12
leaq 0xb0(%rsp), %rdi
leaq 0x510(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x16c66
leaq 0x90(%rsp), %rdi
leaq 0x210(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0xf0(%rsp), %r13
leaq 0x410(%rsp), %rsi
leaq 0x7(%rsp), %rdx
movq %r13, %rdi
callq 0x16c66
leaq 0xd0(%rsp), %rbp
leaq 0x310(%rsp), %rsi
leaq 0x4f(%rsp), %rdx
movq %rbp, %rdi
callq 0x16c66
movzbl %r14b, %edx
movzwl 0x48(%rsp), %ecx
leaq 0xb0(%rsp), %rsi
leaq 0x90(%rsp), %r8
movq %r12, %rdi
movl %r15d, %r9d
pushq %rbp
pushq %r13
callq 0x1e164
popq %rax
popq %rcx
leaq 0xd0(%rsp), %rdi
callq 0x41c0
leaq 0xf0(%rsp), %rdi
callq 0x41c0
leaq 0x90(%rsp), %rdi
callq 0x41c0
leaq 0xb0(%rsp), %rdi
callq 0x41c0
leaq 0x70(%rsp), %rdi
leaq 0x510(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x16c66
leaq 0x50(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x16c66
leaq 0x70(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %r12, %rdi
callq 0x213ea
leaq 0x50(%rsp), %rdi
callq 0x41c0
leaq 0x70(%rsp), %rdi
callq 0x41c0
leaq 0x13b73(%rip), %rdi     # 0x2a5a6
xorl %ebp, %ebp
leaq 0x410(%rsp), %rsi
leaq 0x310(%rsp), %rdx
xorl %eax, %eax
callq 0x4060
movq %r12, %rdi
callq 0x1f7dc
movl $0xb0, %esi
movq %r12, %rdi
callq 0x43d0
movq %rbx, %rdi
callq 0x1ae58
movl $0x158, %esi            # imm = 0x158
movq %rbx, %rdi
callq 0x43d0
movl %ebp, %eax
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r14d
movq 0x2452c(%rip), %r13     # 0x3afc0
movq (%r13), %r15
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl %eax, %edx
callq 0x1c1bc
movq (%r12), %rdx
leaq 0x13b21(%rip), %rsi     # 0x2a5d6
movq %r15, %rdi
xorl %eax, %eax
callq 0x4580
movq %r12, %rdi
callq 0x41c0
pushq $-0x1
popq %rbp
cmpl $0x32, %r14d
je 0x16a61
movq (%r13), %rcx
leaq 0x13a81(%rip), %rdi     # 0x2a55c
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
callq 0x4780
jmp 0x16a61
movq 0x244ce(%rip), %rax     # 0x3afc0
movq (%rax), %rcx
leaq 0x139cb(%rip), %rdi     # 0x2a4c7
pushq $0x35
jmp 0x16b28
movq 0x244b9(%rip), %rax     # 0x3afc0
movq (%rax), %rcx
leaq 0x139ec(%rip), %rdi     # 0x2a4fd
pushq $0x3a
jmp 0x16b28
movq 0x244a4(%rip), %rax     # 0x3afc0
movq (%rax), %rcx
leaq 0x13a12(%rip), %rdi     # 0x2a538
pushq $0x3c
popq %rsi
pushq $0x1
popq %rdx
callq 0x4780
pushq $-0x1
popq %rbp
jmp 0x16a61
jmp 0x16c40
jmp 0x16c5b
jmp 0x16c40
jmp 0x16c5b
jmp 0x16b65
jmp 0x16c40
jmp 0x16c5b
jmp 0x16b65
jmp 0x16c40
jmp 0x16c5b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x41c0
jmp 0x16c43
jmp 0x16c40
jmp 0x16c5b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x41c0
jmp 0x16b93
movq %rax, %rbx
jmp 0x16c43
jmp 0x16c5b
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x41c0
jmp 0x16baf
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
jmp 0x16c54
jmp 0x16c5b
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x41c0
jmp 0x16bd3
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x41c0
jmp 0x16be5
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x41c0
jmp 0x16bf7
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x41c0
jmp 0x16c09
movq %rax, %rbx
movl $0xb0, %esi
movq %r12, %rdi
callq 0x43d0
jmp 0x16c5e
jmp 0x16c4c
jmp 0x16c5b
jmp 0x16c4c
jmp 0x16c5b
jmp 0x16c4c
jmp 0x16c5b
jmp 0x16c4c
jmp 0x16c5b
jmp 0x16c4c
jmp 0x16c5b
jmp 0x16c4c
jmp 0x16c5b
jmp 0x16c40
jmp 0x16c5b
jmp 0x16c4c
jmp 0x16c5b
jmp 0x16c40
jmp 0x16c5b
jmp 0x16c4c
jmp 0x16c5b
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x16c54
jmp 0x16c5b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x41c0
jmp 0x16c5e
movq %rax, %rbx
movq %rbx, %rdi
callq 0x4700