// File: yangwanyuan[P]HLKVDS/tools/Benchmark.cc
// Function: fun_insert(void*)
void* fun_insert(void *arg) {
    thread_arg *t_args = (thread_arg*) arg;
    KVDS *db = t_args->db;
    int key_start = t_args->key_start;
    int key_end = t_args->key_end;
    vector<string> &key_list = *t_args->key_list;
    uint64_t *latency = t_args->latency;

    string *value = t_args->data;

    int value_size = VALUE_SIZE;
    int key_len = KEY_SIZE;
    Status s;

    for (int i = key_start; i < key_end + 1; i++) {
        string key = key_list[i];
        //string key = key_list[i-key_start];
        KVTime tv_start;
        s = db->Insert(key.c_str(), key_len, value->c_str(), value_size);
        KVTime tv_end;
        latency[i - key_start] = (uint64_t)(tv_end - tv_start);
        if (!s.ok()) {
            cout << "Insert key=" << key << "to DB failed!" << endl;
        }
    }
    return NULL;

}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x100(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xf0(%rsp)
movq 0xf8(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0xec(%rsp)
movq 0xf8(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0xe8(%rsp)
movq 0xf8(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0xe0(%rsp)
movq 0xf8(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0xd8(%rsp)
movq 0xf8(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0xd0(%rsp)
movl $0x1000, 0xcc(%rsp) # imm = 0x1000
movl $0xa, 0xc8(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0xce70
movl 0xec(%rsp), %eax
movl %eax, 0xac(%rsp)
movl 0xac(%rsp), %eax
movl 0xe8(%rsp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x97ec
movq 0xe0(%rsp), %rdi
movslq 0xac(%rsp), %rsi
callq 0xce90
movq %rax, %rsi
leaq 0x88(%rsp), %rdi
callq 0x81b0
jmp 0x95f3
leaq 0x68(%rsp), %rdi
callq 0x555c0
jmp 0x95ff
movq 0xf0(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x8190
movq %rax, 0x38(%rsp)
movl 0xc8(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x8190
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movl 0x44(%rsp), %ecx
movq %rax, %r8
movzwl 0xcc(%rsp), %r9d
movq %rsp, %rax
movl $0x0, (%rax)
leaq 0x58(%rsp), %rdi
callq 0x31e90
jmp 0x9665
movups 0x58(%rsp), %xmm0
movaps %xmm0, 0xb0(%rsp)
leaq 0x58(%rsp), %rdi
callq 0xceb0
leaq 0x48(%rsp), %rdi
callq 0x555c0
jmp 0x9688
leaq 0x48(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x55770
movq %rax, 0x28(%rsp)
jmp 0x969e
movq 0x28(%rsp), %rdx
movq 0xd8(%rsp), %rax
movl 0xac(%rsp), %ecx
movl 0xec(%rsp), %esi
subl %esi, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
leaq 0xb0(%rsp), %rdi
callq 0xcef0
movb %al, 0x27(%rsp)
jmp 0x96d5
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x979c
jmp 0x96e3
movq 0x6e8e6(%rip), %rdi     # 0x77fd0
leaq 0x4dac0(%rip), %rsi     # 0x571b1
callq 0x8520
movq %rax, 0x18(%rsp)
jmp 0x96fd
movq 0x18(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x84a0
movq %rax, 0x10(%rsp)
jmp 0x9716
movq 0x10(%rsp), %rdi
leaq 0x4da9b(%rip), %rsi     # 0x571bd
callq 0x8520
movq %rax, 0x8(%rsp)
jmp 0x972e
movq 0x8(%rsp), %rdi
movq 0x6e866(%rip), %rsi     # 0x77fa0
callq 0x8560
jmp 0x9741
jmp 0x979c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x9803
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x97dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
jmp 0x97d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x557b0
jmp 0x97d3
leaq 0x48(%rsp), %rdi
callq 0x557b0
leaq 0x68(%rsp), %rdi
callq 0x557b0
leaq 0x88(%rsp), %rdi
callq 0x8998
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x95b3
leaq 0x68(%rsp), %rdi
callq 0x557b0
leaq 0x88(%rsp), %rdi
callq 0x8998
jmp 0x9803
leaq 0xb0(%rsp), %rdi
callq 0xceb0
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
retq
leaq 0xb0(%rsp), %rdi
callq 0xceb0
movq 0x80(%rsp), %rdi
callq 0x8880
nopl (%rax)