// File: /workspace/github_cpp_makefile_star2_O2/cphinton42[P]hinton-language/src/ast.cpp
// Function: print_dot_rec(Print_Buffer*, AST*)
internal void print_dot_rec(Print_Buffer *pb, AST *ast)
{
    u32 s = ast->s;
    switch(ast->type)
    {
        case AST_Type::ident_ast: {
            Ident_AST *ident_ast = static_cast<Ident_AST*>(ast);
            String str = *ident_ast->atom.str;
            print_buf(pb, "n%ld[label=\"%.*s\"];\n", s, str.count, str.data);
        } break;
        case AST_Type::decl_ast: {
            Decl_AST *decl_ast = static_cast<Decl_AST*>(ast);
            
            String str = *decl_ast->ident.atom.str;
            print_buf(pb, "n%ld[label=\"Declare %.*s\"];\nn%ld[shape=box];\n", s, str.count, str.data, s);
            if(decl_ast->decl_type)
            {
                print_dot_child(pb, decl_ast->decl_type, s);
            }
            if(decl_ast->expr)
            {
                print_dot_child(pb, decl_ast->expr, s);
            }
        } break;
        case AST_Type::block_ast: {
            Block_AST *block_ast = static_cast<Block_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"Block\"];\nn%ld[shape=box];\n", s, s);
            
            for(u64 i = 0; i < block_ast->statements.count; ++i)
            {
                print_dot_child(pb, block_ast->statements[i], s);
            }
        } break;
        case AST_Type::function_type_ast: {
            Function_Type_AST *type_ast = static_cast<Function_Type_AST*>(ast);
            print_buf(pb, "n%ld[label=\"Function Type\"];\n", s);
            
            for(u64 i = 0; i < type_ast->parameter_types.count; ++i)
            {
                if(type_ast->parameter_types[i])
                {
                    print_dot_child(pb, type_ast->parameter_types[i], s);
                }
            }
            for(u64 i = 0; i < type_ast->return_types.count; ++i)
            {
                if(type_ast->return_types[i])
                {
                    print_dot_child(pb, type_ast->return_types[i], s);
                }
            }
        } break;
        case AST_Type::function_ast: {
            Function_AST *function_ast = static_cast<Function_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"Function\"];\nn%ld[shape=box];\n", s, s);
            
            print_dot_child(pb, function_ast->prototype, s);
            for(u64 i = 0; i < function_ast->param_names.count; ++i)
            {
                if(function_ast->param_names[i])
                {
                    print_dot_child(pb, function_ast->param_names[i], s);
                }
            }
            for(u64 i = 0; i < function_ast->default_values.count; ++i)
            {
                if(function_ast->default_values[i])
                {
                    print_dot_child(pb, function_ast->default_values[i], s);
                }
            }
            print_dot_child(pb, function_ast->block, s);
        } break;
        case AST_Type::function_call_ast: {
            Function_Call_AST *call_ast = static_cast<Function_Call_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"function call\"];\n", s);
            print_dot_child(pb, call_ast->function, s);
            for(u64 i = 0; i < call_ast->args.count; ++i)
            {
                print_dot_child(pb, call_ast->args[i], s);
            }
        } break;
        case AST_Type::access_ast: {
            Access_AST *access_ast = static_cast<Access_AST*>(ast);
            print_buf(pb, "n%ld[label=\".\"];\n", s);
            print_dot_child(pb, access_ast->lhs, s);
        } break;
        case AST_Type::binary_operator_ast: {
            Binary_Operator_AST *bin_ast = static_cast<Binary_Operator_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"%s\"];\n", s, binary_operator_names[(u64)bin_ast->op]);
            print_dot_child(pb, bin_ast->lhs, s);
            print_dot_child(pb, bin_ast->rhs, s);
        } break;
        case AST_Type::number_ast: {
            Number_AST *number_ast = static_cast<Number_AST*>(ast);
            print_buf(pb, "n%ld[label=\"%.*s\"];\n", s, (u32)number_ast->literal.count, number_ast->literal.data);
        } break;
        case AST_Type::while_ast: {
            While_AST *while_ast = static_cast<While_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"while\"];\n", s);
            print_dot_child(pb, while_ast->guard, s);
            print_dot_child(pb, while_ast->body, s);
        } break;
        case AST_Type::for_ast: {
            For_AST *for_ast = static_cast<For_AST*>(ast);
            
            if(for_ast->flags & FOR_FLAG_OVER_ARRAY)
            {
                if(for_ast->flags & FOR_FLAG_BY_POINTER)
                {
                    print_buf(pb, "n%ld[label=\"for &(array)\"];\n", s);
                }
                else
                {
                    print_buf(pb, "n%ld[label=\"for (array)\"];\n", s);
                }
            }
            else
            {
                assert(!(for_ast->flags & FOR_FLAG_BY_POINTER));
                print_buf(pb, "n%ld[label=\"for (range)\"];\n", s);
            }
            print_buf(pb, "n%ld[shape=box];\n", s);
            
            if(for_ast->induction_var)
            {
                print_dot_child(pb, for_ast->induction_var, s);
            }
            if(for_ast->flags & FOR_FLAG_OVER_ARRAY)
            {
                if(for_ast->index_var)
                {
                    print_dot_child(pb, for_ast->index_var, s);
                }
                print_dot_child(pb, for_ast->array_expr, s);
            }
            else
            {
                print_dot_child(pb, for_ast->low_expr, s);
                print_dot_child(pb, for_ast->high_expr, s);
            }
            
            print_dot_child(pb, for_ast->body, s);
        } break;
        case AST_Type::if_ast: {
            If_AST *if_ast = static_cast<If_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"if\"];\n", s);
            print_dot_child(pb, if_ast->guard, s);
            print_dot_child(pb, if_ast->then_block, s);
            if(if_ast->else_block)
            {
                print_dot_child(pb, if_ast->else_block, s);
            }
        } break;
        case AST_Type::struct_ast: {
            Struct_AST *struct_ast = static_cast<Struct_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"struct\"];\n", s);
            for(u64 i = 0; i < struct_ast->constants.count; ++i)
            {
                print_dot_child(pb, struct_ast->constants[i], s);
            }
            for(u64 i = 0; i < struct_ast->fields.count; ++i)
            {
                print_dot_child(pb, struct_ast->fields[i], s);
            }
        } break;
        case AST_Type::enum_ast: {
            Enum_AST *enum_ast = static_cast<Enum_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"enum\"];\n", s);
            for(u64 i = 0; i < enum_ast->values.count; ++i)
            {
                print_dot_child(pb, enum_ast->values[i], s);
            }
        } break;
        case AST_Type::assign_ast: {
            Assign_AST *assign_ast = static_cast<Assign_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"%s\"];\n", s, assign_names[(u64)assign_ast->assign_type]);
            print_dot_child(pb, assign_ast->lhs, s);
            print_dot_child(pb, assign_ast->rhs, s);
        } break;
        case AST_Type::unary_ast: {
            Unary_Operator_AST *unary_ast = static_cast<Unary_Operator_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"%s\"];\n", s, unary_operator_names[(u64)unary_ast->op]);
            print_dot_child(pb, unary_ast->operand, s);
        } break;
        case AST_Type::return_ast: {
            Return_AST *return_ast = static_cast<Return_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"return\"];\n", s);
            print_dot_child(pb, return_ast->expr, s);
        } break;
        case AST_Type::primitive_ast: {
            Primitive_AST *primitive_ast = static_cast<Primitive_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"%s\"];\n", s, primitive_names[(u64)primitive_ast->primitive]);
        } break;
        case AST_Type::string_ast: {
            String_AST *string_ast = static_cast<String_AST*>(ast);
            
            print_buf(pb, "n%ld[label=\"\\\"%.*s\\\"\"];\n", s, string_ast->literal.count, string_ast->literal.data);
        } break;
        case AST_Type::bool_ast: {
            Bool_AST *bool_ast = static_cast<Bool_AST*>(ast);
            if(bool_ast->value)
            {
                print_buf(pb, "n%ld[label=\"true\"];\n", s);
            }
            else
            {
                print_buf(pb, "n%ld[label=\"false\"];\n", s);
            }
        } break;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movzwl (%rsi), %eax
cmpq $0x13, %rax
ja 0x3a3e
movq %rsi, %r15
movq %rdi, %r14
movl 0x4(%rsi), %ebx
leaq 0xa6ca(%rip), %rcx      # 0xe010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x30(%r15), %rax
movq (%rax), %rcx
movq 0x8(%rax), %r8
leaq 0xba27(%rip), %rsi      # 0xf388
movq %r14, %rdi
movl %ebx, %edx
movl %ebx, %r9d
xorl %eax, %eax
callq 0x389d
movq 0x50(%r15), %rsi
testq %rsi, %rsi
je 0x3984
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
movq 0x58(%r15), %rsi
jmp 0x3a35
movq 0x20(%r15), %rax
leaq 0x10d68(%rip), %rcx     # 0x14700
movq (%rcx,%rax,8), %rcx
leaq 0xbab2(%rip), %rsi      # 0xf455
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
jmp 0x3df0
leaq 0xbba0(%rip), %rsi      # 0xf55b
xorl %r12d, %r12d
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
cmpq 0x20(%r15), %r12
jae 0x3a3e
movq 0x28(%r15), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
incq %r12
jmp 0x39ca
leaq 0xba54(%rip), %rsi      # 0xf443
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
jmp 0x3c4d
leaq 0xbb2a(%rip), %rsi      # 0xf531
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
movq 0x10(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
movq 0x18(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
movq 0x20(%r15), %rsi
testq %rsi, %rsi
jne 0x3df4
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x20(%r15), %rax
leaq 0x10c3b(%rip), %rcx     # 0x14690
movq (%rcx,%rax,8), %rcx
leaq 0xb9f5(%rip), %rsi      # 0xf455
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
movq 0x28(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
movq 0x30(%r15), %rsi
jmp 0x3df4
leaq 0xb970(%rip), %rsi      # 0xf3fb
xorl %r12d, %r12d
movq %r14, %rdi
movl %ebx, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x389d
movq 0x20(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
cmpq 0x28(%r15), %r12
jae 0x3ace
movq 0x30(%r15), %rax
movq (%rax,%r12,8), %rsi
testq %rsi, %rsi
je 0x3ac9
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
incq %r12
jmp 0x3aab
xorl %r12d, %r12d
cmpq 0x38(%r15), %r12
jae 0x3af4
movq 0x40(%r15), %rax
movq (%rax,%r12,8), %rsi
testq %rsi, %rsi
je 0x3aef
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
incq %r12
jmp 0x3ad1
movq 0x48(%r15), %rsi
jmp 0x3df4
leaq 0xb964(%rip), %rsi      # 0xf468
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
movq 0x10(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
jmp 0x3c8f
leaq 0xba19(%rip), %rsi      # 0xf544
xorl %r12d, %r12d
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
cmpq 0x20(%r15), %r12
jae 0x3b58
movq 0x28(%r15), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
incq %r12
jmp 0x3b3a
xorl %r12d, %r12d
cmpq 0x30(%r15), %r12
jae 0x3a3e
movq 0x38(%r15), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
incq %r12
jmp 0x3b5b
movzwl 0x2(%r15), %eax
testb $0x8, %al
jne 0x3d7f
testb $0x4, %al
jne 0x3e28
leaq 0xb97c(%rip), %rsi      # 0xf515
jmp 0x3d93
movq 0x20(%r15), %rax
movq (%rax), %rcx
movq 0x8(%rax), %r8
leaq 0xb7c3(%rip), %rsi      # 0xf373
jmp 0x3ca7
leaq 0xb7fa(%rip), %rsi      # 0xf3b6
xorl %r12d, %r12d
movq %r14, %rdi
movl %ebx, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x389d
cmpq 0x10(%r15), %r12
jae 0x3a3e
movq 0x18(%r15), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
incq %r12
jmp 0x3bcd
movq 0x20(%r15), %rax
leaq 0x10566(%rip), %rcx     # 0x14160
movq (%rcx,%rax,8), %rcx
leaq 0xb850(%rip), %rsi      # 0xf455
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x389d
movq 0x10(%r15), %rax
leaq 0x10aa9(%rip), %rcx     # 0x146d0
movq (%rcx,%rax,8), %rcx
leaq 0xb823(%rip), %rsi      # 0xf455
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
movq 0x18(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
movq 0x20(%r15), %rsi
jmp 0x3df4
movl 0x20(%r15), %ecx
movq 0x28(%r15), %r8
leaq 0xb70e(%rip), %rsi      # 0xf373
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x389d
leaq 0xb8ed(%rip), %rsi      # 0xf570
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
movq 0x18(%r15), %rsi
jmp 0x3df4
movq 0x20(%r15), %rcx
movq 0x28(%r15), %r8
leaq 0xb8e0(%rip), %rsi      # 0xf587
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x389d
leaq 0xb760(%rip), %rsi      # 0xf425
xorl %r12d, %r12d
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
movq 0x20(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
cmpq 0x28(%r15), %r12
jae 0x3a3e
movq 0x30(%r15), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
incq %r12
jmp 0x3ce3
leaq 0xb6d1(%rip), %rsi      # 0xf3dd
xorl %r12d, %r12d
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
cmpq 0x20(%r15), %r12
jae 0x3d3e
movq 0x28(%r15), %rax
movq (%rax,%r12,8), %rsi
testq %rsi, %rsi
je 0x3d39
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
incq %r12
jmp 0x3d1b
xorl %r12d, %r12d
cmpq 0x30(%r15), %r12
jae 0x3a3e
movq 0x38(%r15), %rax
movq (%rax,%r12,8), %rsi
testq %rsi, %rsi
je 0x3d63
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
incq %r12
jmp 0x3d41
cmpb $0x1, 0x20(%r15)
jne 0x3e0a
leaq 0xb826(%rip), %rsi      # 0xf5a0
jmp 0x3e11
testb $0x4, %al
leaq 0xb713(%rip), %rax      # 0xf49b
leaq 0xb6ef(%rip), %rsi      # 0xf47e
cmoveq %rax, %rsi
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
leaq 0xb625(%rip), %rsi      # 0xf3cb
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x389d
movq 0x10(%r15), %rsi
testq %rsi, %rsi
je 0x3dc6
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
testb $0x8, 0x2(%r15)
movq 0x18(%r15), %rsi
je 0x3dd6
testq %rsi, %rsi
je 0x3de1
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
movq 0x20(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xb0a4
movq 0x28(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xb0a4
leaq 0xb7a4(%rip), %rsi      # 0xf5b5
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x389d
leaq 0xb688(%rip), %rdi      # 0xf4b7
leaq 0xb6a9(%rip), %rsi      # 0xf4df
leaq 0xb6ae(%rip), %rcx      # 0xf4eb
movl $0x112, %edx            # imm = 0x112
callq 0x3080