// File: /workspace/github_cpp_makefile_star2_O1/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 0xc9b2
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 0x9cb5
leaq 0x98(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0xc9b2
leaq 0x88(%rsp), %rdi
movl %r12d, %esi
movl %r13d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0x99b0
movl %eax, %r14d
movq 0x88(%rsp), %rdi
cmpq %rbx, %rdi
je 0xb924
callq 0x6440
testl %r14d, %r14d
js 0xbf4b
leaq 0x78(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rdi
callq 0xc9b2
leaq 0x68(%rsp), %rdi
movl %r15d, %esi
movl 0x8(%rsp), %edx
callq 0x9b4a
movq %rax, 0x18(%rsp)
movq 0x68(%rsp), %rdi
cmpq %rbx, %rdi
je 0xb972
callq 0x6440
movl $0x18, %edi
callq 0x6460
movslq %ebp, %rcx
movq %rcx, 0x40(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %rax, %r15
movq $0x0, 0x10(%rax)
xorl %r12d, %r12d
movq 0x2b62f(%rip), %r13     # 0x36fd0
leaq 0x18a92(%rip), %rbx     # 0x2443a
leaq 0x18aa2(%rip), %r14     # 0x24451
movl $0x16, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x64a0
movl $0x7, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x64a0
movq %r13, %rdi
movl %r12d, %esi
callq 0x6710
movl $0x9, %edx
movq %rax, %rdi
leaq 0x18a70(%rip), %rsi     # 0x24459
callq 0x64a0
movl $0x16, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x64a0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x6450
movsbl %al, %esi
movq %r13, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x6300
movq 0x18(%rsp), %rdi
movl %ebp, %esi
leaq 0x50(%rsp), %rdx
movl 0x14(%rsp), %ecx
movq %r15, %r8
callq 0x9fe7
movsd %xmm0, 0x48(%rsp)
movl $0x16, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x64a0
movl $0x7, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x64a0
movq %r13, %rdi
movl %r12d, %esi
callq 0x6710
movl $0xd, %edx
movq %rax, %rdi
leaq 0x189e5(%rip), %rsi     # 0x24463
callq 0x64a0
movl $0x16, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x64a0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x6450
movsbl %al, %esi
movq %r13, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x6300
movsd 0x8(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
incl %r12d
cmpl $0xa, %r12d
jne 0xb9af
movq 0x2b4ef(%rip), %rdi     # 0x36fd0
leaq 0x18952(%rip), %rsi     # 0x2443a
movl $0x16, %edx
callq 0x64a0
movq %r15, %r13
movq 0x2b4d4(%rip), %rdi     # 0x36fd0
leaq 0x1896e(%rip), %rsi     # 0x24471
movl $0x13, %edx
callq 0x64a0
movq 0x2b4bc(%rip), %rbx     # 0x36fd0
leaq 0x1891f(%rip), %rsi     # 0x2443a
movl $0x16, %edx
movq %rbx, %rdi
callq 0x64a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x6450
movsbl %al, %esi
movq 0x2b48a(%rip), %rdi     # 0x36fd0
callq 0x6050
movq %rax, %rdi
callq 0x6300
leaq 0xa8(%rsp), %rsi
movq %r13, %rdi
callq 0xc3bc
movq 0x40(%rsp), %rbp
movq (%r13), %rsi
movq 0x8(%r13), %rcx
xorl %eax, %eax
cmpq %rcx, %rsi
je 0xbb86
movq %rsi, %rdx
addq (%rdx), %rax
addq $0x8, %rdx
cmpq %rcx, %rdx
jne 0xbb7a
movq %rcx, %rdi
subq %rsi, %rdi
sete %r8b
sarq $0x3, %rdi
xorl %edx, %edx
divq %rdi
movq %rax, %rbx
leaq 0x8(%rsi), %rax
cmpq %rcx, %rax
sete %dil
orb %r8b, %dil
movq %rsi, %rdx
jne 0xbbcf
movq %rax, %r8
movq %rsi, %r9
movq (%r8), %r10
movq %r8, %rdx
cmpq (%r9), %r10
jb 0xbbc3
movq %r9, %rdx
addq $0x8, %r8
movq %rdx, %r9
cmpq %rcx, %r8
jne 0xbbb5
testb %dil, %dil
je 0xbbd9
movq %rsi, %rdi
jmp 0xbbf3
movq (%rsi), %r8
movq %rax, %rdi
cmpq (%rax), %r8
jb 0xbbe7
movq %rsi, %rdi
addq $0x8, %rax
movq %rdi, %rsi
cmpq %rcx, %rax
jne 0xbbd9
movq (%rdx), %r12
movq (%rdi), %r15
movq 0x2b3d0(%rip), %rdi     # 0x36fd0
leaq 0x1887e(%rip), %rsi     # 0x24485
movl $0x24, %edx
callq 0x64a0
movq 0x2b3b8(%rip), %rdi     # 0x36fd0
movsd 0x8(%rsp), %xmm0
callq 0x6680
movq %rax, %r14
leaq 0x18783(%rip), %rsi     # 0x243b0
movl $0x1, %edx
movq %rax, %rdi
callq 0x64a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6450
movsbl %al, %esi
movq %r14, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x6300
movq 0x2b368(%rip), %rdi     # 0x36fd0
leaq 0x18584(%rip), %rsi     # 0x241f3
movl $0x22, %edx
callq 0x64a0
leaq (,%rbp,2), %rax
leaq (%rax,%rax,4), %rax
movq %rax, %xmm1
punpckldq 0x1838e(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x18396(%rip), %xmm1    # 0x24030
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd 0x8(%rsp), %xmm0
movq 0x2b31d(%rip), %rdi     # 0x36fd0
callq 0x6680
movq %rax, %r14
leaq 0x18554(%rip), %rsi     # 0x24216
movl $0x14, %edx
movq %rax, %rdi
callq 0x64a0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x62f0
movq %rax, %rbx
leaq 0x18547(%rip), %rsi     # 0x2422b
movl $0x11, %edx
movq %rax, %rdi
callq 0x64a0
imulq $0xa064, %rbp, %rax     # imm = 0xA064
movq %rax, %xmm1
punpckldq 0x1831b(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x18323(%rip), %xmm1    # 0x24030
movsd 0x182fb(%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 0x6680
movq %rax, %rbx
leaq 0x184f8(%rip), %rsi     # 0x2423d
movl $0x5, %edx
movq %rax, %rdi
callq 0x64a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6450
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x6300
movq 0x2b250(%rip), %rdi     # 0x36fd0
leaq 0x184bc(%rip), %rsi     # 0x24243
movl $0x21, %edx
callq 0x64a0
movq 0x2b238(%rip), %rdi     # 0x36fd0
movq %r12, %rsi
callq 0x62f0
movq %rax, %rbx
leaq 0x184bb(%rip), %rsi     # 0x24265
movl $0x8, %edx
movq %rax, %rdi
callq 0x64a0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x62f0
movq %rax, %rbx
leaq 0x184a2(%rip), %rsi     # 0x2426e
movl $0x8, %edx
movq %rax, %rdi
callq 0x64a0
movq 0xa8(%rsp), %rsi
movq %rbx, %rdi
callq 0x62f0
movq %rax, %rbx
leaq 0x18344(%rip), %rsi     # 0x24137
movl $0x1, %edx
movq %rax, %rdi
callq 0x64a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6450
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x6300
movq 0x2b1a2(%rip), %rdi     # 0x36fd0
leaq 0x18442(%rip), %rsi     # 0x24277
movl $0x21, %edx
callq 0x64a0
movq 0xb0(%rsp), %rsi
movq 0x2b182(%rip), %rdi     # 0x36fd0
callq 0x62f0
movq %rax, %rbx
leaq 0x1843c(%rip), %rsi     # 0x24299
movl $0x8, %edx
movq %rax, %rdi
callq 0x64a0
movq 0xb8(%rsp), %rsi
movq %rbx, %rdi
callq 0x62f0
movq %rax, %rbx
leaq 0x1841e(%rip), %rsi     # 0x242a2
movl $0x8, %edx
movq %rax, %rdi
callq 0x64a0
movq 0xc0(%rsp), %rsi
movq %rbx, %rdi
callq 0x62f0
movq %rax, %rbx
leaq 0x18400(%rip), %rsi     # 0x242ab
movl $0x9, %edx
movq %rax, %rdi
callq 0x64a0
movq 0xc8(%rsp), %rsi
movq %rbx, %rdi
callq 0x62f0
movq %rax, %rbx
leaq 0x183e3(%rip), %rsi     # 0x242b5
movl $0xa, %edx
movq %rax, %rdi
callq 0x64a0
movq 0xd0(%rsp), %rsi
movq %rbx, %rdi
callq 0x62f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6450
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6050
movq %rax, %rdi
callq 0x6300
movq (%r13), %rdi
cmpq %rdi, 0x8(%r13)
je 0xbf27
movq %rdi, 0x8(%r13)
testq %rdi, %rdi
je 0xbf31
callq 0x6440
movq %r13, %rdi
callq 0x6440
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xbf91
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0xbf91
movq 0x2b07e(%rip), %rbx     # 0x36fd0
leaq 0x184cf(%rip), %rsi     # 0x24428
movl $0x11, %edx
movq %rbx, %rdi
callq 0x64a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x6450
movsbl %al, %esi
movq 0x2b04c(%rip), %rdi     # 0x36fd0
callq 0x6050
movq %rax, %rdi
callq 0x6300
leaq 0x50(%rsp), %rdi
callq 0xc4ba
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xbfaf
callq 0x6440
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xbfec
movq %rax, %r14
movq 0x68(%rsp), %rdi
jmp 0xbfda
jmp 0xbfec
movq %rax, %r14
movq 0x88(%rsp), %rdi
cmpq %rbx, %rdi
je 0xbfef
callq 0x6440
jmp 0xbfef
jmp 0xbfec
jmp 0xbfec
jmp 0xbfec
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0xc4ba
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xc00d
callq 0x6440
movq %r14, %rdi
callq 0x6720