// File: /workspace/github_cpp_makefile_star2_O3/yangwanyuan[P]HLKVDS/tools/Benchmark.cc
// Function: Bench_Overwrite(benchmark_arg)
void Bench_Overwrite(benchmark_arg bm_arg) {
    string file_path = bm_arg.file_path;
    int db_size = bm_arg.db_size;
    int record_num =bm_arg.record_num;
    int thread_num = bm_arg.thread_num;
    int segment_K = bm_arg.segment_K;
    int shards_num = bm_arg.shards_num;
    int ds_type = bm_arg.ds_type;
    int aggregate = bm_arg.aggregate;

    vector<string> key_list;
    Create_Keys(record_num, key_list);
    if (Create_DB(file_path, db_size, segment_K, shards_num, ds_type) < 0) {
        cout << "Create DB Fail!!!" <<endl;
        return;
    }

    KVDS *db = Open_DB(file_path, shards_num, aggregate);

    double total_time;
    LatMgr *total_lat_mgr = new LatMgr;
    for (int i = 0; i < OVERWRITE_TIMES; i++) {
        cout << "======================";
        cout << "Insert " << i << " Start!!!";
        cout << "======================" << endl;

        total_time += Bench_Insert(db, record_num, key_list, thread_num, total_lat_mgr);

        cout << "======================";
        cout << "Insert " << i << " Completed!!!";
        cout << "======================" << endl;
    }
    cout << "======================";
    cout << "Finsh All Insert!!!";
    cout << "======================" << endl;

    Lat_Stats lat_stats;
    total_lat_mgr->GetStatistics(lat_stats);

    uint64_t total_record_num = record_num * OVERWRITE_TIMES;
    double iops = total_record_num / total_time;

    uint64_t total_size = (uint64_t)total_record_num * (KEY_SIZE + VALUE_SIZE);
    double throughput = total_size / (total_time * 1024 * 1024);

    uint64_t avg = total_lat_mgr->GetAvg();
    uint64_t min = total_lat_mgr->GetMin();
    uint64_t max = total_lat_mgr->GetMax();

    cout << "Overwrite Bench Finish. Total time: " << total_time << "s" <<endl;
    cout << "Performance Report     :   IOPS = " <<  iops << ", Average Latency = "
            << avg << "us, Throughput = " << throughput << "MB/s." << endl;
    cout << "Latency Report(usec)   :   Min = " << min << ", Max = "
            << max << ", Med = " << lat_stats.med << "." << endl;
    cout << "Latency Statistic(usec):   P50 = " << lat_stats.P_50 << ", P75 = "
            << lat_stats.P_75 << ", P99 = " << lat_stats.P_99 << ", P999 = "
            << lat_stats.P_999 << ", P9999 = " << lat_stats.P_9999 << endl;

    delete total_lat_mgr;
    delete db;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%rdi), %rsi
movq 0x8(%rdi), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0xcb08
movl 0x20(%rbx), %r12d
movl 0x24(%rbx), %ebp
movl 0x28(%rbx), %eax
movl %eax, 0x14(%rsp)
movl 0x2c(%rbx), %r13d
movl 0x30(%rbx), %r15d
movl 0x34(%rbx), %r14d
movl 0x38(%rbx), %eax
movl %eax, 0x8(%rsp)
xorpd %xmm0, %xmm0
leaq 0x50(%rsp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movl %ebp, %edi
callq 0x9e45
leaq 0x98(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0xcb08
leaq 0x88(%rsp), %rdi
movl %r12d, %esi
movl %r13d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0x9b40
movl %eax, %r14d
movq 0x88(%rsp), %rdi
cmpq %rbx, %rdi
je 0xba9e
callq 0x6430
testl %r14d, %r14d
js 0xbd62
leaq 0x78(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rdi
callq 0xcb08
leaq 0x68(%rsp), %rdi
movl %r15d, %esi
movl 0x8(%rsp), %edx
callq 0x9cda
movq %rax, 0x18(%rsp)
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0xbaec
callq 0x6430
movl $0x18, %edi
callq 0x6450
movslq %ebp, %rcx
movq %rcx, 0x40(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %rax, %r15
movq $0x0, 0x10(%rax)
xorl %r12d, %r12d
movq 0x2b4b5(%rip), %r13     # 0x36fd0
leaq 0x18918(%rip), %rbx     # 0x2443a
leaq 0x18928(%rip), %r14     # 0x24451
movl $0x16, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6490
movl $0x7, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x6490
movq %r13, %rdi
movl %r12d, %esi
callq 0x6700
movl $0x9, %edx
movq %rax, %rdi
leaq 0x188f6(%rip), %rsi     # 0x24459
callq 0x6490
movl $0x16, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6490
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x6440
movsbl %al, %esi
movq %r13, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x62f0
movq 0x18(%rsp), %rdi
movl %ebp, %esi
leaq 0x50(%rsp), %rdx
movl 0x14(%rsp), %ecx
movq %r15, %r8
callq 0xa177
movsd %xmm0, 0x48(%rsp)
movl $0x16, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6490
movl $0x7, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x6490
movq %r13, %rdi
movl %r12d, %esi
callq 0x6700
movl $0xd, %edx
movq %rax, %rdi
leaq 0x1886b(%rip), %rsi     # 0x24463
callq 0x6490
movl $0x16, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6490
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x6440
movsbl %al, %esi
movq %r13, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x62f0
movsd 0x8(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
incl %r12d
cmpl $0xa, %r12d
jne 0xbb29
movq 0x2b375(%rip), %rdi     # 0x36fd0
leaq 0x187d8(%rip), %rsi     # 0x2443a
movl $0x16, %edx
callq 0x6490
movq %r15, %r13
movq 0x2b35a(%rip), %rdi     # 0x36fd0
leaq 0x187f4(%rip), %rsi     # 0x24471
movl $0x13, %edx
callq 0x6490
movq 0x2b342(%rip), %rbx     # 0x36fd0
leaq 0x187a5(%rip), %rsi     # 0x2443a
movl $0x16, %edx
movq %rbx, %rdi
callq 0x6490
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x6440
movsbl %al, %esi
movq 0x2b310(%rip), %rdi     # 0x36fd0
callq 0x6050
movq %rax, %rdi
callq 0x62f0
leaq 0xa8(%rsp), %rsi
movq %r13, %rdi
callq 0xc530
movq 0x40(%rsp), %rbp
movq (%r13), %rcx
movq 0x8(%r13), %rsi
cmpq %rsi, %rcx
je 0xbdad
xorl %eax, %eax
movq %rcx, %rdx
addq (%rdx), %rax
addq $0x8, %rdx
cmpq %rsi, %rdx
jne 0xbcf8
movq %rsi, %rdi
subq %rcx, %rdi
sarq $0x3, %rdi
xorl %edx, %edx
divq %rdi
movq %rax, %rbx
leaq 0x8(%rcx), %rax
cmpq %rsi, %rax
je 0xbdaf
movq (%rcx), %rdx
movq %rdx, %rdi
movq %rax, %r9
movq %rcx, %r8
movq (%r9), %r10
cmpq %rdi, %r10
cmovbq %r10, %rdi
cmovbq %r9, %r8
addq $0x8, %r9
cmpq %rsi, %r9
jne 0xbd2f
movq (%r8), %r15
movq (%rax), %rdi
cmpq %rdi, %rdx
cmovbeq %rdi, %rdx
cmovbq %rax, %rcx
addq $0x8, %rax
cmpq %rsi, %rax
jne 0xbd49
jmp 0xbdb2
movq 0x2b267(%rip), %rbx     # 0x36fd0
leaq 0x186b8(%rip), %rsi     # 0x24428
movl $0x11, %edx
movq %rbx, %rdi
callq 0x6490
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x6440
movsbl %al, %esi
movq 0x2b235(%rip), %rdi     # 0x36fd0
callq 0x6050
movq %rax, %rdi
callq 0x62f0
jmp 0xc105
xorl %ebx, %ebx
movq (%rcx), %r15
movq (%rcx), %r12
movq 0x2b214(%rip), %rdi     # 0x36fd0
leaq 0x186c2(%rip), %rsi     # 0x24485
movl $0x24, %edx
callq 0x6490
movq 0x2b1fc(%rip), %rdi     # 0x36fd0
movsd 0x8(%rsp), %xmm0
callq 0x6670
movq %rax, %r14
leaq 0x185c7(%rip), %rsi     # 0x243b0
movl $0x1, %edx
movq %rax, %rdi
callq 0x6490
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6440
movsbl %al, %esi
movq %r14, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x62f0
movq 0x2b1ac(%rip), %rdi     # 0x36fd0
leaq 0x183c8(%rip), %rsi     # 0x241f3
movl $0x22, %edx
callq 0x6490
leaq (,%rbp,2), %rax
leaq (%rax,%rax,4), %rax
movq %rax, %xmm1
punpckldq 0x181d2(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x181da(%rip), %xmm1    # 0x24030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x8(%rsp), %xmm0
movq 0x2b161(%rip), %rdi     # 0x36fd0
callq 0x6670
movq %rax, %r14
leaq 0x18398(%rip), %rsi     # 0x24216
movl $0x14, %edx
movq %rax, %rdi
callq 0x6490
movq %r14, %rdi
movq %rbx, %rsi
callq 0x62e0
movq %rax, %rbx
leaq 0x1838b(%rip), %rsi     # 0x2422b
movl $0x11, %edx
movq %rax, %rdi
callq 0x6490
imulq $0xa064, %rbp, %rax     # imm = 0xA064
movq %rax, %xmm1
punpckldq 0x1815f(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x18167(%rip), %xmm1    # 0x24030
movsd 0x1813f(%rip), %xmm2    # 0x24010
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
movsd 0x8(%rsp), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm1, %xmm0
mulsd %xmm2, %xmm3
divsd %xmm3, %xmm0
movq %rbx, %rdi
callq 0x6670
movq %rax, %rbx
leaq 0x1833c(%rip), %rsi     # 0x2423d
movl $0x5, %edx
movq %rax, %rdi
callq 0x6490
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6440
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x62f0
movq 0x2b094(%rip), %rdi     # 0x36fd0
leaq 0x18300(%rip), %rsi     # 0x24243
movl $0x21, %edx
callq 0x6490
movq 0x2b07c(%rip), %rdi     # 0x36fd0
movq %r15, %rsi
callq 0x62e0
movq %rax, %rbx
leaq 0x182ff(%rip), %rsi     # 0x24265
movl $0x8, %edx
movq %rax, %rdi
callq 0x6490
movq %rbx, %rdi
movq %r12, %rsi
callq 0x62e0
movq %rax, %rbx
leaq 0x182e6(%rip), %rsi     # 0x2426e
movl $0x8, %edx
movq %rax, %rdi
callq 0x6490
movq 0xa8(%rsp), %rsi
movq %rbx, %rdi
callq 0x62e0
movq %rax, %rbx
leaq 0x18188(%rip), %rsi     # 0x24137
movl $0x1, %edx
movq %rax, %rdi
callq 0x6490
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6440
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x62f0
movq 0x2afe6(%rip), %rdi     # 0x36fd0
leaq 0x18286(%rip), %rsi     # 0x24277
movl $0x21, %edx
callq 0x6490
movq 0xb0(%rsp), %rsi
movq 0x2afc6(%rip), %rdi     # 0x36fd0
callq 0x62e0
movq %rax, %rbx
leaq 0x18280(%rip), %rsi     # 0x24299
movl $0x8, %edx
movq %rax, %rdi
callq 0x6490
movq 0xb8(%rsp), %rsi
movq %rbx, %rdi
callq 0x62e0
movq %rax, %rbx
leaq 0x18262(%rip), %rsi     # 0x242a2
movl $0x8, %edx
movq %rax, %rdi
callq 0x6490
movq 0xc0(%rsp), %rsi
movq %rbx, %rdi
callq 0x62e0
movq %rax, %rbx
leaq 0x18244(%rip), %rsi     # 0x242ab
movl $0x9, %edx
movq %rax, %rdi
callq 0x6490
movq 0xc8(%rsp), %rsi
movq %rbx, %rdi
callq 0x62e0
movq %rax, %rbx
leaq 0x18227(%rip), %rsi     # 0x242b5
movl $0xa, %edx
movq %rax, %rdi
callq 0x6490
movq 0xd0(%rsp), %rsi
movq %rbx, %rdi
callq 0x62e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6440
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x62f0
movq (%r13), %rdi
cmpq %rdi, 0x8(%r13)
je 0xc0e3
movq %rdi, 0x8(%r13)
testq %rdi, %rdi
je 0xc0ed
callq 0x6430
movq %r13, %rdi
callq 0x6430
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xc105
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x50(%rsp), %rdi
callq 0xc62e
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xc123
callq 0x6430
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc160
movq %rax, %r14
movq 0x68(%rsp), %rdi
jmp 0xc14e
jmp 0xc160
movq %rax, %r14
movq 0x88(%rsp), %rdi
cmpq %rbx, %rdi
je 0xc163
callq 0x6430
jmp 0xc163
jmp 0xc160
jmp 0xc160
jmp 0xc160
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0xc62e
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xc181
callq 0x6430
movq %r14, %rdi
callq 0x6710