// File: /workspace/github_cpp_makefile_star2_O1/Konano[P]UselessDatabase/Table.cpp
// Function: Table::rebuild(int, unsigned int)
void Table::rebuild(int ty, uint col_id) {
    if (record_num == 0) return;
    int _main_file;
    fm->createFile(dirPath(db->name, name, "tmp", "usid"));
    fm->openFile(dirPath(db->name, name, "tmp", "usid"), _main_file);
    uint _record_size, _record_onepg;
    int index;
    BufType buf, _buf, buf_st, _buf_st;
    switch (ty) {
    case 0: // del
        _record_size = record_size - col_ty[col_id].size();
        _record_onepg = 0;
        while ((_record_onepg + 1) * _record_size + _record_onepg / 8 + 1 <= PAGE_SIZE) _record_onepg++;
        for (uint i = 0; i < record_num; i++) {
            if (i % record_onepg == 0) {
                buf_st = buf = bpm->getPage(main_file, i / record_onepg);
                buf += (record_onepg - 1) / 8 + 1;
            }
            if (i % _record_onepg == 0) {
                _buf_st = _buf = bpm->getPage(_main_file, i / _record_onepg, index);
                _buf += (_record_onepg - 1) / 8 + 1;
            }
            
            if (exist(buf_st, i % record_onepg))
                exist_set(_buf_st, i % _record_onepg);
            else if (exist(_buf_st, i % _record_onepg))
                exist_reset(_buf_st, i % _record_onepg);
            for (uint j = 0; j < col_num; j++) {
                if (j != col_id) memcpy(_buf, buf, col_ty[j].size());
                buf += col_ty[j].size();
                if (j != col_id) _buf += col_ty[j].size();
            }
            bpm->markDirty(index);
        }
        break;
    case 1: // add
        _record_size = record_size + col_ty[col_id].size();
        _record_onepg = 0;
        while ((_record_onepg + 1) * _record_size + _record_onepg / 8 + 1 <= PAGE_SIZE) _record_onepg++;
        for (uint i = 0; i < record_num; i++) {
            if (i % record_onepg == 0) {
                buf_st = buf = bpm->getPage(main_file, i / record_onepg);
                buf += (record_onepg - 1) / 8 + 1;
            }
            if (i % _record_onepg == 0) {
                _buf_st = _buf = bpm->getPage(_main_file, i / _record_onepg, index);
                _buf += (_record_onepg - 1) / 8 + 1;
            }
            if (exist(buf_st, i % record_onepg)) 
                exist_set(_buf_st, i % _record_onepg);
            else if (exist(_buf_st, i % _record_onepg))
                exist_reset(_buf_st, i % _record_onepg);
            for (uint j = 0; j < col_num - 1; j++) {
                memcpy(_buf, buf, col_ty[j].size());
                buf += col_ty[j].size(); 
                _buf += col_ty[j].size();
            }
            insert(col_ty[col_num - 1].def, col_ty[col_num - 1].ty, col_ty[col_num - 1].size(), _buf);
            bpm->markDirty(index);
        }
        break;
    }
    fm->closeFile(main_file);
    fm->closeFile(_main_file);
    replaceFile(dirPath(db->name, name, "tmp", "usid"), dirPath(db->name, name, "usid"));

    fm->openFile(dirPath(db->name, name, "usid"), main_file);
    record_size = _record_size;
    record_onepg = _record_onepg;
}

// Assembly:
cmpl $0x0, 0x9fa0(%rdi)
je 0x23bd0
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %esi, %r14d
movq %rdi, %rbx
movl %edx, (%rsp)
movq 0x38(%rdi), %rdi
movq 0x40(%rbx), %r15
leaq 0x18(%rbx), %rbp
leaq 0x1e701(%rip), %r12     # 0x41c1e
leaq 0x1a1ca(%rip), %r13     # 0x3d6ee
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1876d
movq %r15, %rdi
movq %rax, %rsi
callq 0x183c4
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %r15
movq %rbp, 0x48(%rsp)
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1876d
leaq 0x14(%rsp), %rdx
movq %r15, %rdi
movq %rax, %rsi
callq 0x183ec
cmpl $0x1, %r14d
je 0x235aa
testl %r14d, %r14d
jne 0x23b2f
movl 0x9fa8(%rbx), %esi
movl (%rsp), %r13d
imulq $0x38, %r13, %rax
movl 0x7c(%rbx,%rax), %ecx
cmpq $0x4, %rcx
ja 0x2361e
leaq 0x1e532(%rip), %rdx     # 0x41acc
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x4, %eax
jmp 0x23623
movl 0x9fa8(%rbx), %eax
movl (%rsp), %ecx
imulq $0x38, %rcx, %rcx
movl 0x7c(%rbx,%rcx), %edx
cmpq $0x4, %rdx
ja 0x23875
leaq 0x1e49c(%rip), %rsi     # 0x41a68
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movl $0x4, %edx
jmp 0x2387a
movl $0x10, %eax
jmp 0x23623
movl $0x10, %edx
jmp 0x2387a
addq %rbx, %rax
addq $0x58, %rax
movzbl 0x28(%rax), %eax
jmp 0x23623
addq %rbx, %rcx
addq $0x58, %rcx
movzbl 0x28(%rcx), %edx
jmp 0x2387a
movl $0x8, %eax
jmp 0x23623
movl $0x8, %edx
jmp 0x2387a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subl %eax, %esi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0x1, %eax
incl %ebp
addl %esi, %eax
movl %ebp, %ecx
shrl $0x3, %ecx
addl %eax, %ecx
cmpl $0x2001, %ecx           # imm = 0x2001
jb 0x2362f
cmpl $0x0, 0x9fa0(%rbx)
movl %esi, 0x24(%rsp)
je 0x23b2f
movq %rbp, (%rsp)
leal -0x1(%rbp), %eax
shrl $0x3, %eax
movq %rax, 0x28(%rsp)
leaq 0x80(%rbx), %rax
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
movl %r14d, %eax
xorl %edx, %edx
divl 0x9fac(%rbx)
testl %edx, %edx
jne 0x236a8
movq 0x48(%rbx), %rdi
movl 0x9fa4(%rbx), %esi
movl %eax, %edx
callq 0x6768
movl 0x9fac(%rbx), %ecx
decl %ecx
shrl $0x3, %ecx
movq %rax, 0x38(%rsp)
leaq (%rax,%rcx), %rbp
incq %rbp
movl %r14d, %eax
xorl %edx, %edx
divl (%rsp)
movl %edx, %r15d
testl %edx, %edx
jne 0x236e3
movq 0x48(%rbx), %rdi
movl 0x14(%rsp), %esi
movl %eax, %edx
leaq 0x10(%rsp), %rcx
callq 0x6834
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rsp)
addq %rcx, %rax
incq %rax
movq %rax, 0x18(%rsp)
movl %r14d, %eax
xorl %edx, %edx
divl 0x9fac(%rbx)
movl %edx, %eax
shrl $0x3, %eax
movq 0x38(%rsp), %rcx
movzbl (%rcx,%rax), %eax
andl $0x7, %edx
btl %edx, %eax
jae 0x23720
movl %r15d, %ecx
andb $0x7, %cl
movl $0x1, %eax
shll %cl, %eax
shrl $0x3, %r15d
movq 0x8(%rsp), %rcx
orb %al, (%rcx,%r15)
jmp 0x23750
movl %r15d, %eax
movl %r15d, %ecx
andb $0x7, %cl
movl $0x1, %edx
shll %cl, %edx
shrl $0x3, %eax
movq 0x8(%rsp), %rcx
movzbl (%rcx,%rax), %ecx
andl $0x7, %r15d
btl %r15d, %ecx
jae 0x23750
subb %dl, %cl
movq 0x8(%rsp), %rdx
movb %cl, (%rdx,%rax)
movq %r14, 0x40(%rsp)
cmpl $0x0, 0x54(%rbx)
je 0x2384a
movq 0x18(%rsp), %r15
movq 0x30(%rsp), %r14
xorl %r12d, %r12d
cmpq %r12, %r13
je 0x237b6
movl -0x4(%r14), %eax
cmpq $0x4, %rax
ja 0x237a6
leaq 0x1e35e(%rip), %rcx     # 0x41ae0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x4, %edx
jmp 0x237ab
movl $0x10, %edx
jmp 0x237ab
movzbl (%r14), %edx
jmp 0x237ab
movl $0x8, %edx
jmp 0x237ab
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r15, %rdi
movq %rbp, %rsi
callq 0x5310
movl -0x4(%r14), %ecx
cmpq $0x4, %rcx
ja 0x237eb
leaq 0x1e32d(%rip), %rdx     # 0x41af4
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movl $0x4, %eax
jmp 0x237f0
movl $0x10, %eax
jmp 0x237f0
movzbl (%r14), %eax
jmp 0x237f0
movl $0x8, %eax
jmp 0x237f0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %r12, %r13
je 0x23834
cmpl $0x4, %ecx
ja 0x23827
movl %ecx, %ecx
leaq 0x1e305(%rip), %rdx     # 0x41b08
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x4, %ecx
jmp 0x2382c
movl $0x10, %ecx
jmp 0x2382c
movzbl (%r14), %ecx
jmp 0x2382c
movl $0x8, %ecx
jmp 0x2382c
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
addq %rcx, %r15
movq %r15, 0x18(%rsp)
addq %rax, %rbp
incq %r12
movl 0x54(%rbx), %eax
addq $0x38, %r14
cmpq %rax, %r12
jb 0x2376c
movq 0x48(%rbx), %rdi
movl 0x10(%rsp), %esi
callq 0x68ee
movq 0x40(%rsp), %r14
incl %r14d
cmpl 0x9fa0(%rbx), %r14d
jb 0x23671
movq (%rsp), %rbp
jmp 0x23b2f
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
addl %eax, %edx
leaq 0x58(%rbx), %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0x1, %eax
incl %ebp
addl %edx, %eax
movl %ebp, %ecx
shrl $0x3, %ecx
addl %eax, %ecx
cmpl $0x2001, %ecx           # imm = 0x2001
jb 0x2388a
cmpl $0x0, 0x9fa0(%rbx)
movl %edx, 0x24(%rsp)
je 0x23b2f
leal -0x1(%rbp), %eax
shrl $0x3, %eax
movq %rax, 0x50(%rsp)
leaq 0x80(%rbx), %rax
movq %rax, 0x28(%rsp)
xorl %ecx, %ecx
leaq 0x1e1ae(%rip), %r12     # 0x41a7c
movq %rbp, (%rsp)
movq %r15, 0x30(%rsp)
movl %ecx, %eax
xorl %edx, %edx
divl 0x9fac(%rbx)
testl %edx, %edx
jne 0x23913
movq 0x48(%rbx), %rdi
movl 0x9fa4(%rbx), %esi
movl %eax, %edx
movq %rcx, %r14
callq 0x6768
movq %r14, %rcx
movl 0x9fac(%rbx), %edx
decl %edx
shrl $0x3, %edx
movq %rax, 0x38(%rsp)
leaq (%rax,%rdx), %r14
incq %r14
movl %ecx, %eax
xorl %edx, %edx
divl %ebp
movl %edx, %r13d
testl %edx, %edx
jne 0x23952
movq 0x48(%rbx), %rdi
movl 0x14(%rsp), %esi
movl %eax, %edx
movq %rcx, %r15
leaq 0x10(%rsp), %rcx
callq 0x6834
movq %r15, %rcx
movq %rax, %rdx
movq 0x50(%rsp), %rax
movq %rdx, 0x8(%rsp)
addq %rdx, %rax
incq %rax
movq %rax, 0x18(%rsp)
movq %rcx, 0x40(%rsp)
movl %ecx, %eax
xorl %edx, %edx
divl 0x9fac(%rbx)
movl %edx, %eax
shrl $0x3, %eax
movq 0x38(%rsp), %rcx
movzbl (%rcx,%rax), %eax
andl $0x7, %edx
btl %edx, %eax
jae 0x23993
movl %r13d, %ecx
andb $0x7, %cl
movl $0x1, %eax
shll %cl, %eax
shrl $0x3, %r13d
movq 0x8(%rsp), %rcx
orb %al, (%rcx,%r13)
jmp 0x239c3
movl %r13d, %eax
movl %r13d, %ecx
andb $0x7, %cl
movl $0x1, %edx
shll %cl, %edx
shrl $0x3, %eax
movq 0x8(%rsp), %rcx
movzbl (%rcx,%rax), %ecx
andl $0x7, %r13d
btl %r13d, %ecx
jae 0x239c3
subb %dl, %cl
movq 0x8(%rsp), %rdx
movb %cl, (%rdx,%rax)
movl 0x54(%rbx), %eax
decl %eax
je 0x23aa8
movq 0x18(%rsp), %r13
movq 0x28(%rsp), %rbp
xorl %r15d, %r15d
movl -0x4(%rbp), %eax
cmpq $0x4, %rax
ja 0x23a08
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x4, %edx
jmp 0x23a0d
movl $0x10, %edx
jmp 0x23a0d
movzbl (%rbp), %edx
jmp 0x23a0d
movl $0x8, %edx
jmp 0x23a0d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r13, %rdi
movq %r14, %rsi
callq 0x5310
movl -0x4(%rbp), %ecx
cmpq $0x4, %rcx
ja 0x23a4c
leaq 0x1e068(%rip), %rdx     # 0x41a90
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movl $0x4, %eax
jmp 0x23a51
movl $0x10, %eax
jmp 0x23a51
movzbl (%rbp), %eax
jmp 0x23a51
movl $0x8, %eax
jmp 0x23a51
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x4, %ecx
ja 0x23a83
movl %ecx, %ecx
leaq 0x1e045(%rip), %rdx     # 0x41aa4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x4, %ecx
jmp 0x23a88
movl $0x10, %ecx
jmp 0x23a88
movzbl (%rbp), %ecx
jmp 0x23a88
movl $0x8, %ecx
jmp 0x23a88
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
addq %rax, %r14
addq %rcx, %r13
movq %r13, 0x18(%rsp)
incq %r15
movl 0x54(%rbx), %eax
decl %eax
addq $0x38, %rbp
cmpq %rax, %r15
jb 0x239db
movl %eax, %eax
imulq $0x38, %rax, %rax
movq 0x30(%rsp), %r15
movl 0x24(%r15,%rax), %edx
cmpq $0x4, %rdx
ja 0x23af1
leaq 0x1dff3(%rip), %rsi     # 0x41ab8
movslq (%rsi,%rdx,4), %rcx
addq %rsi, %rcx
movq (%rsp), %rbp
jmpq *%rcx
movl $0x4, %ecx
jmp 0x23afa
movl $0x10, %ecx
jmp 0x23afa
leaq (%r15,%rax), %rcx
movzbl 0x28(%rcx), %ecx
jmp 0x23afa
movl $0x8, %ecx
jmp 0x23afa
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq (%rsp), %rbp
leaq (%r15,%rax), %rsi
addq $0x30, %rsi
movq %rbx, %rdi
leaq 0x18(%rsp), %r8
callq 0x21df2
movq 0x48(%rbx), %rdi
movl 0x10(%rsp), %esi
callq 0x68ee
movq 0x40(%rsp), %rcx
incl %ecx
cmpl 0x9fa0(%rbx), %ecx
jb 0x238d7
movq 0x40(%rbx), %rdi
leaq 0x9fa4(%rbx), %r14
movl 0x9fa4(%rbx), %esi
callq 0x1836a
movq 0x40(%rbx), %rdi
movl 0x14(%rsp), %esi
callq 0x1836a
movq 0x38(%rbx), %rdi
leaq 0x1e0c1(%rip), %rdx     # 0x41c1e
leaq 0x19b8a(%rip), %r15     # 0x3d6ee
movq 0x48(%rsp), %r12
movq %r12, %rsi
movq %r15, %rcx
callq 0x1876d
movq %rax, %r13
movq 0x38(%rbx), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x186c1
movq %r13, %rdi
movq %rax, %rsi
callq 0x18996
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %r13
movq %r12, %rsi
movq %r15, %rdx
callq 0x186c1
movq %r13, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x183ec
movl 0x24(%rsp), %eax
movl %eax, 0x9fa8(%rbx)
movl %ebp, 0x9fac(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop