// File: /workspace/github_cpp_makefile_star2_O3/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, -0x38(%rbp)
movq %r8, -0x30(%rbp)
movq %rcx, %r13
movl %edx, %r12d
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdi), %rdi
callq 0x4ec8
movq 0x6265(%rip), %r15      # 0x8fd8
leaq 0x3336(%rip), %rsi      # 0x60b0
movl $0x10, %edx
movq %r15, %rdi
callq 0x2170
testq %rbx, %rbx
je 0x2da8
movq %rbx, %rdi
callq 0x2070
movq 0x623d(%rip), %rdi      # 0x8fd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2170
jmp 0x2dc0
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x21e0
leaq 0x3473(%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 0x4762
testb %al, %al
je 0x2e89
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 0x2ecc
movq -0x30(%rbp), %rdx
movq (%rdx), %rdx
movq -0x38(%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 0x2e57
jmp 0x2ed2
movq 0x6148(%rip), %r14      # 0x8fd8
leaq 0x322a(%rip), %rsi      # 0x60c1
movl $0x12, %edx
movq %r14, %rdi
callq 0x2170
testq %rbx, %rbx
je 0x2fe7
movq %rbx, %rdi
callq 0x2070
movq 0x611c(%rip), %rdi      # 0x8fd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2170
jmp 0x2fff
movl $0x3, %r13d
cvtsi2sd %r12d, %xmm0
addsd 0x3129(%rip), %xmm0     # 0x6008
movsd 0x3129(%rip), %xmm1     # 0x6010
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
testl %eax, %eax
je 0x3030
movq %r14, -0x38(%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 0x2f6d
leaq 0x31ba(%rip), %rsi      # 0x60ed
movl %edx, -0x30(%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 -0x30(%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 0x3075
leaq 0x315f(%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 0x310c
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 0x310c
leaq 0x309d(%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 0x310c
movq -0x38(%rbp), %r14
movq (%r14), %rdi
movl -0x3c(%rbp), %esi
leaq -0x20e0(%rbp), %rcx
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x47bc
movupd (%r14), %xmm0
leaq -0xe0(%rbp), %rdx
movq $0x0, 0x80(%rdx)
movl $0x0, 0x88(%rdx)
xorpd %xmm1, %xmm1
movapd %xmm1, (%rdx)
movapd %xmm1, 0x10(%rdx)
movapd %xmm1, 0x20(%rdx)
movapd %xmm1, 0x30(%rdx)
movapd %xmm1, 0x40(%rdx)
movapd %xmm1, 0x50(%rdx)
movapd %xmm1, 0x60(%rdx)
movupd %xmm1, 0x6c(%rdx)
movapd %xmm0, 0x90(%rdx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3136
leaq -0xe0(%rbp), %rsi
movq %r14, %rdi
callq 0x3648
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
nop