// File: /workspace/github_cpp_makefile_star2_O1/wwdatabase[P]database/./rcdmana/rm.h
// Function: RecordManager::createFile(char const*, int, std::vector<int, std::allocator<int>>, std::vector<int, std::allocator<int>>, std::vector<int, std::allocator<int>>, int)
RC RecordManager::createFile(const char *fileName,
                            int recordSize,
                            vector<int> attrType,
                            vector<int> attrLength,
                            vector<int> isNull,
                            int priKeyNum) {
    if (!pfm->createFile(fileName)){
        cout << "create file error!" << endl;
    }
    cout << ">>> create file " << fileName << " sucessfully." << endl;

    /* init */
    int fileID;
    if (!pfm->openFile(fileName, fileID)){
        cout << "error open file : " << fileName << endl;
        return 103;
    }
    uint b[2048];

    /* set record size. */
    int offset = 0;
    b[offset ++] = recordSize;

    /* set attr num. */
    int attrNum = attrType.size();
    b[offset ++] = attrNum;

    /* set primary key num. */
    b[offset ++] = priKeyNum;

    for (int i = 0; i < attrNum; ++i) {
        b[offset ++] = attrType[i];
        b[offset ++] = attrLength[i];
        b[offset ++] = isNull[i];
    }

    /* set record log number for each page. */
    double par = recordSize + 1.0 / 8; 
    int rcdTop = (PAGE_SIZE - 1) / par;
    if (rcdTop == 0){
        cout << "record size is too large" << endl;
        return 105;
    }
    else
        b[offset++] = rcdTop;

    /* set record tag size with bit map in each page. */
    int tagSize = rcdTop / 8 + 1;
    if (rcdTop * recordSize + tagSize + 3 > PAGE_SIZE) {
        cout << "error attribute tags map !" << endl;
    }
    b[offset++] = tagSize;

    /* set record log number for all pages. */
    int rcdNum = 0;
    b[offset++] = rcdNum;

    /* set bitmap size (devided by 8 by default). */
    b[offset++] = 4;

    /* set page bit map in file, init with 32 pages' map. */
    unsigned int &bitmap = b[offset++];
    bitmap = 0;
    /*for (int i = 0; i < 32; ++i)
        bitmap &= ~(1 << i); // set i bit zero
     */

    if (offset > 2047) {
        cout << "Data Bomb!!!" << endl;
        return 110;
    }

    pfm->writePage(fileID, 0, b, 0);

    /* output file init info */
    RM_FileHandle fileHandle(this->pfm, this->bpm);
    openFile(fileName, fileHandle);
    closeFile(fileHandle);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20b8, %rsp           # imm = 0x20B8
movq %r9, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %rcx, %r13
movl %edx, %r12d
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdi), %rdi
callq 0x5008
movq 0x6223(%rip), %r15      # 0x8fd8
leaq 0x32f4(%rip), %rsi      # 0x60b0
movl $0x10, %edx
movq %r15, %rdi
callq 0x2170
testq %rbx, %rbx
je 0x2dea
movq %rbx, %rdi
callq 0x2070
movq 0x61fb(%rip), %rdi      # 0x8fd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2170
jmp 0x2e02
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x21e0
leaq 0x3431(%rip), %rsi      # 0x623a
movl $0xd, %edx
movq %r15, %rdi
callq 0x2170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movq (%r14), %rdi
leaq -0x3c(%rbp), %rdx
movq %rbx, %rsi
callq 0x485c
testb %al, %al
je 0x2ecb
movl 0x10(%rbp), %edx
movl %r12d, -0x20e0(%rbp)
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movl %ecx, -0x20dc(%rbp)
movl %edx, -0x20d8(%rbp)
testl %ecx, %ecx
jle 0x2f0e
movq -0x38(%rbp), %rdx
movq (%rdx), %rdx
movq -0x30(%rbp), %rsi
movq (%rsi), %rsi
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl $0x3, %r13d
xorl %edi, %edi
movl (%rax,%rdi,4), %r8d
movl %r8d, -0x20e0(%rbp,%r13,4)
movl (%rdx,%rdi,4), %r8d
movl %r8d, -0x20dc(%rbp,%r13,4)
movl (%rsi,%rdi,4), %r8d
movl %r8d, -0x20d8(%rbp,%r13,4)
addq $0x3, %r13
incq %rdi
cmpq %rdi, %rcx
jne 0x2e99
jmp 0x2f14
movq 0x6106(%rip), %r14      # 0x8fd8
leaq 0x31e8(%rip), %rsi      # 0x60c1
movl $0x12, %edx
movq %r14, %rdi
callq 0x2170
testq %rbx, %rbx
je 0x3029
movq %rbx, %rdi
callq 0x2070
movq 0x60da(%rip), %rdi      # 0x8fd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2170
jmp 0x3041
movl $0x3, %r13d
cvtsi2sd %r12d, %xmm0
addsd 0x30e7(%rip), %xmm0     # 0x6008
movsd 0x30e7(%rip), %xmm1     # 0x6010
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
testl %eax, %eax
je 0x3072
movq %r14, -0x30(%rbp)
leal 0x1(%r13), %edx
movl %r13d, %r14d
movl %eax, -0x20e0(%rbp,%r14,4)
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x3, %ecx
imull %eax, %r12d
leal (%rcx,%r12), %eax
incl %eax
movl %ecx, %r12d
incl %r12d
cmpl $0x1ffe, %eax           # imm = 0x1FFE
jl 0x2faf
leaq 0x3178(%rip), %rsi      # 0x60ed
movl %edx, -0x38(%rbp)
movl $0x1a, %edx
movq %r15, %rdi
callq 0x2170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movl -0x38(%rbp), %edx
movl %edx, %eax
movl %r12d, -0x20e0(%rbp,%rax,4)
movabsq $0x400000000, %rax      # imm = 0x400000000
movq %rax, -0x20d8(%rbp,%r14,4)
movl $0x0, -0x20d0(%rbp,%r14,4)
cmpl $0x7fb, %r13d           # imm = 0x7FB
jb 0x30b7
leaq 0x311d(%rip), %rsi      # 0x6108
movl $0xc, %edx
movq %r15, %rdi
callq 0x2170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movl $0x6e, %eax
jmp 0x31ab
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x21e0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movl $0x67, %eax
jmp 0x31ab
leaq 0x305b(%rip), %rsi      # 0x60d4
movl $0x18, %edx
movq %r15, %rdi
callq 0x2170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movl $0x69, %eax
jmp 0x31ab
movq -0x30(%rbp), %r15
movq (%r15), %rdi
movl -0x3c(%rbp), %esi
leaq -0x20e0(%rbp), %rcx
xorl %r14d, %r14d
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x48b6
movq (%r15), %rax
movq 0x8(%r15), %rcx
movq %r14, -0x60(%rbp)
movq %r14, -0x70(%rbp)
movl %r14d, -0x68(%rbp)
movl %r14d, -0x58(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0xd0(%rbp)
movapd %xmm0, -0xc0(%rbp)
movapd %xmm0, -0xe0(%rbp)
movapd %xmm0, -0xb0(%rbp)
movapd %xmm0, -0xa0(%rbp)
movapd %xmm0, -0x90(%rbp)
movq -0xc8(%rbp), %rdx
cmpq %rdx, -0xc0(%rbp)
je 0x3137
movq %rdx, -0xc0(%rbp)
movq -0xb0(%rbp), %rdx
cmpq %rdx, -0xa8(%rbp)
je 0x314e
movq %rdx, -0xa8(%rbp)
movq -0x98(%rbp), %rdx
cmpq %rdx, -0x90(%rbp)
movq -0x30(%rbp), %r14
je 0x3169
movq %rdx, -0x90(%rbp)
leaq -0xe0(%rbp), %rdx
movapd %xmm0, 0x60(%rdx)
movq %rax, 0x90(%rdx)
movq %rcx, 0x98(%rdx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x31d4
leaq -0xe0(%rbp), %rsi
movq %r14, %rdi
callq 0x36d4
leaq -0xe0(%rbp), %rdi
callq 0x24c0
xorl %eax, %eax
addq $0x20b8, %rsp           # imm = 0x20B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x24c0
movq %rbx, %rdi
callq 0x2200