// File: /workspace/github_cpp_makefile_star2_O2/SunriseFox[P]very-simple-c-compiler/./src/main.cpp
// Function: showTree(TreeNode*)
void showTree(TreeNode* root) {

    if (root == nullptr) return;

    auto children = root -> child;
    while (children) {
        showTree(children);
        children = children -> sibling;
    }
    Symbol* ownSymbol = nullptr;

    cout << "(Line " << root -> lineno << ") " << root->nodeID << ": ";
    switch (root->nodeType) {
    case TreeNode::NODE_NONE:
        cout << "[Unknown] ";
        break;
    case TreeNode::NODE_STATMENT:
        cout << "[Statement ";
        switch (static_cast<StatementNode*>(root)->type) {
        case StatementNode::ST_NONE:
            cout << "Unknown";
            break;
        case StatementNode::ST_EMPTY:
            cout << "Empty";
            break;
        case StatementNode::ST_SCOPE:
            cout << "Scope";
            break;
        case StatementNode::ST_RET:
            cout << "Return";
            break;
        case StatementNode::ST_DO_WHILE:
            cout << "Do-While";
            break;
        case StatementNode::ST_WHILE:
            cout << "While";
            break;
        case StatementNode::ST_FOR:
            cout << "For";
            break;
        case StatementNode::ST_FUNCTION:
            cout << "Function<";
            cout << static_cast<FuncStatementNode*>(root)->symbol->value << ">";
            break;
        case StatementNode::ST_IF:
            cout << "If";
            break;
        case StatementNode::ST_IF_ELSE:
            cout << "If-Else";
            break;
        case StatementNode::ST_BREAK:
            cout << "Break";
            break;
        case StatementNode::ST_CONTINUE:
            cout << "Continue";
            break;
        case StatementNode::ST_GOTO:
            cout << "Goto";
            break;
        }
        cout << "]";
        break;

    case TreeNode::NODE_FUNCCALL:
        cout << "[FuncCall<";
        ownSymbol = static_cast<DeclarationNode*>(root)->symbol;
        cout << Symbol::getSymbolName(ownSymbol);
        cout << "> " <<static_cast<DeclarationNode*>(root)->symbol->value << "] ";
        break;

    case TreeNode::NODE_DECLARATION:
        cout << "[Declaration<";
        // fall through
        [[clang::fallthrough]];
    case TreeNode::NODE_EXPRESSION:
        if(root->nodeType == TreeNode::NODE_EXPRESSION)
            cout << "[Expression<";

        ownSymbol = static_cast<DeclarationNode*>(root)->symbol;

        cout << Symbol::getSymbolName(ownSymbol);

        cout << "> " <<static_cast<DeclarationNode*>(root)->symbol->value << "] ";
        break;

    case TreeNode::NODE_OPERATOR:
        ownSymbol = root->symbol = new OpNode(root->child->symbol->type, "");
        cout << "[Operator ";
        cout << OperatorNode::getTypeStr(static_cast<OperatorNode*>(root)->type);
        cout << " <";
        cout << Symbol::getSymbolName(ownSymbol);
        cout << ">]";
        switch (static_cast<OperatorNode*>(root)->type) {
        case OperatorNode::OP_ASSIGN:
        case OperatorNode::OP_ADDAS:
        case OperatorNode::OP_SUBAS:
        case OperatorNode::OP_MULAS:
        case OperatorNode::OP_DIVAS:
        case OperatorNode::OP_BORAS:
        case OperatorNode::OP_BANDAS:
        case OperatorNode::OP_BXORAS:
        case OperatorNode::OP_LSHFTAS:
        case OperatorNode::OP_RSHFTAS:
        default: break;
        }
        break;
    }
    children = root -> child;
    if(children) {
        cout << endl << "\tChildren: ";
    }
    while (children) {
        cout << children->nodeID << " ";
        children = children -> sibling;
    }
    cout << endl;
    children = root -> child;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
testq %rdi, %rdi
je 0x6f1d
movq %rdi, %rbx
leaq 0x18(%rdi), %r12
movq %r12, %r14
movq (%r14), %r14
testq %r14, %r14
je 0x6b85
movq %r14, %rdi
callq 0x6b50
addq $0x20, %r14
jmp 0x6b6f
movq 0xb434(%rip), %rdi      # 0x11fc0
leaq 0x4b05(%rip), %rsi      # 0xb698
callq 0x31d0
movl 0xc(%rbx), %esi
movq %rax, %rdi
callq 0x3370
leaq 0x4af5(%rip), %rsi      # 0xb69f
movq %rax, %rdi
callq 0x31d0
movl 0x8(%rbx), %esi
movq %rax, %rdi
callq 0x3370
leaq 0x4b9f(%rip), %rsi      # 0xb763
movq %rax, %rdi
callq 0x31d0
movl 0x10(%rbx), %eax
cmpq $0x5, %rax
ja 0x6ebd
leaq 0x4a6c(%rip), %rcx      # 0xb64c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xb3d0(%rip), %rdi      # 0x11fc0
leaq 0x4aab(%rip), %rsi      # 0xb6a2
jmp 0x6eb8
pushq $0x30
popq %rdi
callq 0x31e0
movq %rax, %r14
movq (%r12), %rax
movq 0x28(%rax), %rax
movl (%rax), %ebp
leaq 0x478e(%rip), %rsi      # 0xb3a6
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
callq 0x615c
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0xa31e
movq %r14, 0x28(%rbx)
leaq 0x20(%rsp), %rdi
callq 0x30f0
movq 0xb377(%rip), %r15      # 0x11fc0
leaq 0x4ae3(%rip), %rsi      # 0xb733
movq %r15, %rdi
callq 0x31d0
movl 0x30(%rbx), %esi
movq %rsp, %rbx
movq %rbx, %rdi
callq 0xa5cc
movq %r15, %rdi
movq %rbx, %rsi
callq 0x31c0
movq %rsp, %rdi
callq 0x30f0
movq 0xb340(%rip), %rbx      # 0x11fc0
leaq 0x4ab7(%rip), %rsi      # 0xb73e
movq %rbx, %rdi
callq 0x31d0
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xa160
movq %rbx, %rdi
movq %r15, %rsi
callq 0x31c0
movq %rsp, %rdi
callq 0x30f0
movq 0xb309(%rip), %rdi      # 0x11fc0
leaq 0x4a83(%rip), %rsi      # 0xb741
jmp 0x6eb8
movq 0xb2f6(%rip), %rdi      # 0x11fc0
leaq 0x4a47(%rip), %rsi      # 0xb718
callq 0x31d0
cmpl $0x3, 0x10(%rbx)
jne 0x6cef
movq 0xb2dd(%rip), %rdi      # 0x11fc0
leaq 0x4a3c(%rip), %rsi      # 0xb726
callq 0x31d0
movq 0x28(%rbx), %rsi
movq %rsp, %r14
movq %r14, %rdi
callq 0xa160
movq 0xb2bb(%rip), %rdi      # 0x11fc0
movq %r14, %rsi
callq 0x31c0
jmp 0x6d82
movq 0xb2aa(%rip), %rdi      # 0x11fc0
leaq 0x4990(%rip), %rsi      # 0xb6ad
callq 0x31d0
movl 0x30(%rbx), %eax
cmpq $0xc, %rax
ja 0x6eaa
leaq 0x492e(%rip), %rcx      # 0xb664
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xb27a(%rip), %rdi      # 0x11fc0
leaq 0x496c(%rip), %rsi      # 0xb6b9
jmp 0x6ea5
movq 0xb267(%rip), %r14      # 0x11fc0
leaq 0x49aa(%rip), %rsi      # 0xb70a
movq %r14, %rdi
callq 0x31d0
movq 0x28(%rbx), %rsi
movq %rsp, %r15
movq %r15, %rdi
callq 0xa160
movq %r14, %rdi
movq %r15, %rsi
callq 0x31c0
movq %rsp, %rdi
callq 0x30f0
movq 0xb22f(%rip), %rdi      # 0x11fc0
leaq 0x497d(%rip), %rsi      # 0xb715
callq 0x31d0
movq 0x28(%rbx), %rsi
addq $0x8, %rsi
movq %rax, %rdi
callq 0x31c0
leaq 0x48f6(%rip), %rsi      # 0xb6aa
movq %rax, %rdi
jmp 0x6eb8
movq 0xb1fd(%rip), %rdi      # 0x11fc0
leaq 0x493b(%rip), %rsi      # 0xb705
jmp 0x6ea5
movq 0xb1ea(%rip), %rdi      # 0x11fc0
leaq 0x48f7(%rip), %rsi      # 0xb6d4
jmp 0x6ea5
movq 0xb1d7(%rip), %r14      # 0x11fc0
leaq 0x48f1(%rip), %rsi      # 0xb6e1
movq %r14, %rdi
callq 0x31d0
movq 0x28(%rbx), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x31c0
leaq 0x66c6(%rip), %rsi      # 0xd4d5
movq %rax, %rdi
jmp 0x6ea5
movq 0xb1a2(%rip), %rdi      # 0x11fc0
leaq 0x48d1(%rip), %rsi      # 0xb6f6
jmp 0x6ea5
movq 0xb192(%rip), %rdi      # 0x11fc0
leaq 0x4892(%rip), %rsi      # 0xb6c7
jmp 0x6ea5
movq 0xb182(%rip), %rdi      # 0x11fc0
leaq 0x4888(%rip), %rsi      # 0xb6cd
jmp 0x6ea5
movq 0xb172(%rip), %rdi      # 0x11fc0
leaq 0x4896(%rip), %rsi      # 0xb6eb
jmp 0x6ea5
movq 0xb162(%rip), %rdi      # 0x11fc0
leaq 0x485c(%rip), %rsi      # 0xb6c1
jmp 0x6ea5
movq 0xb152(%rip), %rdi      # 0x11fc0
leaq 0x4862(%rip), %rsi      # 0xb6d7
jmp 0x6ea5
movq 0xb142(%rip), %rdi      # 0x11fc0
leaq 0x4858(%rip), %rsi      # 0xb6dd
jmp 0x6ea5
movq 0xb132(%rip), %rdi      # 0x11fc0
leaq 0x4867(%rip), %rsi      # 0xb6fc
jmp 0x6ea5
movq 0xb122(%rip), %rdi      # 0x11fc0
leaq 0x4849(%rip), %rsi      # 0xb6ee
callq 0x31d0
movq 0xb10f(%rip), %rdi      # 0x11fc0
leaq 0x488a(%rip), %rsi      # 0xb742
callq 0x31d0
movq (%r12), %r15
testq %r15, %r15
je 0x6ee1
movq 0xb0f3(%rip), %rdi      # 0x11fc0
callq 0x3100
leaq 0x486b(%rip), %rsi      # 0xb744
movq %rax, %rdi
callq 0x31d0
movq 0xb0d8(%rip), %rbx      # 0x11fc0
leaq 0x47b1(%rip), %r14      # 0xb6a0
testq %r15, %r15
je 0x6f11
movl 0x8(%r15), %esi
movq %rbx, %rdi
callq 0x3370
movq %rax, %rdi
movq %r14, %rsi
callq 0x31d0
movq 0x20(%r15), %r15
jmp 0x6eef
movq 0xb0a8(%rip), %rdi      # 0x11fc0
callq 0x3100
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6f4f
jmp 0x6f4f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x30f0
jmp 0x6f42
jmp 0x6f4f
movq %rax, %rbx
pushq $0x30
popq %rsi
movq %r14, %rdi
callq 0x31f0
jmp 0x6f5a
movq %rax, %rbx
movq %rsp, %rdi
callq 0x30f0
movq %rbx, %rdi
callq 0x3390