// File: wwdatabase[P]database/./rcdmana/rm.h
// Function: RecordManager::openFile(char const*, RM_FileHandle&)
RC RecordManager::openFile(const char *fileName, RM_FileHandle &fileHandle) {
    fileHandle.fileName = fileName;
    if (!pfm->openFile(fileName, fileHandle.fileID)){
        cout << "error open file : " << fileName << endl;
        return 103;
    }
    cout << endl;
    cout << ">>> open file " << fileName << " sucessfully." << endl;
    fileHandle.bufType = bpm->getPage(fileHandle.fileID, 
                                        fileHandle.pageID,
                                        fileHandle.index);
    BufType b = fileHandle.bufType;
    fileHandle.init();
    cout << "******file " << fileName << " info******" << endl;
    int offset = 0;
    cout << "* record size : " << b[offset] << "\n" ;
    fileHandle.recordSize = b[offset ++ ];
    fileHandle.attrNum = b[offset ++];
    fileHandle.priKeyNum = b[offset ++];
    for (int i = 0; i < fileHandle.attrNum; ++i) {
        fileHandle.attrType.push_back(b[offset ++]);
        fileHandle.attrLength.push_back(b[offset ++]);
        fileHandle.isNull.push_back(b[offset ++]);
    }
    cout << "* record number in each page : " << b[offset] << "\n" ;
    fileHandle.recordNumForEachPage = b[offset ++];
    cout << "* tags map size in each page : " << b[offset] << "\n" ;
    fileHandle.tagSize = b[offset ++];
    cout << "* record number for total pages : " << b[offset] << "\n";
    fileHandle.recordNumForAllPages = b[offset ++];
    cout << "* bitmap size : " << b[offset]*8 << "\n" ;
    fileHandle.bitmapSize = b[offset ++];
    fileHandle.bitmap = b + offset;
    
    cout << "* bitmap : " ;
    unsigned int bitmap;
    for (int i = 0; i < fileHandle.bitmapSize; ++i) {
        bitmap = b[offset+i];
        for (int j = 0; j < 8; ++j) {
            cout << (bitmap & (1 << j));
        }
    }
    cout << endl;
    cout << "******end file info************" << endl;
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq %rdx, (%rcx)
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq $0x8, %rdx
callq 0x5470
testb $0x1, %al
jne 0x3769
movq 0xa8a2(%rip), %rdi      # 0xdfd8
leaq 0x59b3(%rip), %rsi      # 0x90f0
callq 0x21c0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x21c0
movq %rax, %rdi
movq 0xa870(%rip), %rsi      # 0xdfc8
callq 0x2200
movl $0x67, -0x4(%rbp)
jmp 0x3b85
movq 0xa868(%rip), %rdi      # 0xdfd8
movq 0xa851(%rip), %rsi      # 0xdfc8
callq 0x2200
movq 0xa855(%rip), %rdi      # 0xdfd8
leaq 0x59e5(%rip), %rsi      # 0x916f
callq 0x21c0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x21c0
movq %rax, %rdi
leaq 0x5ac4(%rip), %rsi      # 0x9269
callq 0x21c0
movq %rax, %rdi
movq 0xa814(%rip), %rsi      # 0xdfc8
callq 0x2200
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x20(%rbp), %rax
movl 0x78(%rax), %edx
movq -0x20(%rbp), %rcx
addq $0x88, %rcx
callq 0x4ea0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x26f0
movq 0xa7cc(%rip), %rdi      # 0xdfd8
leaq 0x596b(%rip), %rsi      # 0x917e
callq 0x21c0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x21c0
movq %rax, %rdi
leaq 0x595c(%rip), %rsi      # 0x918a
callq 0x21c0
movq %rax, %rdi
movq 0xa78b(%rip), %rsi      # 0xdfc8
callq 0x2200
movl $0x0, -0x2c(%rbp)
movq 0xa788(%rip), %rdi      # 0xdfd8
leaq 0x593f(%rip), %rsi      # 0x9196
callq 0x21c0
movq %rax, %rdi
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x2290
movq %rax, %rdi
leaq 0x592e(%rip), %rsi      # 0x91a7
callq 0x21c0
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x14(%rax)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x3972
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
leaq -0x34(%rbp), %rsi
callq 0x5740
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
leaq -0x38(%rbp), %rsi
callq 0x5740
movq -0x20(%rbp), %rdi
addq $0x48, %rdi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
leaq -0x3c(%rbp), %rsi
callq 0x5740
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x38d9
movq 0xa65f(%rip), %rdi      # 0xdfd8
leaq 0x5829(%rip), %rsi      # 0x91a9
callq 0x21c0
movq %rax, %rdi
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x2290
movq %rax, %rdi
leaq 0x5805(%rip), %rsi      # 0x91a7
callq 0x21c0
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x64(%rax)
movq 0xa60e(%rip), %rdi      # 0xdfd8
leaq 0x57f8(%rip), %rsi      # 0x91c9
callq 0x21c0
movq %rax, %rdi
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x2290
movq %rax, %rdi
leaq 0x57b4(%rip), %rsi      # 0x91a7
callq 0x21c0
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x60(%rax)
movq 0xa5bd(%rip), %rdi      # 0xdfd8
leaq 0x57c7(%rip), %rsi      # 0x91e9
callq 0x21c0
movq %rax, %rdi
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x2290
movq %rax, %rdi
leaq 0x5763(%rip), %rsi      # 0x91a7
callq 0x21c0
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x68(%rax)
movq 0xa56c(%rip), %rdi      # 0xdfd8
leaq 0x5799(%rip), %rsi      # 0x920c
callq 0x21c0
movq %rax, %rdi
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
shll $0x3, %esi
callq 0x2290
movq %rax, %rdi
leaq 0x570f(%rip), %rsi      # 0x91a7
callq 0x21c0
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x28(%rbp), %rcx
movslq -0x2c(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x70(%rax)
movq 0xa501(%rip), %rdi      # 0xdfd8
leaq 0x573f(%rip), %rsi      # 0x921d
callq 0x21c0
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x6c(%rcx), %eax
jge 0x3b49
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl -0x44(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x48(%rbp)
cmpl $0x8, -0x48(%rbp)
jge 0x3b3c
movl -0x40(%rbp), %esi
movl -0x48(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
andl %eax, %esi
movq 0xa4ac(%rip), %rdi      # 0xdfd8
callq 0x2290
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x3b10
jmp 0x3b3e
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x3aea
movq 0xa488(%rip), %rdi      # 0xdfd8
movq 0xa471(%rip), %rsi      # 0xdfc8
callq 0x2200
movq 0xa475(%rip), %rdi      # 0xdfd8
leaq 0x56bf(%rip), %rsi      # 0x9229
callq 0x21c0
movq %rax, %rdi
movq 0xa44f(%rip), %rsi      # 0xdfc8
callq 0x2200
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop