// File: /workspace/github_cpp_makefile_star2_O3/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 0x23632
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %esi, %r14d
movq %rdi, %rbx
movl %edx, 0x8(%rsp)
movq 0x38(%rdi), %rdi
movq 0x40(%rbx), %r15
leaq 0x18(%rbx), %rbp
leaq 0x1dce0(%rip), %r12     # 0x40c4e
leaq 0x19779(%rip), %r13     # 0x3c6ee
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x18003
movq %r15, %rdi
movq %rax, %rsi
callq 0x17c64
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %r15
movq %rbp, 0x48(%rsp)
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x18003
leaq 0x14(%rsp), %rdx
movq %r15, %rdi
movq %rax, %rsi
callq 0x17c8c
cmpl $0x1, %r14d
je 0x22ffc
testl %r14d, %r14d
jne 0x23591
movl 0x9fa8(%rbx), %esi
movl 0x8(%rsp), %r13d
imulq $0x38, %r13, %rax
movl 0x7c(%rbx,%rax), %ecx
cmpq $0x4, %rcx
ja 0x23071
leaq 0x1dacc(%rip), %rdx     # 0x40ab8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x4, %eax
jmp 0x23076
movl 0x9fa8(%rbx), %eax
movl 0x8(%rsp), %ecx
imulq $0x38, %rcx, %rcx
movl 0x7c(%rbx,%rcx), %edx
cmpq $0x4, %rdx
ja 0x232cc
leaq 0x1da39(%rip), %rsi     # 0x40a58
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movl $0x4, %edx
jmp 0x232d1
movl $0x10, %eax
jmp 0x23076
movl $0x10, %edx
jmp 0x232d1
addq %rbx, %rax
addq $0x58, %rax
movzbl 0x28(%rax), %eax
jmp 0x23076
addq %rbx, %rcx
addq $0x58, %rcx
movzbl 0x28(%rcx), %edx
jmp 0x232d1
movl $0x8, %eax
jmp 0x23076
movl $0x8, %edx
jmp 0x232d1
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 0x23082
cmpl $0x0, 0x9fa0(%rbx)
movl %esi, 0x2c(%rsp)
je 0x23591
movq %rbp, 0x30(%rsp)
leal -0x1(%rbp), %eax
shrl $0x3, %eax
movq %rax, 0x38(%rsp)
leaq 0x80(%rbx), %rax
movq %rax, 0x40(%rsp)
xorl %r14d, %r14d
movl 0x9fac(%rbx), %ecx
movl %r14d, %eax
xorl %edx, %edx
divl %ecx
testl %edx, %edx
jne 0x230ff
movq 0x48(%rbx), %rdi
movl 0x9fa4(%rbx), %esi
movl %eax, %edx
callq 0x6722
movl 0x9fac(%rbx), %ecx
leal -0x1(%rcx), %edx
shrl $0x3, %edx
movq %rax, 0x20(%rsp)
leaq (%rax,%rdx), %rbp
incq %rbp
movl %r14d, %eax
xorl %edx, %edx
divl 0x30(%rsp)
movl %edx, %r15d
testl %edx, %edx
jne 0x23140
movq 0x48(%rbx), %rdi
movl 0x14(%rsp), %esi
movl %eax, %edx
leaq 0x10(%rsp), %rcx
callq 0x67e4
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, (%rsp)
addq %rcx, %rax
incq %rax
movq %rax, 0x18(%rsp)
movl 0x9fac(%rbx), %ecx
movl %r14d, %eax
xorl %edx, %edx
divl %ecx
movl %edx, %eax
shrl $0x3, %eax
movq 0x20(%rsp), %rcx
movzbl (%rcx,%rax), %eax
andl $0x7, %edx
btl %edx, %eax
jae 0x23178
movl %r15d, %ecx
andb $0x7, %cl
movl $0x1, %eax
shll %cl, %eax
shrl $0x3, %r15d
movq (%rsp), %rcx
orb %al, (%rcx,%r15)
jmp 0x231a6
movl %r15d, %eax
movl %r15d, %ecx
andb $0x7, %cl
movl $0x1, %edx
shll %cl, %edx
shrl $0x3, %eax
movq (%rsp), %rcx
movzbl (%rcx,%rax), %ecx
andl $0x7, %r15d
btl %r15d, %ecx
jae 0x231a6
subb %dl, %cl
movq (%rsp), %rdx
movb %cl, (%rdx,%rax)
movq %r14, 0x8(%rsp)
cmpl $0x0, 0x54(%rbx)
je 0x232a0
movq 0x18(%rsp), %r15
movq 0x40(%rsp), %r14
xorl %r12d, %r12d
cmpq %r12, %r13
je 0x2320c
movl -0x4(%r14), %eax
cmpq $0x4, %rax
ja 0x231fc
leaq 0x1d8f4(%rip), %rcx     # 0x40acc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x4, %edx
jmp 0x23201
movl $0x10, %edx
jmp 0x23201
movzbl (%r14), %edx
jmp 0x23201
movl $0x8, %edx
jmp 0x23201
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r15, %rdi
movq %rbp, %rsi
callq 0x5310
movl -0x4(%r14), %ecx
cmpq $0x4, %rcx
ja 0x23241
leaq 0x1d8c3(%rip), %rdx     # 0x40ae0
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movl $0x4, %eax
jmp 0x23246
movl $0x10, %eax
jmp 0x23246
movzbl (%r14), %eax
jmp 0x23246
movl $0x8, %eax
jmp 0x23246
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %r12, %r13
je 0x2328a
cmpl $0x4, %ecx
ja 0x2327d
movl %ecx, %ecx
leaq 0x1d89b(%rip), %rdx     # 0x40af4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x4, %ecx
jmp 0x23282
movl $0x10, %ecx
jmp 0x23282
movzbl (%r14), %ecx
jmp 0x23282
movl $0x8, %ecx
jmp 0x23282
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 0x231c2
movq 0x48(%rbx), %rdi
movl 0x10(%rsp), %esi
callq 0x689e
movq 0x8(%rsp), %r14
incl %r14d
cmpl 0x9fa0(%rbx), %r14d
jb 0x230c5
movq 0x30(%rsp), %rbp
jmp 0x23591
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
addl %eax, %edx
leaq 0x58(%rbx), %r12
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 0x232e1
cmpl $0x0, 0x9fa0(%rbx)
movl %edx, 0x2c(%rsp)
je 0x23591
leal -0x1(%rbp), %eax
shrl $0x3, %eax
movq %rax, 0x50(%rsp)
leaq 0x80(%rbx), %rax
movq %rax, 0x38(%rsp)
xorl %r13d, %r13d
leaq 0x1d746(%rip), %r15     # 0x40a6c
movq %rbp, 0x30(%rsp)
movq %r12, 0x20(%rsp)
movl 0x9fac(%rbx), %ecx
movl %r13d, %eax
xorl %edx, %edx
divl %ecx
testl %edx, %edx
jne 0x2336a
movq 0x48(%rbx), %rdi
movl 0x9fa4(%rbx), %esi
movl %eax, %edx
callq 0x6722
movl 0x9fac(%rbx), %ecx
leal -0x1(%rcx), %edx
shrl $0x3, %edx
movq %rax, 0x40(%rsp)
leaq (%rax,%rdx), %r14
incq %r14
movl %r13d, %eax
xorl %edx, %edx
divl %ebp
movq %r13, %r12
movl %edx, %r13d
testl %edx, %edx
jne 0x233ac
movq 0x48(%rbx), %rdi
movl 0x14(%rsp), %esi
movl %eax, %edx
leaq 0x10(%rsp), %rcx
callq 0x67e4
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rsp)
addq %rcx, %rax
incq %rax
movq %rax, 0x18(%rsp)
movl 0x9fac(%rbx), %ecx
movq %r12, 0x8(%rsp)
movl %r12d, %eax
xorl %edx, %edx
divl %ecx
movl %edx, %eax
shrl $0x3, %eax
movq 0x40(%rsp), %rcx
movzbl (%rcx,%rax), %eax
andl $0x7, %edx
btl %edx, %eax
jae 0x233ee
movl %r13d, %ecx
andb $0x7, %cl
movl $0x1, %eax
shll %cl, %eax
shrl $0x3, %r13d
movq (%rsp), %rcx
orb %al, (%rcx,%r13)
movq 0x20(%rsp), %r12
jmp 0x23421
movl %r13d, %eax
movl %r13d, %ecx
andb $0x7, %cl
movl $0x1, %edx
shll %cl, %edx
shrl $0x3, %eax
movq (%rsp), %rcx
movzbl (%rcx,%rax), %ecx
andl $0x7, %r13d
btl %r13d, %ecx
movq 0x20(%rsp), %r12
jae 0x23421
subb %dl, %cl
movq (%rsp), %rdx
movb %cl, (%rdx,%rax)
cmpl $0x1, 0x54(%rbx)
jne 0x2342e
xorl %eax, %eax
jmp 0x23517
movq 0x18(%rsp), %r13
movq 0x38(%rsp), %r12
xorl %ebp, %ebp
movl -0x4(%r12), %eax
cmpq $0x4, %rax
ja 0x2346a
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movl $0x4, %edx
jmp 0x2346f
movl $0x10, %edx
jmp 0x2346f
movzbl (%r12), %edx
jmp 0x2346f
movl $0x8, %edx
jmp 0x2346f
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r13, %rdi
movq %r14, %rsi
callq 0x5310
movl -0x4(%r12), %ecx
cmpq $0x4, %rcx
ja 0x234b7
leaq 0x1d5f4(%rip), %rdx     # 0x40a80
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movl $0x4, %eax
jmp 0x234bc
addq $0x10, %r14
movl $0x10, %eax
jmp 0x234ee
movzbl (%r12), %eax
addq %rax, %r14
jmp 0x234ee
addq $0x8, %r14
jmp 0x234e2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq %rax, %r14
cmpl $0x3, %ecx
ja 0x234e9
movl $0x4, %eax
movl %ecx, %ecx
leaq 0x1d5c2(%rip), %rdx     # 0x40a94
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movzbl (%r12), %eax
jmp 0x234ee
movl $0x8, %eax
jmp 0x234ee
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq %rax, %r13
movq %r13, 0x18(%rsp)
incq %rbp
movl 0x54(%rbx), %eax
decl %eax
addq $0x38, %r12
cmpq %rax, %rbp
jb 0x2343a
movl %eax, %eax
movq 0x30(%rsp), %rbp
movq 0x20(%rsp), %r12
movq 0x8(%rsp), %r13
imulq $0x38, %rax, %rax
movl 0x24(%r12,%rax), %edx
cmpq $0x4, %rdx
ja 0x2355a
leaq 0x1d572(%rip), %rsi     # 0x40aa4
movslq (%rsi,%rdx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
movl $0x4, %ecx
jmp 0x2355f
movl $0x10, %ecx
jmp 0x2355f
leaq (%r12,%rax), %rcx
movzbl 0x28(%rcx), %ecx
jmp 0x2355f
movl $0x8, %ecx
jmp 0x2355f
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
leaq (%r12,%rax), %rsi
addq $0x30, %rsi
movq %rbx, %rdi
leaq 0x18(%rsp), %r8
callq 0x218fe
movq 0x48(%rbx), %rdi
movl 0x10(%rsp), %esi
callq 0x689e
incl %r13d
cmpl 0x9fa0(%rbx), %r13d
jb 0x23330
movq 0x40(%rbx), %rdi
leaq 0x9fa4(%rbx), %r14
movl 0x9fa4(%rbx), %esi
callq 0x17c0a
movq 0x40(%rbx), %rdi
movl 0x14(%rsp), %esi
callq 0x17c0a
movq 0x38(%rbx), %rdi
leaq 0x1d68f(%rip), %rdx     # 0x40c4e
leaq 0x19128(%rip), %r15     # 0x3c6ee
movq 0x48(%rsp), %r12
movq %r12, %rsi
movq %r15, %rcx
callq 0x18003
movq %rax, %r13
movq 0x38(%rbx), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x17f62
movq %r13, %rdi
movq %rax, %rsi
callq 0x18204
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %r13
movq %r12, %rsi
movq %r15, %rdx
callq 0x17f62
movq %r13, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x17c8c
movl 0x2c(%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