// File: wwdatabase[P]database/testrcdmana.cpp
// Function: main
int main() {
    RecordManager *prm = RecordManager::getInstance();
    const char *fileName = "database.txt";
    vector<int> attrType, attrLength, isNull;
    for (int i = 0; i < 3; ++i) {
        attrType.push_back(1);
        attrLength.push_back(4);
        isNull.push_back(1);
    }
    prm->createFile(fileName, 12, attrType, attrLength, isNull, 1);

    RM_FileHandle fileHandle(prm->pfm, prm->bpm);
    prm->openFile(fileName, fileHandle);
    RID rid;
    /*prm->fileHandle->insertRec("123451345512", rid);
    cout << rid << endl;
    prm->fileHandle->insertRec("123451345512", rid);
    cout << rid << endl;
    prm->fileHandle->insertRec("This is one ", rid);
    prm->fileHandle->insertRec("123451345512", rid);
    prm->fileHandle->insertRec("123451345512", rid);
*/
    RM_Record rec;
    /*prm->fileHandle->getRec(rid, rec);
    cout << string(rec.data) << endl;

    rec.setData("this is another case");
    prm->fileHandle->updateRec(rec);

    prm->fileHandle->getRec(rid, rec);
    cout << string(rec.data) << endl;

    prm->fileHandle->deleteRec(rid);
    prm->fileHandle->insertRec("33333333333333333333", rid);
*/
    int b = 40100200;
    char data[12];
    strcpy(data, "abcd");
    for (int i = 0; i < 4; ++i) {
        char t = *((char*)(&b)+i);
        cout << t << " ddd" << endl;
        strcat(data, &t);
        cout << data << " ddd " << strlen(data) << endl;
    }
    strcat(data, "1234");
    cout << "size : " << strlen(data) << endl;
    fileHandle.insertRec(data, rid);
    b = 20; 
    strcpy(data, "1111");
    for (int i = 0; i < 4; ++i) {
        strcat(data, (char*)(&b)+i);
    }
    strcat(data, "3333");
    fileHandle.insertRec(data, rid);
    // a = {'a', 'b', 'c', 'd'}; 
    b = 345; 
    // c = {'a', 'b', 'c', 'd'};
    strcpy(data, "2222");
    for (int i = 0; i < 4; ++i) {
        strcat(data, (char*)(&b)+i);
    }
    strcat(data, "6666");
    fileHandle.insertRec(data, rid);

    RM_FileScan fs;
    b = 40100200;
    void* value = (void*)(&b);
    fs.openScan(fileHandle,
                ATTRINT,
                4,
                4,
                GT_OP,
                value);
    fs.getNextRec(rec);
    if (!rec.empty()) {
        cout << string(rec.data) << " , " << rec.rid << endl;
    }
    fs.closeScan();

    prm->closeFile(fileHandle);

    prm->destroyFile(fileName);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movl $0x0, -0x4(%rbp)
callq 0x5960
movq %rax, -0x10(%rbp)
leaq 0x4ca0(%rip), %rax      # 0x9332
movq %rax, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4e00
leaq -0x48(%rbp), %rdi
callq 0x4e00
leaq -0x60(%rbp), %rdi
callq 0x4e00
movl $0x0, -0x64(%rbp)
cmpl $0x3, -0x64(%rbp)
jge 0x471e
movl $0x1, -0x68(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x5740
jmp 0x46d4
movl $0x4, -0x78(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x5740
jmp 0x46ea
movl $0x1, -0x7c(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x7c(%rbp), %rsi
callq 0x5740
jmp 0x4700
jmp 0x4702
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x46b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x4dcf
movq -0x10(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x218(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x59d0
jmp 0x4746
leaq -0xb0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x59d0
jmp 0x4758
leaq -0xc8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x59d0
jmp 0x476a
movq -0x218(%rbp), %rsi
movq -0x220(%rbp), %rdi
movq %rsp, %rax
movl $0x1, (%rax)
movl $0xc, %edx
leaq -0x98(%rbp), %rcx
leaq -0xb0(%rbp), %r8
leaq -0xc8(%rbp), %r9
callq 0x3240
jmp 0x47a2
leaq -0xc8(%rbp), %rdi
callq 0x4e20
leaq -0xb0(%rbp), %rdi
callq 0x4e20
leaq -0x98(%rbp), %rdi
callq 0x4e20
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq -0x168(%rbp), %rdi
callq 0x2550
jmp 0x47df
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0x36f0
jmp 0x47f5
leaq -0x170(%rbp), %rdi
callq 0x5840
jmp 0x4803
leaq -0x180(%rbp), %rdi
callq 0x5810
jmp 0x4811
movl $0x263e168, -0x184(%rbp) # imm = 0x263E168
leaq -0x190(%rbp), %rdi
leaq 0x4b16(%rip), %rsi      # 0x933f
callq 0x21b0
movl $0x0, -0x194(%rbp)
cmpl $0x4, -0x194(%rbp)
jge 0x49cb
movslq -0x194(%rbp), %rax
movb -0x184(%rbp,%rax), %al
movb %al, -0x195(%rbp)
movsbl -0x195(%rbp), %esi
movq 0x9771(%rip), %rdi      # 0xdfd8
callq 0x2250
movq %rax, -0x228(%rbp)
jmp 0x4875
movq -0x228(%rbp), %rdi
leaq 0x4ac1(%rip), %rsi      # 0x9344
callq 0x21c0
movq %rax, -0x230(%rbp)
jmp 0x4891
movq -0x230(%rbp), %rdi
movq 0x9729(%rip), %rsi      # 0xdfc8
callq 0x2200
jmp 0x48a6
leaq -0x190(%rbp), %rdi
movq %rdi, -0x240(%rbp)
leaq -0x195(%rbp), %rsi
callq 0x2330
movq -0x240(%rbp), %rsi
movq 0x970a(%rip), %rdi      # 0xdfd8
callq 0x21c0
movq %rax, -0x238(%rbp)
jmp 0x48dc
movq -0x238(%rbp), %rdi
leaq 0x4a5f(%rip), %rsi      # 0x9349
callq 0x21c0
movq %rax, -0x248(%rbp)
jmp 0x48f8
leaq -0x190(%rbp), %rdi
callq 0x20c0
movq -0x248(%rbp), %rdi
movq %rax, %rsi
callq 0x2050
movq %rax, -0x250(%rbp)
jmp 0x491c
movq -0x250(%rbp), %rdi
movq 0x969e(%rip), %rsi      # 0xdfc8
callq 0x2200
jmp 0x4931
jmp 0x4933
movl -0x194(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x194(%rbp)
jmp 0x4838
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x4987
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x497b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x4e20
leaq -0xb0(%rbp), %rdi
callq 0x4e20
leaq -0x98(%rbp), %rdi
callq 0x4e20
jmp 0x4dcf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x4dc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x4db7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x4dab
leaq 0x497d(%rip), %rsi      # 0x934f
leaq -0x190(%rbp), %rdi
callq 0x2330
movq 0x95f3(%rip), %rdi      # 0xdfd8
leaq 0x47b3(%rip), %rsi      # 0x919f
callq 0x21c0
movq %rax, -0x258(%rbp)
jmp 0x49fa
leaq -0x190(%rbp), %rdi
callq 0x20c0
movq -0x258(%rbp), %rdi
movq %rax, %rsi
callq 0x2050
movq %rax, -0x260(%rbp)
jmp 0x4a1e
movq -0x260(%rbp), %rdi
movq 0x959c(%rip), %rsi      # 0xdfc8
callq 0x2200
jmp 0x4a33
leaq -0x168(%rbp), %rdi
leaq -0x190(%rbp), %rsi
leaq -0x170(%rbp), %rdx
callq 0x2890
jmp 0x4a4f
movl $0x14, -0x184(%rbp)
leaq -0x190(%rbp), %rdi
leaq 0x48ed(%rip), %rsi      # 0x9354
callq 0x21b0
movl $0x0, -0x19c(%rbp)
cmpl $0x4, -0x19c(%rbp)
jge 0x4aad
leaq -0x190(%rbp), %rdi
movslq -0x19c(%rbp), %rax
leaq -0x184(%rbp), %rsi
addq %rax, %rsi
callq 0x2330
movl -0x19c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x19c(%rbp)
jmp 0x4a76
leaq 0x48a5(%rip), %rsi      # 0x9359
leaq -0x190(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x2330
movq -0x268(%rbp), %rsi
leaq -0x168(%rbp), %rdi
leaq -0x170(%rbp), %rdx
callq 0x2890
jmp 0x4ae3
movl $0x159, -0x184(%rbp)    # imm = 0x159
leaq -0x190(%rbp), %rdi
leaq 0x4863(%rip), %rsi      # 0x935e
callq 0x21b0
movl $0x0, -0x1a0(%rbp)
cmpl $0x4, -0x1a0(%rbp)
jge 0x4b41
leaq -0x190(%rbp), %rdi
movslq -0x1a0(%rbp), %rax
leaq -0x184(%rbp), %rsi
addq %rax, %rsi
callq 0x2330
movl -0x1a0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a0(%rbp)
jmp 0x4b0a
leaq 0x481b(%rip), %rsi      # 0x9363
leaq -0x190(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x2330
movq -0x270(%rbp), %rsi
leaq -0x168(%rbp), %rdi
leaq -0x170(%rbp), %rdx
callq 0x2890
jmp 0x4b77
leaq -0x1e0(%rbp), %rdi
callq 0x3eb0
jmp 0x4b85
movl $0x263e168, -0x184(%rbp) # imm = 0x263E168
leaq -0x184(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x1e8(%rbp), %rcx
movq %rsp, %rax
movq %rcx, (%rax)
leaq -0x1e0(%rbp), %rdi
leaq -0x168(%rbp), %rsi
movl $0x1, %edx
movl $0x4, %r8d
movl $0x3, %r9d
movl %r8d, %ecx
callq 0x3f40
jmp 0x4bd3
leaq -0x1e0(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x4070
jmp 0x4be8
leaq -0x180(%rbp), %rdi
callq 0x5ac0
movb %al, -0x271(%rbp)
jmp 0x4bfc
movb -0x271(%rbp), %al
testb $0x1, %al
jne 0x4d14
jmp 0x4c0c
movq -0x180(%rbp), %rax
movq %rax, -0x288(%rbp)
leaq -0x209(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x2320
movq -0x288(%rbp), %rsi
movq -0x280(%rbp), %rdx
leaq -0x208(%rbp), %rdi
callq 0x5070
jmp 0x4c49
movq 0x9388(%rip), %rdi      # 0xdfd8
leaq -0x208(%rbp), %rsi
callq 0x21a0
movq %rax, -0x290(%rbp)
jmp 0x4c65
movq -0x290(%rbp), %rdi
leaq 0x46f5(%rip), %rsi      # 0x9368
callq 0x21c0
movq %rax, -0x298(%rbp)
jmp 0x4c81
movq -0x298(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x24e0
movq %rax, -0x2a0(%rbp)
jmp 0x4c9d
movq -0x2a0(%rbp), %rdi
movq 0x931d(%rip), %rsi      # 0xdfc8
callq 0x2200
jmp 0x4cb2
leaq -0x208(%rbp), %rdi
callq 0x2110
leaq -0x209(%rbp), %rdi
callq 0x2220
jmp 0x4d14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x4d9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x4d03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x2110
leaq -0x209(%rbp), %rdi
callq 0x2220
jmp 0x4d9f
leaq -0x1e0(%rbp), %rdi
callq 0x4650
movq -0x10(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x3b90
jmp 0x4d32
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3e10
jmp 0x4d41
movl $0x0, -0x4(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x3f10
leaq -0x180(%rbp), %rdi
callq 0x5850
leaq -0x170(%rbp), %rdi
callq 0x58a0
leaq -0x168(%rbp), %rdi
callq 0x26b0
leaq -0x60(%rbp), %rdi
callq 0x4e20
leaq -0x48(%rbp), %rdi
callq 0x4e20
leaq -0x30(%rbp), %rdi
callq 0x4e20
movl -0x4(%rbp), %eax
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
leaq -0x1e0(%rbp), %rdi
callq 0x3f10
leaq -0x180(%rbp), %rdi
callq 0x5850
leaq -0x170(%rbp), %rdi
callq 0x58a0
leaq -0x168(%rbp), %rdi
callq 0x26b0
leaq -0x60(%rbp), %rdi
callq 0x4e20
leaq -0x48(%rbp), %rdi
callq 0x4e20
leaq -0x30(%rbp), %rdi
callq 0x4e20
movq -0x70(%rbp), %rdi
callq 0x2310
nopw %cs:(%rax,%rax)
nopl (%rax)