// File: /workspace/github_cpp_makefile_star2_O2/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 $0xf8, %rsp
movl %edx, 0x3c(%rsp)
movl %esi, %eax
movq %rax, 0x40(%rsp)
shlq $0x7, %rax
cmpb $0x0, 0x848(%rdi,%rax)
je 0x7316
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %ebx
movq %rdi, %r14
addq %rdi, %rax
addq $0x848, %rax            # imm = 0x848
movb $0x1, (%rax)
movq 0x68(%rax), %r15
movq %rax, 0x48(%rsp)
movq 0x70(%rax), %r12
cmpq %r12, %r15
je 0x734e
movl (%r15), %esi
notl %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x72da
addq $0x4, %r15
jmp 0x7334
movb $0x0, 0x490fd(%rip)     # 0x50452
leaq 0x8848(%r14), %rax
movq %rax, 0x30(%rsp)
leaq 0x20(%r14), %r15
xorl %eax, %eax
pushq $0x28
popq %r12
movl %eax, %r13d
movq 0x48(%rsp), %rax
movq 0x38(%rax), %rcx
movq 0x40(%rax), %rax
subq %rcx, %rax
cqto
idivq %r12
cmpq %r13, %rax
jbe 0x73b4
imulq $0x28, %r13, %rax
movslq (%rcx,%rax), %rax
testq %rax, %rax
leaq (%r15,%rax,8), %rcx
notl %eax
movq 0x30(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
cmovsq %rax, %rcx
movq (%rcx), %rdi
callq 0x1f0d4
leal 0x1(%r13), %eax
jmp 0x736b
movzbl 0x3c(%rsp), %ecx
xorl %r12d, %r12d
movq %r14, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x70f0
movq 0x48(%rsp), %rcx
movq 0x10(%rcx), %rax
cmpq 0x8(%rcx), %rax
je 0x74a8
movq 0x48(%rsp), %rax
movq 0x20(%rax), %rbx
movq 0x28(%rax), %r13
leaq 0xd8(%rsp), %r14
leaq 0xc8(%rsp), %r15
cmpq %r13, %rbx
je 0x7446
movq %r15, %rdi
movq %rbx, %rsi
callq 0x87ee
movl 0xc8(%rsp), %eax
cmpl $0x4, %eax
jne 0x7431
movq 0x40(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq (%rdx,%rcx,8), %rcx
movl %r12d, %edx
imulq $0x38, %rdx, %rdx
movl $0x4, 0x7c(%rcx,%rdx)
cmpl $0x1, %eax
sbbl $-0x1, %r12d
movq %r14, %rdi
callq 0x5200
addq $0x30, %rbx
jmp 0x73f8
cmpb $0x0, 0x3c(%rsp)
je 0x7304
cmpb $0x0, 0x48ffa(%rip)     # 0x50452
jne 0x7304
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
movl 0x9fa0(%rdi), %eax
pushq $0x32
popq %rcx
xorl %edx, %edx
divl %ecx
testl %edx, %edx
je 0x7304
movl %edx, %esi
callq 0x1eb88
testb %al, %al
jne 0x7304
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x1e2d0
jmp 0x7304
movq 0x48(%rsp), %rax
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rax
movq %rax, 0xb8(%rsp)
cmpq %rsi, %rax
je 0x73db
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rcx,%rax,8), %rax
leaq 0x58(%rax), %rcx
movq %rcx, 0xb0(%rsp)
movq %rax, 0x28(%rsp)
addq $0x9fd0, %rax           # imm = 0x9FD0
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x50(%rsp), %r13
cmpq 0xb8(%rsp), %rsi
je 0x73db
leaq 0xc8(%rsp), %rdi
movq %rsi, 0xc0(%rsp)
callq 0x87ee
movl 0xc8(%rsp), %eax
cmpq $0x4, %rax
ja 0x78f5
leaq 0x2baff(%rip), %rcx     # 0x33038
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl 0x20(%rsp), %ebx
jmpq *%rax
imulq $0x38, %rbx, %rax
movq 0xb0(%rsp), %rcx
cmpl $0x0, 0x24(%rcx,%rax)
je 0x7780
fldz
fstpt (%rsp)
movq 0x28(%rsp), %rax
movq 0x9fb8(%rax), %rbp
movq 0x9fc0(%rax), %r15
xorl %r14d, %r14d
cmpq %r15, %rbp
je 0x75b8
movq %r13, %rdi
movq %rbp, %rsi
callq 0x9158
movq 0x50(%rsp), %rax
cmpq $0x0, (%rax,%rbx,8)
je 0x75aa
leaq (%rax,%rbx,8), %rdi
callq 0x8b5e
incl %r14d
fldt (%rax)
fldt (%rsp)
faddp %st, %st(1)
fstpt (%rsp)
movq %r13, %rdi
callq 0x9268
addq $0x18, %rbp
jmp 0x7578
cmpl $0x3, 0xc8(%rsp)
jne 0x780c
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x8b32
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x8ea0
movq 0x90(%rsp), %rdi
jmp 0x78de
andq $0x0, (%rsp)
movq 0x28(%rsp), %rax
movq 0x9fb8(%rax), %rbp
movq 0x9fc0(%rax), %r14
cmpq %r14, %rbp
je 0x7750
movq %r13, %rdi
movq %rbp, %rsi
callq 0x9158
cmpq $0x0, (%rsp)
movq 0x50(%rsp), %rax
movq (%rax,%rbx,8), %rdi
je 0x765f
testq %rdi, %rdi
je 0x766e
leaq (%rax,%rbx,8), %rdi
movq %rsp, %rsi
callq 0x8a44
testb %al, %al
je 0x766e
andq $0x0, (%rsp)
movq 0x50(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x766e
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x766a
testq %rdi, %rdi
je 0x766e
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, (%rsp)
movq %r13, %rdi
callq 0x9268
addq $0x18, %rbp
jmp 0x760b
movq 0x28(%rsp), %rax
movl 0x9fa0(%rax), %eax
movl %eax, 0x50(%rsp)
leaq 0xa8(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8948
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x8ea0
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x78f5
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x78f5
andq $0x0, (%rsp)
movq 0x28(%rsp), %rax
movq 0x9fb8(%rax), %rbp
movq 0x9fc0(%rax), %r14
cmpq %r14, %rbp
je 0x7768
movq %r13, %rdi
movq %rbp, %rsi
callq 0x9158
cmpq $0x0, (%rsp)
movq 0x50(%rsp), %rax
movq (%rax,%rbx,8), %rdi
je 0x7733
testq %rdi, %rdi
je 0x7742
leaq (%rax,%rbx,8), %rdi
movq %rsp, %rsi
callq 0x8974
testb %al, %al
je 0x7742
andq $0x0, (%rsp)
movq 0x50(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x7742
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x773e
testq %rdi, %rdi
je 0x7742
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, (%rsp)
movq %r13, %rdi
callq 0x9268
addq $0x18, %rbp
jmp 0x76df
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x7897
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x7899
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x78b4
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x78b6
andl $0x0, (%rsp)
movq 0x28(%rsp), %rax
movq 0x9fb8(%rax), %rbp
movq 0x9fc0(%rax), %r15
xorl %r14d, %r14d
cmpq %r15, %rbp
je 0x77d5
movq %r13, %rdi
movq %rbp, %rsi
callq 0x9158
movq 0x50(%rsp), %rax
cmpq $0x0, (%rax,%rbx,8)
je 0x77c7
leaq (%rax,%rbx,8), %rdi
callq 0x8b08
incl %r14d
movl (%rax), %eax
addl %eax, (%rsp)
movq %r13, %rdi
callq 0x9268
addq $0x18, %rbp
jmp 0x779a
cmpl $0x3, 0xc8(%rsp)
jne 0x784f
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x8948
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x8ea0
movq 0xa0(%rsp), %rdi
jmp 0x78de
fldt (%rsp)
movl %r14d, 0x84(%rsp)
fidivl 0x84(%rsp)
fstpt 0x50(%rsp)
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8b32
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x8ea0
movq 0x88(%rsp), %rdi
jmp 0x78de
movl (%rsp), %eax
movl %eax, 0x7c(%rsp)
fildl 0x7c(%rsp)
movl %r14d, 0x80(%rsp)
fidivl 0x80(%rsp)
fstpt 0x50(%rsp)
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8b32
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x8ea0
movq 0x98(%rsp), %rdi
jmp 0x78de
xorl %eax, %eax
movq %rax, 0x68(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x8ea0
movq 0x68(%rsp), %rdi
jmp 0x78cf
xorl %eax, %eax
movq %rax, 0x70(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x8ea0
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x78da
movq (%rdi), %rax
callq *0x8(%rax)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x78e9
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x20(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x5200
movq 0xc0(%rsp), %rsi
addq $0x30, %rsi
jmp 0x74fe
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
jmp 0x79ba
jmp 0x79c7
movq %rax, %rbx
movq 0x98(%rsp), %rdi
jmp 0x79ba
jmp 0x79c7
jmp 0x79b3
jmp 0x79b3
movq %rax, %rbx
movq 0x90(%rsp), %rdi
jmp 0x79ba
jmp 0x79c7
movq %rax, %rbx
movq 0x88(%rsp), %rdi
jmp 0x79ba
jmp 0x79c7
movq %rax, %rbx
movq 0x68(%rsp), %rdi
jmp 0x7971
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x79b6
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x79b6
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
jmp 0x79ba
jmp 0x79c7
jmp 0x79a2
jmp 0x7991
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x9268
jmp 0x79b6
jmp 0x79c7
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x9268
jmp 0x79ca
jmp 0x79b3
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x79ca
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x79ca
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x5200
movq %rbx, %rdi
callq 0x56f0