// File: /workspace/github_cpp_makefile_star2_O1/Konano[P]UselessDatabase/Database.cpp
// Function: Database::buildSel(unsigned int, bool)
void Database::buildSel(uint idx, bool print) {
    if (sel[idx].build) return; 
    sel[idx].build = true;
    for (auto it: sel[idx].recursion) buildSel(-1-it);
    selStop = false;
    for (uint i = 0; i < sel[idx].from.size(); i++) 
        filterTable(sel[idx].from[i].first)->removePointer();
    dfsCross(idx, 0, print);
    if (sel[idx].select.size() == 0 && sel[idx].aggr.size() > 0) {
        uint _idx = 0;
        Table* table = sel_table[idx];
        for (auto it: sel[idx].aggr) switch (it.ty) {
            case AG_COUNT: {
                table->val.push_back(Any((int)table->record_num));
                break;
            }
            case AG_MIN: {
                Any min = Any();
                for (auto _it: table->data) if (min.isNull()) min = _it[_idx]; else if (_it[_idx].isNull()) continue; else if (_it[_idx] < min) min = _it[_idx];
                table->val.push_back(min);
                _idx++;
                break;
            }
            case AG_MAX: {
                Any max = Any();
                for (auto _it: table->data) if (max.isNull()) max = _it[_idx]; else if (_it[_idx].isNull()) continue; else if (_it[_idx] > max) max = _it[_idx];
                table->val.push_back(max);
                _idx++;
                break;
            }
            case AG_SUM: 
            case AG_AVG: {
                if (table->col_ty[_idx].ty == INT) {
                    int sum = 0;
                    int num = 0;
                    for (auto _it: table->data) if (_it[_idx].isNull() == false) num++, sum += _it[_idx].anyRefCast<int>();
                    if (it.ty == AG_SUM) table->val.push_back(Any(sum)); else table->val.push_back(Any((long double)sum / num));
                } else {
                    long double sum = 0;
                    int num = 0;
                    for (auto _it: table->data) if (_it[_idx].isNull() == false) num++, sum += _it[_idx].anyRefCast<long double>();
                    if (it.ty == AG_SUM) table->val.push_back(Any(sum)); else table->val.push_back(Any(sum / num));
                }
                _idx++;
                break;
            }
        }
    }
    uint _idx = 0;
    for (auto it: sel[idx].aggr) {
        if (it.ty == AG_AVG) sel_table[idx]->col_ty[_idx].ty = DECIMAL;
        if (it.ty != AG_COUNT) _idx++;
    }
    if (print && selStop == false && sel_table[idx]->record_num % MAX_RESULT_LINES && sel_table[idx]->printBack(sel_table[idx]->record_num % MAX_RESULT_LINES) == false) {
        sel_table[idx]->print();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %esi, %eax
movq %rax, 0x48(%rsp)
shlq $0x7, %rax
cmpb $0x0, 0x848(%rdi,%rax)
je 0x8444
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r14d
movq %rdi, %r12
movl %edx, 0x44(%rsp)
addq %rdi, %rax
addq $0x848, %rax            # imm = 0x848
movb $0x1, (%rax)
movq 0x68(%rax), %rbx
movq %rax, 0x8(%rsp)
movq 0x70(%rax), %r15
cmpq %r15, %rbx
je 0x8480
movl (%rbx), %esi
notl %esi
movq %r12, %rdi
xorl %edx, %edx
callq 0x840c
addq $0x4, %rbx
jmp 0x8467
movq %r12, 0x38(%rsp)
movb $0x0, 0x4bfb6(%rip)     # 0x54442
movq 0x8(%rsp), %r13
movq 0x38(%r13), %rax
cmpq %rax, 0x40(%r13)
je 0x84fb
movq 0x38(%rsp), %rcx
leaq 0x8848(%rcx), %rbx
leaq 0x20(%rcx), %r15
movl $0x1, %ebp
xorl %ecx, %ecx
movabsq $-0x3333333333333333, %r12 # imm = 0xCCCCCCCCCCCCCCCD
leaq (%rcx,%rcx,4), %rcx
movslq (%rax,%rcx,8), %rax
testq %rax, %rax
leaq (%r15,%rax,8), %rcx
notl %eax
cltq
leaq (%rbx,%rax,8), %rax
cmovsq %rax, %rcx
movq (%rcx), %rdi
callq 0x2606c
movl %ebp, %ecx
movq 0x38(%r13), %rax
movq 0x40(%r13), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x84bc
movzbl 0x44(%rsp), %ecx
movq 0x38(%rsp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x80b0
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rax
movq %r13, %rbx
je 0x863c
movq %rbx, %rax
movq 0x20(%rbx), %rbx
movq 0x28(%rax), %r15
cmpq %r15, %rbx
je 0x85d2
leaq 0x98(%rsp), %r14
xorl %ebp, %ebp
leaq 0xa8(%rsp), %r12
movl 0x8(%rbx), %eax
movl %eax, 0x90(%rsp)
movq (%rbx), %rax
movq %rax, 0x88(%rsp)
movq %r12, 0x98(%rsp)
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xa88e
movl 0x88(%rsp), %eax
cmpl $0x4, %eax
jne 0x85a2
movq 0x38(%rsp), %rcx
movq 0x48(%rsp), %rdx
movq 0x8848(%rcx,%rdx,8), %rcx
movl %ebp, %edx
imulq $0x38, %rdx, %rdx
movl $0x4, 0x7c(%rcx,%rdx)
cmpl $0x1, %eax
sbbl $-0x1, %ebp
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0x85c5
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x53a0
addq $0x30, %rbx
cmpq %r15, %rbx
jne 0x8546
cmpb $0x0, 0x44(%rsp)
movq 0x38(%rsp), %rbx
je 0x8432
cmpb $0x0, 0x4be59(%rip)     # 0x54442
jne 0x8432
movq 0x48(%rsp), %rax
movq 0x8848(%rbx,%rax,8), %rdi
movl 0x9fa0(%rdi), %esi
imulq $0x51eb851f, %rsi, %rax # imm = 0x51EB851F
shrq $0x24, %rax
imull $0x32, %eax, %eax
subl %eax, %esi
je 0x8432
callq 0x25a68
testb %al, %al
jne 0x8432
movq 0x48(%rsp), %rax
movq 0x8848(%rbx,%rax,8), %rdi
callq 0x24e76
jmp 0x8432
movq 0x20(%rbx), %rdx
movq 0x28(%rbx), %rax
movq %rax, 0xf8(%rsp)
cmpq %rdx, %rax
je 0x8520
movq 0x38(%rsp), %rax
movq 0x48(%rsp), %rcx
movq 0x8848(%rax,%rcx,8), %rax
leaq 0xa8(%rsp), %r14
leaq 0x58(%rax), %rcx
movq %rcx, 0xf0(%rsp)
movq %rax, 0x30(%rsp)
addq $0x9fd0, %rax           # imm = 0x9FD0
movq %rax, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
leaq 0xc8(%rsp), %r12
movl 0x8(%rdx), %eax
movl %eax, 0x90(%rsp)
movq (%rdx), %rax
movq %rax, 0x88(%rsp)
movq %r14, 0x98(%rsp)
movq 0x10(%rdx), %rsi
movq %rdx, 0x100(%rsp)
movq 0x18(%rdx), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0xa88e
movl 0x88(%rsp), %eax
cmpq $0x4, %rax
ja 0x8b06
leaq 0x34947(%rip), %rcx     # 0x3d038
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x10(%rsp), %r15d
imulq $0x38, %r15, %rax
movq 0xf0(%rsp), %rcx
cmpl $0x0, 0x24(%rcx,%rax)
je 0x89d8
movq 0x30(%rsp), %rax
movq 0x9fb8(%rax), %rbp
movq 0x9fc0(%rax), %rbx
fldz
fld %st(0)
fstpt 0x24(%rsp)
fstpt 0xe4(%rsp)
cmpq %rbx, %rbp
je 0x879f
xorl %r14d, %r14d
fldz
fstpt 0x24(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0xa450
movq 0xc8(%rsp), %rax
cmpq $0x0, (%rax,%r15,8)
je 0x8778
leaq (%rax,%r15,8), %rdi
callq 0x9fe8
incl %r14d
fldt (%rax)
fldt 0x24(%rsp)
faddp %st, %st(1)
fstpt 0x24(%rsp)
movq %r12, %rdi
callq 0xa564
addq $0x18, %rbp
cmpq %rbx, %rbp
jne 0x8746
movl %r14d, 0xc4(%rsp)
fildl 0xc4(%rsp)
fstpt 0xe4(%rsp)
cmpl $0x3, 0x88(%rsp)
jne 0x8a52
movl $0x20, %edi
leaq 0xa8(%rsp), %r14
callq 0x5390
movq 0x8(%rsp), %rbx
leaq 0x4b2d5(%rip), %rcx     # 0x53aa0
movq %rcx, (%rax)
fldt 0x24(%rsp)
fstpt 0x10(%rax)
movq %rax, 0x58(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xa1bc
movq 0x58(%rsp), %rdi
jmp 0x8aef
movq $0x0, (%rsp)
movq 0x30(%rsp), %rax
movq 0x9fb8(%rax), %rbp
movq 0x9fc0(%rax), %rbx
cmpq %rbx, %rbp
je 0x889a
movl 0x10(%rsp), %r15d
movq %r12, %rdi
movq %rbp, %rsi
callq 0xa450
cmpq $0x0, (%rsp)
movq 0xc8(%rsp), %rax
je 0x886e
cmpq $0x0, (%rax,%r15,8)
je 0x8889
leaq (%rax,%r15,8), %rdi
movq %rsp, %rsi
callq 0x9e50
testb %al, %al
je 0x8889
movq 0xc8(%rsp), %rax
movq $0x0, (%rsp)
movq (%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0x8889
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x8885
movq $0x0, (%rsp)
movq (%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0x8889
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, (%rsp)
movq %r12, %rdi
callq 0xa564
addq $0x18, %rbp
cmpq %rbx, %rbp
jne 0x881c
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8a9e
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x8(%rsp), %rbx
jmp 0x8aa5
movq 0x30(%rsp), %rax
movl 0x9fa0(%rax), %ebx
movl $0x10, %edi
callq 0x5390
leaq 0x4b1a5(%rip), %rcx     # 0x53a78
movq %rcx, (%rax)
movl %ebx, 0x8(%rax)
movq %rax, 0x80(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xa1bc
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %rbx
je 0x8b06
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x8b06
movq $0x0, (%rsp)
movq 0x30(%rsp), %rax
movq 0x9fb8(%rax), %rbp
movq 0x9fc0(%rax), %rbx
cmpq %rbx, %rbp
je 0x89bb
movl 0x10(%rsp), %r15d
movq %r12, %rdi
movq %rbp, %rsi
callq 0xa450
cmpq $0x0, (%rsp)
movq 0xc8(%rsp), %rax
je 0x898f
cmpq $0x0, (%rax,%r15,8)
je 0x89aa
leaq (%rax,%r15,8), %rdi
movq %rsp, %rsi
callq 0x9cec
testb %al, %al
je 0x89aa
movq 0xc8(%rsp), %rax
movq $0x0, (%rsp)
movq (%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0x89aa
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x89a6
movq $0x0, (%rsp)
movq (%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0x89aa
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, (%rsp)
movq %r12, %rdi
callq 0xa564
addq $0x18, %rbp
cmpq %rbx, %rbp
jne 0x893d
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8ac0
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x8(%rsp), %rbx
jmp 0x8ac7
movq 0x30(%rsp), %rax
movq 0x9fb8(%rax), %rbp
movq 0x9fc0(%rax), %r13
cmpq %r13, %rbp
je 0x8b42
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r12, %rdi
movq %rbp, %rsi
callq 0xa450
movq 0xc8(%rsp), %rax
cmpq $0x0, (%rax,%r15,8)
je 0x8a21
leaq (%rax,%r15,8), %rdi
callq 0x9fbe
incl %r14d
addl (%rax), %ebx
movq %r12, %rdi
callq 0xa564
addq $0x18, %rbp
cmpq %r13, %rbp
jne 0x89f9
movl %r14d, 0xc0(%rsp)
fildl 0xc0(%rsp)
fstpt 0x24(%rsp)
leaq 0xa8(%rsp), %r14
jmp 0x8b4a
movl $0x20, %edi
leaq 0xa8(%rsp), %r14
callq 0x5390
movq 0x8(%rsp), %rbx
fldt 0x24(%rsp)
fldt 0xe4(%rsp)
fdivrp %st, %st(1)
leaq 0x4b023(%rip), %rcx     # 0x53aa0
movq %rcx, (%rax)
fstpt 0x10(%rax)
movq %rax, 0x50(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xa1bc
movq 0x50(%rsp), %rdi
jmp 0x8aef
xorl %eax, %eax
movq 0x8(%rsp), %rbx
movq %rax, 0x70(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xa1bc
movq 0x70(%rsp), %rdi
jmp 0x8ae0
xorl %eax, %eax
movq 0x8(%rsp), %rbx
movq %rax, 0x78(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0xa1bc
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x8aeb
movq (%rdi), %rax
callq *0x8(%rax)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8afa
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x8b23
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x53a0
movq 0x100(%rsp), %rdx
addq $0x30, %rdx
cmpq 0xf8(%rsp), %rdx
jne 0x869c
jmp 0x8520
xorl %ebx, %ebx
fldz
fstpt 0x24(%rsp)
cmpl $0x3, 0x88(%rsp)
jne 0x8b86
movl $0x10, %edi
callq 0x5390
leaq 0x4af13(%rip), %rcx     # 0x53a78
movq %rcx, (%rax)
movl %ebx, 0x8(%rax)
movq %rax, 0x68(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0xa1bc
movq 0x68(%rsp), %rdi
jmp 0x8bc8
movl $0x20, %edi
callq 0x5390
movl %ebx, 0xbc(%rsp)
fldt 0x24(%rsp)
fidivrl 0xbc(%rsp)
leaq 0x4aef7(%rip), %rcx     # 0x53aa0
movq %rcx, (%rax)
fstpt 0x10(%rax)
movq %rax, 0x60(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xa1bc
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %rbx
jne 0x8af4
jmp 0x8afa
jmp 0x8c86
movq %rax, %rbx
movq 0x68(%rsp), %rdi
jmp 0x8c79
jmp 0x8c86
movq %rax, %rbx
movq 0x60(%rsp), %rdi
jmp 0x8c79
jmp 0x8c72
jmp 0x8c72
movq %rax, %rbx
movq 0x58(%rsp), %rdi
jmp 0x8c79
jmp 0x8c86
movq %rax, %rbx
movq 0x50(%rsp), %rdi
jmp 0x8c79
jmp 0x8c86
movq %rax, %rbx
movq 0x80(%rsp), %rdi
jmp 0x8c79
jmp 0x8c86
movq %rax, %rbx
movq 0x78(%rsp), %rdi
jmp 0x8c39
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8c75
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x8c75
jmp 0x8c5e
jmp 0x8c4a
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0xa564
jmp 0x8c75
jmp 0x8c86
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0xa564
jmp 0x8c89
jmp 0x8c72
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8c89
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x8c89
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x8cae
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x53a0
movq %rbx, %rdi
callq 0x56e0