// File: /workspace/github_cpp_makefile_star2_O2/yangwanyuan[P]HLKVDS/tools/DbTest.cc
// Function: Open_DB_Test(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Open_DB_Test(string filename) {

    Options opts;
    KVDS *db = KVDS::Open_KVDS(filename.c_str(), opts);

    //DB Insert 
    string test_key = "test-key";
    int test_key_size = 8;
    string test_value = "test-value";
    int test_value_size = 10;

    Status s = db->Insert(test_key.c_str(), test_key_size, test_value.c_str(),
                          test_value_size);
    if (!s.ok()) {
        std::cout << "Insert Failed" << std::endl;
    } else {
        std::cout << "Insert Success" << std::endl;
    }

    test_value = "test-value-new";
    test_value_size = 14;
    s = db->Insert(test_key.c_str(), test_key_size, test_value.c_str(),
                   test_value_size);
    if (!s.ok()) {
        std::cout << "Insert Failed" << std::endl;
    } else {
        std::cout << "Insert Success" << std::endl;
    }

    //DB Get
    string get_data;
    s = db->Get(test_key.c_str(), test_key_size, get_data);
    if (!s.ok()) {
        std::cout << "Get Failed" << std::endl;
    } else {
        std::cout << "Get Success: data is " << get_data << std::endl;
    }

    //DB Delete
    s = db->Delete(test_key.c_str(), test_key_size);
    if (!s.ok()) {
        std::cout << "Delete Failed" << std::endl;
    } else {
        std::cout << "Delete Success!" << std::endl;
    }

    ////DB Get
    //if (!db->Get(test_key.c_str(), test_key_size, get_data)){
    //  std::cout << "Get Failed" << std::endl;
    //}else{
    //  std::cout << "Get Success: data is " << get_data << std::endl; 
    //}

    WriteBatch batch;
    batch.put(test_key.c_str(), test_key_size, test_value.c_str(),
                test_value_size);

    string test_key2 = "test-key2";
    int test_key2_size = 9;
    string test_value2 = "test-value2";
    int test_value2_size = 11;
    batch.put(test_key2.c_str(), test_key2_size, test_value2.c_str(),
                test_value2_size);
    batch.put("keykeykey3",10,"value3",6);
    batch.put("keykeykey4",10,"value4",6);
    batch.put("keykeykey5",10,"value5",6);
    batch.put("keykeykey6",10,"value6",6);
    batch.put("keykeykey7",10,"value7",6);
    batch.put("keykeykey8",10,"value8",6);
    batch.put("keykeykey9",10,"value9",6);
    batch.del(test_key.c_str(), test_key_size);

    s = db->InsertBatch(&batch);
    if (!s.ok()) {
        std::cout << "Insert Batch Failed" << std::endl;
    }
    else {
        std::cout << "Insert Batch Success" << std::endl;
    }

    //DB Get
    //string get_data;
    s = db->Get(test_key.c_str(), test_key_size, get_data);
    if (!s.ok()) {
        std::cout << "Get Failed" << std::endl;
    } else {
        std::cout << "Get Success: data is " << get_data << std::endl;
    }
    s = db->Get(test_key2.c_str(), test_key2_size, get_data);
    if (!s.ok()) {
        std::cout << "Get Failed" << std::endl;
    } else {
        std::cout << "Get Success: data is " << get_data << std::endl;
    }

    Iterator* it = db->NewIterator();
    //test iterator if compile iterator
    if ( it != NULL) {
        cout << "Iterator the db: First to Last" << endl;
        for(it->SeekToFirst(); it->Valid(); it->Next()) {
            cout << it->Key() << ": " << it->Value() << endl;
        }
        sleep(3);
        cout << "Iterator the db: Last to First" << endl;
        for(it->SeekToLast(); it->Valid(); it->Prev()) {
            cout << it->Key() << ": " << it->Value() << endl;
        }
        delete it;
    }
    delete db;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, %rbx
leaq 0x168(%rsp), %r14
movq %r14, %rdi
callq 0x14ba8
movq (%rbx), %rax
pushq $0xa
popq %rcx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x10de8
movq %rax, %r15
leaq 0x1854d(%rip), %rsi     # 0x1f006
leaq 0xc0(%rsp), %rdi
leaq 0x108(%rsp), %rdx
callq 0x6150
leaq 0x1853a(%rip), %rsi     # 0x1f00f
leaq 0x108(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x6150
movq 0xc0(%rsp), %rdx
movq 0x108(%rsp), %r8
andl $0x0, (%rsp)
leaq 0x50(%rsp), %rdi
pushq $0x8
popq %rcx
pushq $0xa
popq %r9
movq %r15, %rsi
callq 0x112fe
cmpl $0x0, 0x50(%rsp)
leaq 0x1850a(%rip), %rbx     # 0x1f028
leaq 0x184f5(%rip), %r14     # 0x1f01a
movq %r14, %rsi
cmoveq %rbx, %rsi
movq 0x2b49d(%rip), %rdi     # 0x31fd0
callq 0x6400
movq %rax, %rdi
callq 0x61c0
leaq 0x184f0(%rip), %rsi     # 0x1f037
leaq 0x108(%rsp), %rdi
callq 0x6730
movq 0xc0(%rsp), %rdx
movq 0x108(%rsp), %r8
andl $0x0, (%rsp)
leaq 0x80(%rsp), %rdi
pushq $0x8
popq %rcx
pushq $0xe
popq %r9
movq %r15, %rsi
callq 0x112fe
movups 0x80(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
cmoveq %rbx, %r14
movq 0x2b434(%rip), %rdi     # 0x31fd0
movq %r14, %rsi
callq 0x6400
movq %rax, %rdi
callq 0x61c0
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xc0(%rsp), %rdx
leaq 0xe0(%rsp), %rdi
pushq $0x8
popq %rcx
leaq 0x80(%rsp), %r8
movq %r15, %rsi
callq 0x1143c
movups 0xe0(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
je 0x6c0c
movq 0x2b3d2(%rip), %rdi     # 0x31fd0
leaq 0x18441(%rip), %rsi     # 0x1f046
callq 0x6400
jmp 0x6c2f
movq 0x2b3bd(%rip), %rdi     # 0x31fd0
leaq 0x18437(%rip), %rsi     # 0x1f051
callq 0x6400
leaq 0x80(%rsp), %rsi
movq %rax, %rdi
callq 0x63b0
movq %rax, %rdi
callq 0x61c0
movq 0xc0(%rsp), %rdx
leaq 0xe0(%rsp), %rdi
pushq $0x8
popq %rcx
movq %r15, %rsi
callq 0x1141c
movups 0xe0(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
leaq 0x1840a(%rip), %rax     # 0x1f075
leaq 0x183f5(%rip), %rsi     # 0x1f067
cmoveq %rax, %rsi
movq 0x2b353(%rip), %rdi     # 0x31fd0
callq 0x6400
movq %rax, %rdi
callq 0x61c0
leaq 0x68(%rsp), %rdi
callq 0x1e174
movq 0xc0(%rsp), %rsi
movq 0x108(%rsp), %rcx
leaq 0x68(%rsp), %rdi
pushq $0x8
popq %rdx
pushq $0xe
popq %r8
callq 0x1e1ce
leaq 0x183c9(%rip), %rsi     # 0x1f085
leaq 0xe0(%rsp), %rdi
leaq 0x128(%rsp), %rdx
callq 0x6150
leaq 0x183b7(%rip), %rsi     # 0x1f08f
leaq 0x128(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x6150
movq 0xe0(%rsp), %rsi
movq 0x128(%rsp), %rcx
leaq 0x68(%rsp), %rdi
pushq $0x9
popq %rdx
pushq $0xb
popq %r8
callq 0x1e1ce
leaq 0x18386(%rip), %rsi     # 0x1f09b
leaq 0x1838a(%rip), %rcx     # 0x1f0a6
leaq 0x68(%rsp), %rdi
pushq $0xa
popq %rdx
pushq $0x6
popq %r8
callq 0x1e1ce
leaq 0x18379(%rip), %rsi     # 0x1f0ad
leaq 0x1837d(%rip), %rcx     # 0x1f0b8
leaq 0x68(%rsp), %rdi
pushq $0xa
popq %rdx
pushq $0x6
popq %r8
callq 0x1e1ce
leaq 0x1836c(%rip), %rsi     # 0x1f0bf
leaq 0x18370(%rip), %rcx     # 0x1f0ca
leaq 0x68(%rsp), %rdi
pushq $0xa
popq %rdx
pushq $0x6
popq %r8
callq 0x1e1ce
leaq 0x1835f(%rip), %rsi     # 0x1f0d1
leaq 0x18363(%rip), %rcx     # 0x1f0dc
leaq 0x68(%rsp), %rdi
pushq $0xa
popq %rdx
pushq $0x6
popq %r8
callq 0x1e1ce
leaq 0x18352(%rip), %rsi     # 0x1f0e3
leaq 0x18356(%rip), %rcx     # 0x1f0ee
leaq 0x68(%rsp), %rdi
pushq $0xa
popq %rdx
pushq $0x6
popq %r8
callq 0x1e1ce
leaq 0x18345(%rip), %rsi     # 0x1f0f5
leaq 0x18349(%rip), %rcx     # 0x1f100
leaq 0x68(%rsp), %rdi
pushq $0xa
popq %rdx
pushq $0x6
popq %r8
callq 0x1e1ce
leaq 0x18338(%rip), %rsi     # 0x1f107
leaq 0x1833c(%rip), %rcx     # 0x1f112
leaq 0x68(%rsp), %rdi
pushq $0xa
popq %rdx
pushq $0x6
popq %r8
callq 0x1e1ce
movq 0xc0(%rsp), %rsi
leaq 0x68(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x1e23c
leaq 0xa0(%rsp), %rdi
leaq 0x68(%rsp), %rdx
movq %r15, %rsi
callq 0x11632
movups 0xa0(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
leaq 0x18303(%rip), %rax     # 0x1f12d
leaq 0x182e8(%rip), %rsi     # 0x1f119
cmoveq %rax, %rsi
movq 0x2b194(%rip), %rdi     # 0x31fd0
callq 0x6400
movq %rax, %rdi
callq 0x61c0
movq 0xc0(%rsp), %rdx
leaq 0xa0(%rsp), %rdi
pushq $0x8
popq %rcx
leaq 0x80(%rsp), %r8
movq %r15, %rsi
callq 0x1143c
movups 0xa0(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
je 0x6e95
movq 0x2b149(%rip), %rdi     # 0x31fd0
leaq 0x181b8(%rip), %rsi     # 0x1f046
callq 0x6400
jmp 0x6eb8
movq 0x2b134(%rip), %rdi     # 0x31fd0
leaq 0x181ae(%rip), %rsi     # 0x1f051
callq 0x6400
leaq 0x80(%rsp), %rsi
movq %rax, %rdi
callq 0x63b0
movq %rax, %rdi
callq 0x61c0
movq 0xe0(%rsp), %rdx
leaq 0xa0(%rsp), %rdi
pushq $0x9
popq %rcx
leaq 0x80(%rsp), %r8
movq %r15, %rsi
callq 0x1143c
movups 0xa0(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
je 0x6f0c
movq 0x2b0d2(%rip), %rdi     # 0x31fd0
leaq 0x18141(%rip), %rsi     # 0x1f046
callq 0x6400
jmp 0x6f2f
movq 0x2b0bd(%rip), %rdi     # 0x31fd0
leaq 0x18137(%rip), %rsi     # 0x1f051
callq 0x6400
leaq 0x80(%rsp), %rsi
movq %rax, %rdi
callq 0x63b0
movq %rax, %rdi
callq 0x61c0
movq %r15, %rdi
callq 0x10da8
movq %rax, %r14
testq %rax, %rax
je 0x70c8
movq 0x2b07e(%rip), %rdi     # 0x31fd0
leaq 0x181e9(%rip), %rsi     # 0x1f142
callq 0x6400
movq %rax, %rdi
callq 0x61c0
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq %r15, 0x100(%rsp)
leaq 0xa0(%rsp), %r15
movq 0x2b04a(%rip), %r12     # 0x31fd0
leaq 0x18bc4(%rip), %r13     # 0x1fb51
leaq 0x148(%rsp), %rbp
movq (%r14), %rax
movq %r14, %rdi
callq *0x48(%rax)
testb %al, %al
je 0x7001
movq (%r14), %rax
movq %r15, %rdi
movq %r14, %rsi
callq *0x38(%rax)
movq %r12, %rdi
movq %r15, %rsi
callq 0x63b0
movq %rax, %rdi
movq %r13, %rsi
callq 0x6400
movq %rax, %rbx
movq (%r14), %rax
movq %rbp, %rdi
movq %r14, %rsi
callq *0x40(%rax)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x63b0
movq %rax, %rdi
callq 0x61c0
movq %rbp, %rdi
callq 0x6788
movq %r15, %rdi
callq 0x6788
movq (%r14), %rax
movq %r14, %rdi
callq *0x28(%rax)
jmp 0x6f95
pushq $0x3
popq %rdi
callq 0x6330
movq 0x2afc0(%rip), %rdi     # 0x31fd0
leaq 0x1814a(%rip), %rsi     # 0x1f161
callq 0x6400
movq %rax, %rdi
callq 0x61c0
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
leaq 0xa0(%rsp), %r15
movq 0x2af94(%rip), %r12     # 0x31fd0
leaq 0x18b0e(%rip), %r13     # 0x1fb51
leaq 0x148(%rsp), %rbp
movq (%r14), %rax
movq %r14, %rdi
callq *0x48(%rax)
testb %al, %al
je 0x70b7
movq (%r14), %rax
movq %r15, %rdi
movq %r14, %rsi
callq *0x38(%rax)
movq %r12, %rdi
movq %r15, %rsi
callq 0x63b0
movq %rax, %rdi
movq %r13, %rsi
callq 0x6400
movq %rax, %rbx
movq (%r14), %rax
movq %rbp, %rdi
movq %r14, %rsi
callq *0x40(%rax)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x63b0
movq %rax, %rdi
callq 0x61c0
movq %rbp, %rdi
callq 0x6788
movq %r15, %rdi
callq 0x6788
movq (%r14), %rax
movq %r14, %rdi
callq *0x30(%rax)
jmp 0x704b
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
movq 0x100(%rsp), %r15
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
leaq 0x128(%rsp), %rdi
callq 0x6788
leaq 0xe0(%rsp), %rdi
callq 0x6788
leaq 0x68(%rsp), %rdi
callq 0x1e182
leaq 0x80(%rsp), %rdi
callq 0x6788
leaq 0x108(%rsp), %rdi
callq 0x6788
leaq 0xc0(%rsp), %rdi
callq 0x6788
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7192
jmp 0x7192
jmp 0x7192
movq %rax, %rbx
jmp 0x71a2
jmp 0x713b
movq %rax, %rbx
jmp 0x71af
jmp 0x7152
jmp 0x7152
jmp 0x7152
jmp 0x7157
jmp 0x7157
movq %rax, %rbx
jmp 0x71d3
movq %rax, %rbx
jmp 0x71b9
movq %rax, %rbx
jmp 0x71c6
jmp 0x7192
jmp 0x7192
jmp 0x716c
jmp 0x7192
jmp 0x716c
jmp 0x7192
jmp 0x716c
jmp 0x7171
movq %rax, %rbx
jmp 0x7181
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x6788
leaq 0xa0(%rsp), %rdi
callq 0x6788
jmp 0x7195
jmp 0x7192
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x6788
leaq 0xe0(%rsp), %rdi
callq 0x6788
leaq 0x68(%rsp), %rdi
callq 0x1e182
leaq 0x80(%rsp), %rdi
callq 0x6788
leaq 0x108(%rsp), %rdi
callq 0x6788
leaq 0xc0(%rsp), %rdi
callq 0x6788
movq %rbx, %rdi
callq 0x6680