// File: chahk0129[P]hash_bench/./bench/benchmark.hpp
// Function: benchmark_t<unsigned long>::ycsb_load(int, int, Pair<unsigned long>*, int, Pair<unsigned long>*, int, int*)
inline void benchmark_t<Key_t>::ycsb_load(int workload_type, int index_type, Pair<Key_t>* init_kv, int init_num, Pair<Key_t>* run_kv, int run_num, int* ops){
    std::string init_file;
    std::string txn_file;

    if(workload_type == WORKLOAD_A){
	init_file = "/hk/workloads2/loada_zipfian_int_100M.dat";
	txn_file = "/hk/workloads2/txnsa_zipfian_int_100M.dat";
    }
    else if(workload_type == WORKLOAD_B){
	init_file = "/hk/workloads2/loadb_zipfian_int_100M.dat";
	txn_file = "/hk/workloads2/txnsb_zipfian_int_100M.dat";
    }
    else if(workload_type == WORKLOAD_C){
	init_file = "/hk/workloads2/loadc_zipfian_int_100M.dat";
	txn_file = "/hk/workloads2/txnsc_zipfian_int_100M.dat";
    }
    else if(workload_type == WORKLOAD_D){
	init_file = "/hk/workloads2/loadd_zipfian_int_100M.dat";
	txn_file = "/hk/workloads2/txnsd_zipfian_int_100M.dat";
    }
    else{
	fprintf(stderr, "unkonw workload type %d\n", workload_type);
	exit(1);
    }


    uint64_t value = 0;
    void* base_ptr = malloc(8);
    uint64_t base = (uint64_t)base_ptr;
    free(base_ptr);

    std::ifstream infile_load;
    infile_load.open(init_file.c_str());
    if(!infile_load.is_open()){
	fprintf(stderr, "init file failed to open\n");
	exit(1);
    }

    std::string op;
    std::string key_;
    Key_t key;

    std::string insert("INSERT");
    std::string read("READ");
    std::string update("UPDATE");

    for(int i=0; i<init_num; i++){
	if constexpr(sizeof(Key_t) > 8)
	    infile_load >> op >> key_;
	else
	    infile_load >> op >> key;
	if(op.compare(insert) != 0){
	    fprintf(stderr, "Reading load file failed\n");
	    exit(1);
	}
	if constexpr(sizeof(Key_t) > 8){
	    strcpy(init_kv[i].key, key_.c_str());
	    //memcpy(init_kv[i].key, key_.c_str(), sizeof(Key_t));
	    //init_kv[i].key[sizeof(Key_t)-1] = 0;
	}
	else
	    init_kv[i].key = key;
	init_kv[i].value = base + rand();
	if constexpr(sizeof(Key_t) > 8)
	    key_ = "";

    }

    infile_load.close();

    Pair<Key_t>* init_kv_data = &init_kv[0];


    std::ifstream infile_txn;
    infile_txn.open(txn_file.c_str());
    if(!infile_txn.is_open()){
	fprintf(stderr, "txn file failed to open\n");
	exit(1);
    }
    
    for(int i=0; i<run_num; i++){
	if constexpr(sizeof(Key_t) > 8)
	    infile_txn >> op >> key_;
	else
	    infile_txn >> op >> key;
	if(op.compare(insert) == 0){
	    ops[i] = OP_INSERT;
	    if constexpr(sizeof(Key_t) > 8){
		strcpy(run_kv[i].key, key_.c_str());
		//memcpy(run_kv[i].key, key_.c_str(), sizeof(Key_t));
		//run_kv[i].key[sizeof(Key_t)-1] = 0;
	    }
	    else
		run_kv[i].key = key;
	    run_kv[i].value = (uint64_t)&run_kv[i];
	}
	else if(op.compare(read) == 0){
	    ops[i] = OP_READ;
	    if constexpr(sizeof(Key_t) > 8){
		strcpy(run_kv[i].key, key_.c_str());
		//memcpy(run_kv[i].key, key_.c_str(), sizeof(Key_t));
		run_kv[i].key[sizeof(Key_t)-1] = 0;
	    }
	    else
		run_kv[i].key = key;
	}
	else if(op.compare(update) == 0){
	    ops[i] = OP_UPDATE;
	    if constexpr(sizeof(Key_t) > 8){
		strcpy(run_kv[i].key, key_.c_str());
		//memcpy(run_kv[i].key, key_.c_str(), sizeof(Key_t));
		//run_kv[i].key[sizeof(Key_t)-1] = 0;
	    }
	    else
		run_kv[i].key = key;
	    run_kv[i].value = (uint64_t)&run_kv[i];
	}
	else{
	    fprintf(stderr, "unknown operation type\n");
	    exit(1);
	}
	if constexpr(sizeof(Key_t) > 8)
	    key_ = "";
    }

    infile_txn.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5c0, %rsp            # imm = 0x5C0
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq %r9, -0x28(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x65d0
leaq -0x68(%rbp), %rdi
callq 0x65d0
cmpl $0x0, -0xc(%rbp)
jne 0x1512a
leaq 0x31232(%rip), %rsi     # 0x46329
leaq -0x48(%rbp), %rdi
callq 0x65c0
jmp 0x15102
leaq 0x3124a(%rip), %rsi     # 0x46353
leaq -0x68(%rbp), %rdi
callq 0x65c0
jmp 0x15114
jmp 0x151dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x15803
cmpl $0x1, -0xc(%rbp)
jne 0x15159
leaq 0x31246(%rip), %rsi     # 0x4637d
leaq -0x48(%rbp), %rdi
callq 0x65c0
jmp 0x15142
leaq 0x3125e(%rip), %rsi     # 0x463a7
leaq -0x68(%rbp), %rdi
callq 0x65c0
jmp 0x15154
jmp 0x151da
cmpl $0x2, -0xc(%rbp)
jne 0x15185
leaq 0x3126b(%rip), %rsi     # 0x463d1
leaq -0x48(%rbp), %rdi
callq 0x65c0
jmp 0x15171
leaq 0x31283(%rip), %rsi     # 0x463fb
leaq -0x68(%rbp), %rdi
callq 0x65c0
jmp 0x15183
jmp 0x151d8
cmpl $0x3, -0xc(%rbp)
jne 0x151b1
leaq 0x31293(%rip), %rsi     # 0x46425
leaq -0x48(%rbp), %rdi
callq 0x65c0
jmp 0x1519d
leaq 0x312ab(%rip), %rsi     # 0x4644f
leaq -0x68(%rbp), %rdi
callq 0x65c0
jmp 0x151af
jmp 0x151d6
movq 0x4ae08(%rip), %rax     # 0x5ffc0
movq (%rax), %rdi
movl -0xc(%rbp), %edx
leaq 0x312b4(%rip), %rsi     # 0x46479
movb $0x0, %al
callq 0x6630
movl $0x1, %edi
callq 0x6530
jmp 0x151d8
jmp 0x151da
jmp 0x151dc
movq $0x0, -0x80(%rbp)
movl $0x8, %edi
callq 0x65a0
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
callq 0x6520
leaq -0x298(%rbp), %rdi
callq 0x64c0
jmp 0x1521d
leaq -0x48(%rbp), %rdi
callq 0x6190
movq %rax, %rsi
leaq -0x298(%rbp), %rdi
movl $0x8, %edx
callq 0x6270
jmp 0x1523c
leaq -0x298(%rbp), %rdi
callq 0x6720
movb %al, -0x56d(%rbp)
jmp 0x15250
movb -0x56d(%rbp), %al
testb $0x1, %al
jne 0x1528f
jmp 0x1525c
movq 0x4ad5d(%rip), %rax     # 0x5ffc0
movq (%rax), %rdi
leaq 0x31225(%rip), %rsi     # 0x46492
movb $0x0, %al
callq 0x6630
movl $0x1, %edi
callq 0x6530
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x157f7
leaq -0x2b8(%rbp), %rdi
callq 0x65d0
leaq -0x2d8(%rbp), %rdi
callq 0x65d0
leaq -0x301(%rbp), %rdi
movq %rdi, -0x578(%rbp)
callq 0x14f00
movq -0x578(%rbp), %rdx
leaq 0x311e4(%rip), %rsi     # 0x464ac
leaq -0x300(%rbp), %rdi
callq 0x1baf0
jmp 0x152d6
leaq -0x301(%rbp), %rdi
callq 0x14f70
leaq -0x329(%rbp), %rdi
movq %rdi, -0x580(%rbp)
callq 0x14f00
movq -0x580(%rbp), %rdx
leaq 0x311b0(%rip), %rsi     # 0x464b3
leaq -0x328(%rbp), %rdi
callq 0x1baf0
jmp 0x15311
leaq -0x329(%rbp), %rdi
callq 0x14f70
leaq -0x351(%rbp), %rdi
movq %rdi, -0x588(%rbp)
callq 0x14f00
movq -0x588(%rbp), %rdx
leaq 0x3117a(%rip), %rsi     # 0x464b8
leaq -0x350(%rbp), %rdi
callq 0x1baf0
jmp 0x1534c
leaq -0x351(%rbp), %rdi
callq 0x14f70
movl $0x0, -0x358(%rbp)
movl -0x358(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x154bb
leaq -0x298(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x6570
movq %rax, -0x590(%rbp)
jmp 0x1538d
movq -0x590(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x6620
jmp 0x153a2
leaq -0x2b8(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x6050
movl %eax, -0x594(%rbp)
jmp 0x153bd
movl -0x594(%rbp), %eax
cmpl $0x0, %eax
je 0x15456
movq 0x4abed(%rip), %rax     # 0x5ffc0
movq (%rax), %rdi
leaq 0x310e2(%rip), %rsi     # 0x464bf
movb $0x0, %al
callq 0x6630
movl $0x1, %edi
callq 0x6530
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x301(%rbp), %rdi
callq 0x14f70
jmp 0x157df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x329(%rbp), %rdi
callq 0x14f70
jmp 0x157d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x351(%rbp), %rdi
callq 0x14f70
jmp 0x157c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x157bb
movq -0x2e0(%rbp), %rcx
movq -0x18(%rbp), %rax
movslq -0x358(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x90(%rbp), %rax
movq %rax, -0x5a0(%rbp)
callq 0x60f0
movq -0x5a0(%rbp), %rcx
cltq
addq %rax, %rcx
movq -0x18(%rbp), %rax
movslq -0x358(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x358(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x358(%rbp)
jmp 0x15362
leaq -0x298(%rbp), %rdi
callq 0x60a0
jmp 0x154c9
movq -0x18(%rbp), %rax
movq %rax, -0x360(%rbp)
leaq -0x568(%rbp), %rdi
callq 0x64c0
jmp 0x154e2
leaq -0x68(%rbp), %rdi
callq 0x6190
movq %rax, %rsi
leaq -0x568(%rbp), %rdi
movl $0x8, %edx
callq 0x6270
jmp 0x15501
leaq -0x568(%rbp), %rdi
callq 0x6720
movb %al, -0x5a1(%rbp)
jmp 0x15515
movb -0x5a1(%rbp), %al
testb $0x1, %al
jne 0x15560
jmp 0x15521
movq 0x4aa98(%rip), %rax     # 0x5ffc0
movq (%rax), %rdi
leaq 0x30fa7(%rip), %rsi     # 0x464d9
movb $0x0, %al
callq 0x6630
movl $0x1, %edi
callq 0x6530
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x568(%rbp), %rdi
callq 0x60e0
jmp 0x157bb
movl $0x0, -0x56c(%rbp)
movl -0x56c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x1573e
leaq -0x568(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x6570
movq %rax, -0x5b0(%rbp)
jmp 0x15595
movq -0x5b0(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x6620
jmp 0x155aa
leaq -0x2b8(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x6050
movl %eax, -0x5b4(%rbp)
jmp 0x155c5
movl -0x5b4(%rbp), %eax
cmpl $0x0, %eax
jne 0x1562b
movq 0x18(%rbp), %rax
movslq -0x56c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x2e0(%rbp), %rcx
movq -0x28(%rbp), %rax
movslq -0x56c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movslq -0x56c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movslq -0x56c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x15728
leaq -0x2b8(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x6050
movl %eax, -0x5b8(%rbp)
jmp 0x15646
movl -0x5b8(%rbp), %eax
cmpl $0x0, %eax
jne 0x15684
movq 0x18(%rbp), %rax
movslq -0x56c(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movq -0x2e0(%rbp), %rcx
movq -0x28(%rbp), %rax
movslq -0x56c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
jmp 0x15726
leaq -0x2b8(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x6050
movl %eax, -0x5bc(%rbp)
jmp 0x1569f
movl -0x5bc(%rbp), %eax
cmpl $0x0, %eax
jne 0x15702
movq 0x18(%rbp), %rax
movslq -0x56c(%rbp), %rcx
movl $0x2, (%rax,%rcx,4)
movq -0x2e0(%rbp), %rcx
movq -0x28(%rbp), %rax
movslq -0x56c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movslq -0x56c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movslq -0x56c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x15724
movq 0x4a8b7(%rip), %rax     # 0x5ffc0
movq (%rax), %rdi
leaq 0x30ddf(%rip), %rsi     # 0x464f2
movb $0x0, %al
callq 0x6630
movl $0x1, %edi
callq 0x6530
jmp 0x15726
jmp 0x15728
jmp 0x1572a
movl -0x56c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x56c(%rbp)
jmp 0x1556a
leaq -0x568(%rbp), %rdi
callq 0x60a0
jmp 0x1574c
leaq -0x568(%rbp), %rdi
callq 0x60e0
leaq -0x350(%rbp), %rdi
callq 0x6260
leaq -0x328(%rbp), %rdi
callq 0x6260
leaq -0x300(%rbp), %rdi
callq 0x6260
leaq -0x2d8(%rbp), %rdi
callq 0x6260
leaq -0x2b8(%rbp), %rdi
callq 0x6260
leaq -0x298(%rbp), %rdi
callq 0x60e0
leaq -0x68(%rbp), %rdi
callq 0x6260
leaq -0x48(%rbp), %rdi
callq 0x6260
addq $0x5c0, %rsp            # imm = 0x5C0
popq %rbp
retq
leaq -0x350(%rbp), %rdi
callq 0x6260
leaq -0x328(%rbp), %rdi
callq 0x6260
leaq -0x300(%rbp), %rdi
callq 0x6260
leaq -0x2d8(%rbp), %rdi
callq 0x6260
leaq -0x2b8(%rbp), %rdi
callq 0x6260
leaq -0x298(%rbp), %rdi
callq 0x60e0
leaq -0x68(%rbp), %rdi
callq 0x6260
leaq -0x48(%rbp), %rdi
callq 0x6260
movq -0x70(%rbp), %rdi
callq 0x6800
nop