// File: yangwanyuan[P]HLKVDS/tools/Benchmark.cc
// Function: Parse_Option(int, char**, benchmark_arg&)
int Parse_Option(int argc, char** argv, benchmark_arg &bm_arg) {
    if (argc != 18) {
        cout << "Please Input all the parameters!" << endl;
        return -1;
    }

    if (!strcmp(argv[1], "write")) {
        bm_arg.bench_type = Benchmark_Type::WRITE;
    }
    else if (!strcmp(argv[1], "overwrite")) {
        bm_arg.bench_type = Benchmark_Type::OVERWRITE;
    }
    else if (!strcmp(argv[1], "read")) {
        bm_arg.bench_type = Benchmark_Type::READ;
    }
    else if (!strcmp(argv[1], "create")) {
        bm_arg.bench_type = Benchmark_Type::CREATE;
    }
    else {
        cout << "Please Input Correct benchmarks !" << endl;
        return -1;
    }

    string str_f = "-f";
    string str_s = "-s";
    string str_n = "-n";
    string str_t = "-t";
    string str_seg = "-seg";
    string str_shards = "-shards";
    string str_type = "-dstype";
    string str_aggregate = "-aggregate";

    if (strcmp(argv[2], str_f.c_str()) !=0 || \
        strcmp(argv[4], str_s.c_str()) != 0 || \
        strcmp(argv[6], str_n.c_str()) != 0 || \
        strcmp(argv[8], str_t.c_str()) != 0 || \
        strcmp(argv[10], str_seg.c_str()) != 0 || \
        strcmp(argv[12], str_shards.c_str()) != 0 || \
        strcmp(argv[14], str_type.c_str()) != 0 || \
        strcmp(argv[16], str_aggregate.c_str()) != 0) {
        cout << "Please Input Correct parameter!" << endl;
        return -1;
    }

    bm_arg.file_path = argv[3];
    bm_arg.db_size = atoi(argv[5]);
    bm_arg.record_num = atoi(argv[7]);
    bm_arg.thread_num = atoi(argv[9]);
    bm_arg.segment_K = atoi(argv[11]);
    bm_arg.shards_num = atoi(argv[13]);
    bm_arg.ds_type = atoi(argv[15]);
    bm_arg.aggregate = atoi(argv[17]);
    
    if (bm_arg.db_size < 0 ||  bm_arg.record_num < 0 || \
        bm_arg.thread_num < 0 || bm_arg.segment_K < 0 || \
        bm_arg.shards_num < 1) {
        cout << "Parametes error, Please Input Positive Integer!" << endl;
        return -1;
    }

    return 0;
}

// Assembly:
subq $0x1f8, %rsp            # imm = 0x1F8
movl %edi, 0x1f0(%rsp)
movq %rsi, 0x1e8(%rsp)
movq %rdx, 0x1e0(%rsp)
cmpl $0x12, 0x1f0(%rsp)
je 0xae4a
movq 0x6d1b1(%rip), %rdi     # 0x77fd0
leaq 0x4c554(%rip), %rsi     # 0x5737a
callq 0x8520
movq %rax, %rdi
movq 0x6d16b(%rip), %rsi     # 0x77fa0
callq 0x8560
movl $0xffffffff, 0x1f4(%rsp) # imm = 0xFFFFFFFF
jmp 0xb6ab
movq 0x1e8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4c542(%rip), %rsi     # 0x5739f
callq 0x86f0
cmpl $0x0, %eax
jne 0xae7b
movq 0x1e0(%rsp), %rax
movl $0x0, 0x3c(%rax)
jmp 0xaf40
movq 0x1e8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4c50d(%rip), %rsi     # 0x5739b
callq 0x86f0
cmpl $0x0, %eax
jne 0xaeac
movq 0x1e0(%rsp), %rax
movl $0x1, 0x3c(%rax)
jmp 0xaf3e
movq 0x1e8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4c4e6(%rip), %rsi     # 0x573a5
callq 0x86f0
cmpl $0x0, %eax
jne 0xaeda
movq 0x1e0(%rsp), %rax
movl $0x2, 0x3c(%rax)
jmp 0xaf3c
movq 0x1e8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4c4bd(%rip), %rsi     # 0x573aa
callq 0x86f0
cmpl $0x0, %eax
jne 0xaf08
movq 0x1e0(%rsp), %rax
movl $0x3, 0x3c(%rax)
jmp 0xaf3a
movq 0x6d0c1(%rip), %rdi     # 0x77fd0
leaq 0x4c49b(%rip), %rsi     # 0x573b1
callq 0x8520
movq %rax, %rdi
movq 0x6d07b(%rip), %rsi     # 0x77fa0
callq 0x8560
movl $0xffffffff, 0x1f4(%rsp) # imm = 0xFFFFFFFF
jmp 0xb6ab
jmp 0xaf3c
jmp 0xaf3e
jmp 0xaf40
leaq 0x1bf(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x8890
movq 0x88(%rsp), %rdx
leaq 0x4c46f(%rip), %rsi     # 0x573d3
leaq 0x1c0(%rsp), %rdi
callq 0x86c0
jmp 0xaf73
leaq 0x1bf(%rsp), %rdi
callq 0x8580
leaq 0x187(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x8890
movq 0x80(%rsp), %rdx
leaq 0x4c432(%rip), %rsi     # 0x573d6
leaq 0x188(%rsp), %rdi
callq 0x86c0
jmp 0xafb3
leaq 0x187(%rsp), %rdi
callq 0x8580
leaq 0x15f(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x8890
movq 0x78(%rsp), %rdx
leaq 0x4c3fb(%rip), %rsi     # 0x573d9
leaq 0x160(%rsp), %rdi
callq 0x86c0
jmp 0xafed
leaq 0x15f(%rsp), %rdi
callq 0x8580
leaq 0x137(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x8890
movq 0x70(%rsp), %rdx
leaq 0x4c3c4(%rip), %rsi     # 0x573dc
leaq 0x138(%rsp), %rdi
callq 0x86c0
jmp 0xb027
leaq 0x137(%rsp), %rdi
callq 0x8580
leaq 0x10f(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x8890
movq 0x68(%rsp), %rdx
leaq 0x4c38d(%rip), %rsi     # 0x573df
leaq 0x110(%rsp), %rdi
callq 0x86c0
jmp 0xb061
leaq 0x10f(%rsp), %rdi
callq 0x8580
leaq 0xe7(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x8890
movq 0x60(%rsp), %rdx
leaq 0x4c358(%rip), %rsi     # 0x573e4
leaq 0xe8(%rsp), %rdi
callq 0x86c0
jmp 0xb09b
leaq 0xe7(%rsp), %rdi
callq 0x8580
leaq 0xbf(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x8890
movq 0x58(%rsp), %rdx
leaq 0x4c326(%rip), %rsi     # 0x573ec
leaq 0xc0(%rsp), %rdi
callq 0x86c0
jmp 0xb0d5
leaq 0xbf(%rsp), %rdi
callq 0x8580
leaq 0x97(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x8890
movq 0x50(%rsp), %rdx
leaq 0x4c2f4(%rip), %rsi     # 0x573f4
leaq 0x98(%rsp), %rdi
callq 0x86c0
jmp 0xb10f
leaq 0x97(%rsp), %rdi
callq 0x8580
movq 0x1e8(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x48(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x8190
movq 0x48(%rsp), %rdi
movq %rax, %rsi
callq 0x86f0
cmpl $0x0, %eax
jne 0xb2b7
movq 0x1e8(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x40(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x8190
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x86f0
cmpl $0x0, %eax
jne 0xb2b7
movq 0x1e8(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x8190
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x86f0
cmpl $0x0, %eax
jne 0xb2b7
movq 0x1e8(%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, 0x30(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x8190
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x86f0
cmpl $0x0, %eax
jne 0xb2b7
movq 0x1e8(%rsp), %rax
movq 0x50(%rax), %rax
movq %rax, 0x28(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x8190
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x86f0
cmpl $0x0, %eax
jne 0xb2b7
movq 0x1e8(%rsp), %rax
movq 0x60(%rax), %rax
movq %rax, 0x20(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x8190
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x86f0
cmpl $0x0, %eax
jne 0xb2b7
movq 0x1e8(%rsp), %rax
movq 0x70(%rax), %rax
movq %rax, 0x18(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x8190
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x86f0
cmpl $0x0, %eax
jne 0xb2b7
movq 0x1e8(%rsp), %rax
movq 0x80(%rax), %rax
movq %rax, 0x10(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x8190
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x86f0
cmpl $0x0, %eax
je 0xb455
movq 0x6cd12(%rip), %rdi     # 0x77fd0
leaq 0x4c13a(%rip), %rsi     # 0x573ff
callq 0x8520
movq %rax, 0x8(%rsp)
jmp 0xb2d1
movq 0x8(%rsp), %rdi
movq 0x6ccc3(%rip), %rsi     # 0x77fa0
callq 0x8560
jmp 0xb2e4
movl $0xffffffff, 0x1f4(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x90(%rsp)
jmp 0xb5e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0x1bf(%rsp), %rdi
callq 0x8580
jmp 0xb6ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0x187(%rsp), %rdi
callq 0x8580
jmp 0xb69c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0x15f(%rsp), %rdi
callq 0x8580
jmp 0xb68f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0x137(%rsp), %rdi
callq 0x8580
jmp 0xb682
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0x10f(%rsp), %rdi
callq 0x8580
jmp 0xb675
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0xe7(%rsp), %rdi
callq 0x8580
jmp 0xb668
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0xbf(%rsp), %rdi
callq 0x8580
jmp 0xb65b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0x97(%rsp), %rdi
callq 0x8580
jmp 0xb64e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b0(%rsp)
movl %eax, 0x1ac(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x8998
jmp 0xb64e
movq 0x1e8(%rsp), %rax
movq 0x18(%rax), %rsi
movq 0x1e0(%rsp), %rdi
callq 0x86b0
jmp 0xb470
movq 0x1e8(%rsp), %rax
movq 0x28(%rax), %rdi
callq 0x87b0
movl %eax, %ecx
movq 0x1e0(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x1e8(%rsp), %rax
movq 0x38(%rax), %rdi
callq 0x87b0
movl %eax, %ecx
movq 0x1e0(%rsp), %rax
movl %ecx, 0x24(%rax)
movq 0x1e8(%rsp), %rax
movq 0x48(%rax), %rdi
callq 0x87b0
movl %eax, %ecx
movq 0x1e0(%rsp), %rax
movl %ecx, 0x28(%rax)
movq 0x1e8(%rsp), %rax
movq 0x58(%rax), %rdi
callq 0x87b0
movl %eax, %ecx
movq 0x1e0(%rsp), %rax
movl %ecx, 0x2c(%rax)
movq 0x1e8(%rsp), %rax
movq 0x68(%rax), %rdi
callq 0x87b0
movl %eax, %ecx
movq 0x1e0(%rsp), %rax
movl %ecx, 0x30(%rax)
movq 0x1e8(%rsp), %rax
movq 0x78(%rax), %rdi
callq 0x87b0
movl %eax, %ecx
movq 0x1e0(%rsp), %rax
movl %ecx, 0x34(%rax)
movq 0x1e8(%rsp), %rax
movq 0x88(%rax), %rdi
callq 0x87b0
movl %eax, %ecx
movq 0x1e0(%rsp), %rax
movl %ecx, 0x38(%rax)
movq 0x1e0(%rsp), %rax
cmpl $0x0, 0x20(%rax)
jl 0xb58b
movq 0x1e0(%rsp), %rax
cmpl $0x0, 0x24(%rax)
jl 0xb58b
movq 0x1e0(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jl 0xb58b
movq 0x1e0(%rsp), %rax
cmpl $0x0, 0x2c(%rax)
jl 0xb58b
movq 0x1e0(%rsp), %rax
cmpl $0x1, 0x30(%rax)
jge 0xb5ce
movq 0x6ca3e(%rip), %rdi     # 0x77fd0
leaq 0x4be86(%rip), %rsi     # 0x5741f
callq 0x8520
movq %rax, (%rsp)
jmp 0xb5a4
movq (%rsp), %rdi
movq 0x6c9f1(%rip), %rsi     # 0x77fa0
callq 0x8560
jmp 0xb5b6
movl $0xffffffff, 0x1f4(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x90(%rsp)
jmp 0xb5e4
movl $0x0, 0x1f4(%rsp)
movl $0x1, 0x90(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x8998
leaq 0xc0(%rsp), %rdi
callq 0x8998
leaq 0xe8(%rsp), %rdi
callq 0x8998
leaq 0x110(%rsp), %rdi
callq 0x8998
leaq 0x138(%rsp), %rdi
callq 0x8998
leaq 0x160(%rsp), %rdi
callq 0x8998
leaq 0x188(%rsp), %rdi
callq 0x8998
leaq 0x1c0(%rsp), %rdi
callq 0x8998
jmp 0xb6ab
leaq 0xc0(%rsp), %rdi
callq 0x8998
leaq 0xe8(%rsp), %rdi
callq 0x8998
leaq 0x110(%rsp), %rdi
callq 0x8998
leaq 0x138(%rsp), %rdi
callq 0x8998
leaq 0x160(%rsp), %rdi
callq 0x8998
leaq 0x188(%rsp), %rdi
callq 0x8998
leaq 0x1c0(%rsp), %rdi
callq 0x8998
jmp 0xb6ba
movl 0x1f4(%rsp), %eax
addq $0x1f8, %rsp            # imm = 0x1F8
retq
movq 0x1b0(%rsp), %rdi
callq 0x8880
nopw (%rax,%rax)