// File: /workspace/github_cpp_makefile_star2_O2/JameyWoo[P]csmile/parse.cpp
// Function: preOrder(TreeNode*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void preOrder(TreeNode* t, string indent) {
    // if (t != NULL)
    //     out << "t->nodekind = " << t->nodekind << endl;
    if (t == NULL) {
        out << "NULL!" << endl;
        return;
    }
    if (t->nodekind == "FunDecl") {
        out << indent << "FunctionDeclaration {\n"
            << indent << "  type: FunctionDeclaration\n"
            << indent << "  id: " << t->child[1]->name << endl
            << indent << "  params: [\n";
        TreeNode* param = t->child[2]->child[0];
        while (param != NULL) {
            if (param->nodekind == "void") {
                out << indent << "    " << param->nodekind << endl;
            } else {
                out << indent << "    " << param->child[0]->nodekind << ": " << param->child[1]->name << endl;
            }
            param = param->sibling;
        }
        out << indent << "  ]\n"
            << indent << "  body: BlockStatement {\n"
            << indent << "    type: BlockStatement\n"
            << indent << "    body: [\n";
        preOrder(t->child[3], indent + "      ");
        out << indent << "    ]\n"
            << indent << "  }\n"
            << indent << "}\n";
        if (t->sibling != NULL) preOrder(t->sibling, indent);
        return;
    }
    if (t->nodekind == "Compound") {
        if (t->child[1] != NULL) {
            TreeNode* loc = t->child[0];
            out << indent << loc->nodekind << ":{\n";
            while (loc != NULL) {
                out << indent << "  " << loc->child[0]->nodekind << ": " << loc->child[1]->name << endl;
                loc = loc->sibling;
            }
            out << indent << "}\n";
        }
        TreeNode* stmt = NULL;
        if (t->child[1] == NULL) {
            stmt = t->child[0];
        } else
            stmt = t->child[1];
        while (stmt != NULL) {
            preOrder(stmt, indent);
            stmt = stmt->sibling;
        }
        return;
    }
    if (t->nodekind == "ReturnStmt") {
        out << indent << t->nodekind << ": {\n";
        preOrder(t->child[0], indent + "  ");
        out << indent << "}\n";
        return;
    }
    if (t->nodekind == "Id") {
        out << indent << t->nodekind << ": " << t->name << endl;
    } else if (t->nodekind == "Const") {
        out << indent << t->nodekind << ": " << t->val << endl;
    } else if (t->nodekind != "Input") {
        out << indent << t->nodekind << ": {\n";
    } else {  // ReturnStmt 会出现在这里输出
        out << indent << t->nodekind << endl;
    }

    for (int i = 0; i < MAX_CHILDREN; ++i) {
        // out << "i = " << i << endl;
        if (t->child[i] == NULL) break;
        blank += 2;
        if (i == 2 && t->nodekind == "Selection") {
            if (t->child[2] != NULL) {
                out << indent << "Else:\n";
            }
        }
        preOrder(t->child[i], indent + "  ");
        blank -= 2;
    }
    if (t->nodekind != "Id" && t->nodekind != "Input" && t->nodekind != "Const") {
        out << indent << "}\n";
    }
    // Assign 的sibling会重复
    // out << "t->nodekind = " << t->nodekind << endl;
    if (t->sibling != NULL) {
        if (t->nodekind != "Assign") {
            preOrder(t->sibling, indent);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
testq %rdi, %rdi
je 0x6940
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x30(%rdi), %r15
leaq 0x8aa6(%rip), %rsi      # 0xf2b1
movq %r15, %rdi
callq 0x368e
testb %al, %al
je 0x696c
leaq 0xfce6(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
leaq 0x8a8e(%rip), %rsi      # 0xf2bf
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21a0
leaq 0x8a8b(%rip), %rsi      # 0xf2d6
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21a0
leaq 0x8a8e(%rip), %rsi      # 0xf2f3
movq %rax, %rdi
callq 0x21b0
movl $0xc0, %ecx
movq 0x8(%r14), %rsi
addq %rcx, %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21a0
leaq 0x8a5f(%rip), %rsi      # 0xf2fa
movq %rax, %rdi
callq 0x21b0
movq %r14, (%rsp)
movq 0x10(%r14), %r15
leaq 0x88c6(%rip), %r12      # 0xf178
leaq 0x8a91(%rip), %r13      # 0xf34a
movq (%r15), %r15
testq %r15, %r15
je 0x6a2b
leaq 0x30(%r15), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x368e
movl %eax, %ebp
leaq 0xfc2b(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
movq %rax, %rdi
movq %r13, %rsi
callq 0x21b0
testb %bpl, %bpl
je 0x68fd
movq %rax, %rdi
movq %r14, %rsi
jmp 0x692a
movq (%r15), %rsi
addq $0x30, %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
leaq 0x89e1(%rip), %rsi      # 0xf2f7
callq 0x21b0
movq 0x8(%r15), %rsi
movl $0xc0, %ecx
addq %rcx, %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
addq $0x20, %r15
jmp 0x68b9
leaq 0xfbc1(%rip), %rdi      # 0x16508
leaq 0x896b(%rip), %rsi      # 0xf2b9
callq 0x21b0
movq %rax, %rdi
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20f0
leaq 0x892b(%rip), %rsi      # 0xf29e
movq %r15, %rdi
callq 0x368e
testb %al, %al
je 0x6b5a
cmpq $0x0, 0x8(%r14)
je 0x6e42
movq %r14, (%rsp)
movq (%r14), %r14
leaq 0xfb6c(%rip), %r15      # 0x16508
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21a0
leaq 0x30(%r14), %rsi
movq %rax, %rdi
callq 0x21a0
leaq 0x89b4(%rip), %rsi      # 0xf36e
movq %rax, %rdi
callq 0x21b0
leaq 0x8983(%rip), %r12      # 0xf34c
leaq 0x8927(%rip), %r13      # 0xf2f7
movl $0xc0, %ebp
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21a0
testq %r14, %r14
je 0x6bec
movq %rax, %rdi
movq %r12, %rsi
callq 0x21b0
movq (%r14), %rsi
addq $0x30, %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movq %r13, %rsi
callq 0x21b0
movq 0x8(%r14), %rsi
addq %rbp, %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
movq 0x20(%r14), %r14
jmp 0x69d5
leaq 0xfad6(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
leaq 0x8910(%rip), %rsi      # 0xf351
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21a0
leaq 0x88ac(%rip), %rsi      # 0xf307
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21a0
leaq 0x88ac(%rip), %rsi      # 0xf321
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21a0
leaq 0x88ac(%rip), %rsi      # 0xf33b
movq %rax, %rdi
callq 0x21b0
movq (%rsp), %r15
movq 0x18(%r15), %r14
leaq 0x88a2(%rip), %rdx      # 0xf348
leaq 0x88(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x70e5
movq %r14, %rdi
movq %r12, %rsi
callq 0x67e0
leaq 0x88(%rsp), %rdi
callq 0x2358
leaq 0xfa30(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
leaq 0x8868(%rip), %rsi      # 0xf34f
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21a0
leaq 0x8855(%rip), %rsi      # 0xf356
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21a0
leaq 0x883d(%rip), %rsi      # 0xf358
movq %rax, %rdi
callq 0x21b0
movq 0x20(%r15), %r14
testq %r14, %r14
je 0x6e78
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2250
movq %r14, %rdi
movq %r12, %rsi
callq 0x67e0
leaq 0x68(%rsp), %rdi
callq 0x2358
jmp 0x6e78
leaq 0x8721(%rip), %rsi      # 0xf282
movq %r15, %rdi
callq 0x368e
testb %al, %al
je 0x6c11
leaq 0xf990(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x21a0
leaq 0x87c9(%rip), %rsi      # 0xf35b
movq %rax, %rdi
callq 0x21b0
movq (%r14), %r14
leaq 0x87a8(%rip), %rdx      # 0xf34c
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x70e5
movq %r14, %rdi
movq %r12, %rsi
callq 0x67e0
leaq 0x28(%rsp), %rdi
callq 0x2358
leaq 0xf938(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
leaq 0x8779(%rip), %rsi      # 0xf358
movq %rax, %rdi
callq 0x21b0
jmp 0x6e78
leaq 0x8765(%rip), %rsi      # 0xf358
movq %rax, %rdi
callq 0x21b0
movq (%rsp), %r14
movq 0x8(%r14), %r15
testq %r15, %r15
jne 0x6e45
jmp 0x6e42
leaq 0x8610(%rip), %rsi      # 0xf228
movq %r15, %rdi
callq 0x368e
testb %al, %al
je 0x6c64
leaq 0xf8dd(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x21a0
leaq 0x86b2(%rip), %rsi      # 0xf2f7
movq %rax, %rdi
callq 0x21b0
movq %r14, %rbp
leaq 0xc0(%r14), %rsi
movq %rax, %rdi
callq 0x21a0
jmp 0x6cfb
leaq 0x85fa(%rip), %rsi      # 0xf265
movq %r15, %rdi
callq 0x368e
testb %al, %al
je 0x6cb4
leaq 0xf88a(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x21a0
leaq 0x865f(%rip), %rsi      # 0xf2f7
movq %rax, %rdi
callq 0x21b0
movq %r14, %rbp
movl 0xb8(%r14), %esi
movq %rax, %rdi
callq 0x22f0
jmp 0x6cfb
leaq 0x85ba(%rip), %rsi      # 0xf275
movq %r15, %rdi
callq 0x7005
movl %eax, %ebp
leaq 0xf83c(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
movq %rax, %rdi
movq %r15, %rsi
callq 0x21a0
testb %bpl, %bpl
je 0x6cf8
movq %r14, %rbp
leaq 0x866d(%rip), %rsi      # 0xf35b
movq %rax, %rdi
callq 0x21b0
jmp 0x6d03
movq %r14, %rbp
movq %rax, %rdi
callq 0x20f0
xorl %r13d, %r13d
leaq 0xa8(%rsp), %r12
cmpq $0x4, %r13
je 0x6d9e
cmpq $0x0, (%rbp,%r13,8)
je 0x6d9e
addl $0x2, 0xf9e5(%rip)      # 0x1670c
cmpq $0x2, %r13
jne 0x6d65
movq %r15, %rdi
leaq 0x8506(%rip), %rsi      # 0xf23d
callq 0x368e
testb %al, %al
je 0x6d65
cmpq $0x0, 0x10(%rbp)
je 0x6d65
leaq 0xf7ba(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x8600(%rip), %rsi      # 0xf360
callq 0x21b0
movq (%rbp,%r13,8), %r14
movq %r12, %rdi
movq %rbx, %rsi
leaq 0x85d5(%rip), %rdx      # 0xf34c
callq 0x70e5
movq %r14, %rdi
movq %r12, %rsi
callq 0x67e0
movq %r12, %rdi
callq 0x2358
addl $-0x2, 0xf976(%rip)     # 0x1670c
incq %r13
jmp 0x6d0e
leaq 0x8483(%rip), %rsi      # 0xf228
movq %r15, %rdi
callq 0x7005
testb %al, %al
je 0x6df5
leaq 0x84bd(%rip), %rsi      # 0xf275
movq %r15, %rdi
callq 0x7005
testb %al, %al
je 0x6df5
leaq 0x849a(%rip), %rsi      # 0xf265
movq %r15, %rdi
callq 0x7005
testb %al, %al
je 0x6df5
leaq 0xf72a(%rip), %rdi      # 0x16508
movq %rbx, %rsi
callq 0x21a0
leaq 0x856b(%rip), %rsi      # 0xf358
movq %rax, %rdi
callq 0x21b0
cmpq $0x0, 0x20(%rbp)
je 0x6e78
leaq 0x84a7(%rip), %rsi      # 0xf2aa
movq %r15, %rdi
callq 0x7005
testb %al, %al
je 0x6e78
movq 0x20(%rbp), %r14
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2250
movq %r14, %rdi
movq %r12, %rsi
callq 0x67e0
leaq 0x8(%rsp), %rdi
jmp 0x6b50
jmp 0x6e8a
jmp 0x6e8a
jmp 0x6e8a
jmp 0x6e8a
jmp 0x6e8a
movq (%r14), %r15
testq %r15, %r15
je 0x6e78
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2250
movq %r15, %rdi
movq %r12, %rsi
callq 0x67e0
leaq 0x48(%rsp), %rdi
callq 0x2358
addq $0x20, %r15
movq %r15, %r14
jmp 0x6e42
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r12, %rdi
callq 0x2358
movq %rbx, %rdi
callq 0x2300