// File: /workspace/github_cpp_makefile_star2_O3/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, 0x40(%rsp)
shlq $0x7, %rax
cmpb $0x0, 0x848(%rdi,%rax)
je 0x8396
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r13
movl %esi, 0x14(%rsp)
movl %edx, 0x2c(%rsp)
leaq (%rdi,%rax), %rbp
addq $0x848, %rbp            # imm = 0x848
movb $0x1, (%rbp)
movq 0x68(%rbp), %rbx
movq 0x70(%rbp), %r14
cmpq %r14, %rbx
je 0x83d1
movl (%rbx), %esi
notl %esi
movq %r13, %rdi
xorl %edx, %edx
callq 0x835e
addq $0x4, %rbx
jmp 0x83b8
movb $0x0, 0x4b06a(%rip)     # 0x53442
movq 0x38(%rbp), %rax
cmpq %rax, 0x40(%rbp)
je 0x843e
leaq 0x8848(%r13), %rbx
leaq 0x20(%r13), %r14
movl $0x1, %r15d
xorl %ecx, %ecx
movabsq $-0x3333333333333333, %r12 # imm = 0xCCCCCCCCCCCCCCCD
leaq (%rcx,%rcx,4), %rcx
movslq (%rax,%rcx,8), %rax
testq %rax, %rax
leaq (%r14,%rax,8), %rcx
notl %eax
leaq (%rbx,%rax,8), %rax
cmovsq %rax, %rcx
movq (%rcx), %rdi
callq 0x25a6c
movl %r15d, %ecx
movq 0x38(%rbp), %rax
movq 0x40(%rbp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
incl %r15d
cmpq %rcx, %rdx
ja 0x83ff
movzbl 0x2c(%rsp), %ecx
movq %r13, 0xd8(%rsp)
movq %r13, %rdi
movl 0x14(%rsp), %esi
xorl %edx, %edx
callq 0x8024
movq 0x10(%rbp), %rax
movq %rbp, 0xe0(%rsp)
cmpq 0x8(%rbp), %rax
jne 0x89cd
movq 0xe0(%rsp), %rax
movq 0x20(%rax), %r14
movq 0x28(%rax), %rax
movq %rax, 0x100(%rsp)
cmpq %r14, %rax
je 0x89cd
movq 0xd8(%rsp), %rax
movq 0x40(%rsp), %rcx
movq 0x8848(%rax,%rcx,8), %rax
leaq 0xc8(%rsp), %r13
leaq 0x58(%rax), %rcx
movq %rcx, 0xf8(%rsp)
movq %rax, 0x38(%rsp)
addq $0x9fd0, %rax           # imm = 0x9FD0
movq %rax, 0x20(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x90(%rsp), %r12
movl 0x8(%r14), %eax
movl %eax, 0xb0(%rsp)
movq (%r14), %rax
movq %rax, 0xa8(%rsp)
movq %r13, 0xb8(%rsp)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0xa5ec
movl 0xa8(%rsp), %eax
cmpq $0x4, %rax
ja 0x899e
leaq 0x33b10(%rip), %rdx     # 0x3c038
movslq (%rdx,%rax,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl 0x8(%rsp), %r15d
imulq $0x38, %r15, %rcx
movq 0xf8(%rsp), %rdx
cmpl $0x0, 0x24(%rdx,%rcx)
movq 0x38(%rsp), %rcx
movq 0x9fb8(%rcx), %rbp
movq 0x9fc0(%rcx), %rbx
je 0x87e8
fldz
fld %st(0)
fstpt 0x14(%rsp)
fstpt 0xec(%rsp)
cmpq %rbx, %rbp
je 0x85e7
movq %r14, 0x30(%rsp)
xorl %r14d, %r14d
fldz
fstpt 0x14(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0xa26a
movq 0x90(%rsp), %rax
cmpq $0x0, (%rax,%r15,8)
je 0x85b4
leaq (%rax,%r15,8), %rdi
callq 0x9dc2
incl %r14d
fldt (%rax)
fldt 0x14(%rsp)
faddp %st, %st(1)
fstpt 0x14(%rsp)
movq %r12, %rdi
callq 0xa37e
addq $0x18, %rbp
cmpq %rbx, %rbp
jne 0x8582
movl 0xa8(%rsp), %eax
movl %r14d, 0x8c(%rsp)
fildl 0x8c(%rsp)
fstpt 0xec(%rsp)
movq 0x30(%rsp), %r14
cmpl $0x3, %eax
jne 0x885a
movl $0x20, %edi
callq 0x5390
leaq 0x4a49f(%rip), %rcx     # 0x52aa0
movq %rcx, (%rax)
fldt 0x14(%rsp)
fstpt 0x10(%rax)
movq %rax, 0x50(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x9f9a
movq 0x50(%rsp), %rdi
jmp 0x8987
movq $0x0, (%rsp)
movq 0x38(%rsp), %rax
movq 0x9fb8(%rax), %rbp
movq 0x9fc0(%rax), %rbx
cmpq %rbx, %rbp
je 0x889c
movq %r14, %r15
movl 0x8(%rsp), %r14d
movq %r12, %rdi
movq %rbp, %rsi
callq 0xa26a
cmpq $0x0, (%rsp)
movq 0x90(%rsp), %rax
movq (%rax,%r14,8), %rdi
je 0x86a9
testq %rdi, %rdi
je 0x86b8
leaq (%rax,%r14,8), %rdi
movq %rsp, %rsi
callq 0x9ca8
testb %al, %al
je 0x86b8
movq 0x90(%rsp), %rax
movq $0x0, (%rsp)
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x86b8
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x86b4
testq %rdi, %rdi
je 0x86b8
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, (%rsp)
movq %r12, %rdi
callq 0xa37e
addq $0x18, %rbp
cmpq %rbx, %rbp
jne 0x8655
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x893a
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x893c
movq 0x38(%rsp), %rax
movl 0x9fa0(%rax), %ebx
movl $0x10, %edi
callq 0x5390
leaq 0x4a37b(%rip), %rcx     # 0x52a78
movq %rcx, (%rax)
movl %ebx, 0x8(%rax)
movq %rax, 0x78(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x9f9a
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x899e
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x899e
movq $0x0, (%rsp)
movq 0x38(%rsp), %rax
movq 0x9fb8(%rax), %rbp
movq 0x9fc0(%rax), %rbx
cmpq %rbx, %rbp
je 0x88a3
movq %r14, %r15
movl 0x8(%rsp), %r14d
movq %r12, %rdi
movq %rbp, %rsi
callq 0xa26a
cmpq $0x0, (%rsp)
movq 0x90(%rsp), %rax
movq (%rax,%r14,8), %rdi
je 0x87b0
testq %rdi, %rdi
je 0x87bf
leaq (%rax,%r14,8), %rdi
movq %rsp, %rsi
callq 0x9bae
testb %al, %al
je 0x87bf
movq 0x90(%rsp), %rax
movq $0x0, (%rsp)
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x87bf
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x87bb
testq %rdi, %rdi
je 0x87bf
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, (%rsp)
movq %r12, %rdi
callq 0xa37e
addq $0x18, %rbp
cmpq %rbx, %rbp
jne 0x875c
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x895a
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x895c
movq %r14, 0x30(%rsp)
cmpq %rbx, %rbp
je 0x88aa
xorl %r13d, %r13d
xorl %r14d, %r14d
movq %r12, %rdi
movq %rbp, %rsi
callq 0xa26a
movq 0x90(%rsp), %rax
cmpq $0x0, (%rax,%r15,8)
je 0x8825
leaq (%rax,%r15,8), %rdi
callq 0x9d98
incl %r13d
addl (%rax), %r14d
movq %r12, %rdi
callq 0xa37e
addq $0x18, %rbp
cmpq %rbx, %rbp
jne 0x87fc
movl 0xa8(%rsp), %eax
movl %r13d, 0x88(%rsp)
fildl 0x88(%rsp)
fstpt 0x14(%rsp)
leaq 0xc8(%rsp), %r13
jmp 0x88b3
movl $0x20, %edi
callq 0x5390
fldt 0x14(%rsp)
fldt 0xec(%rsp)
fdivrp %st, %st(1)
leaq 0x4a228(%rip), %rcx     # 0x52aa0
movq %rcx, (%rax)
fstpt 0x10(%rax)
movq %rax, 0x48(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x9f9a
movq 0x48(%rsp), %rdi
jmp 0x8987
xorl %eax, %eax
jmp 0x893f
xorl %eax, %eax
jmp 0x895f
xorl %r14d, %r14d
fldz
fstpt 0x14(%rsp)
cmpl $0x3, %eax
jne 0x88eb
movl $0x10, %edi
callq 0x5390
leaq 0x4a1af(%rip), %rcx     # 0x52a78
movq %rcx, (%rax)
movl %r14d, 0x8(%rax)
movq %rax, 0x60(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x9f9a
movq 0x60(%rsp), %rdi
jmp 0x892e
movl $0x20, %edi
callq 0x5390
movl %r14d, 0x84(%rsp)
fldt 0x14(%rsp)
fidivrl 0x84(%rsp)
leaq 0x4a191(%rip), %rcx     # 0x52aa0
movq %rcx, (%rax)
fstpt 0x10(%rax)
movq %rax, 0x58(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x9f9a
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
movq 0x30(%rsp), %r14
jne 0x898c
jmp 0x8992
xorl %eax, %eax
movq %r15, %r14
movq %rax, 0x68(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x9f9a
movq 0x68(%rsp), %rdi
jmp 0x8978
xorl %eax, %eax
movq %r15, %r14
movq %rax, 0x70(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x9f9a
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8983
movq (%rdi), %rax
callq *0x8(%rax)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8992
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x89bb
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x53a0
addq $0x30, %r14
cmpq 0x100(%rsp), %r14
jne 0x84da
movq 0xe0(%rsp), %rax
movq 0x20(%rax), %rbx
movq 0x28(%rax), %r15
cmpq %r15, %rbx
movq 0xd8(%rsp), %r13
je 0x8a87
leaq 0xb8(%rsp), %r14
xorl %ebp, %ebp
leaq 0xc8(%rsp), %r12
movl 0x8(%rbx), %eax
movl %eax, 0xb0(%rsp)
movq (%rbx), %rax
movq %rax, 0xa8(%rsp)
movq %r12, 0xb8(%rsp)
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xa5ec
movl 0xa8(%rsp), %eax
cmpl $0x4, %eax
jne 0x8a57
movq 0x40(%rsp), %rcx
movq 0x8848(%r13,%rcx,8), %rcx
movl %ebp, %edx
imulq $0x38, %rdx, %rdx
movl $0x4, 0x7c(%rcx,%rdx)
cmpl $0x1, %eax
sbbl $-0x1, %ebp
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0x8a7a
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x53a0
addq $0x30, %rbx
cmpq %r15, %rbx
jne 0x8a00
cmpb $0x0, 0x2c(%rsp)
je 0x8384
cmpb $0x0, 0x4a9a9(%rip)     # 0x53442
jne 0x8384
movq 0x40(%rsp), %rax
movq 0x8848(%r13,%rax,8), %rdi
movl 0x9fa0(%rdi), %esi
imulq $0x51eb851f, %rsi, %rax # imm = 0x51EB851F
shrq $0x24, %rax
imull $0x32, %eax, %eax
subl %eax, %esi
je 0x8384
callq 0x2547a
testb %al, %al
jne 0x8384
movq 0x40(%rsp), %rax
movq 0x8848(%r13,%rax,8), %rdi
callq 0x24888
jmp 0x8384
movq %rax, %rbx
movq 0x60(%rsp), %rdi
jmp 0x8b87
jmp 0x8b94
movq %rax, %rbx
movq 0x58(%rsp), %rdi
jmp 0x8b87
jmp 0x8b94
jmp 0x8b80
jmp 0x8b80
movq %rax, %rbx
movq 0x50(%rsp), %rdi
jmp 0x8b87
jmp 0x8b94
movq %rax, %rbx
movq 0x48(%rsp), %rdi
jmp 0x8b87
jmp 0x8b94
movq %rax, %rbx
movq 0x78(%rsp), %rdi
jmp 0x8b87
jmp 0x8b94
movq %rax, %rbx
movq 0x70(%rsp), %rdi
jmp 0x8b47
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x8b83
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x8b83
jmp 0x8b6c
jmp 0x8b58
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0xa37e
jmp 0x8b83
jmp 0x8b94
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0xa37e
jmp 0x8b97
jmp 0x8b80
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8b97
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x8b97
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x8bbc
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x53a0
movq %rbx, %rdi
callq 0x56e0