// File: /workspace/github_c_makefile_star2_O2/yutopp[P]cc/node.c
// Function: fprint_impl
void fprint_impl(FILE *fp, Node* node, int indent) {
    switch(node->kind) {
    case NODE_TRANS_UNIT:
    {
        Vector* decls = node->value.trans_unit.decls;
        for(size_t i=0; i<vector_len(decls); ++i) {
            Node** n = (Node**)vector_at(decls, i);
            fprint_impl(fp, *n, indent);
        }
        break;
    }

    case NODE_FUNC_DEF:
        fprint_indent(fp, indent); fprint_impl(fp, node->value.func_def.decl_spec, 0);
        fprintf(fp, " ");
        fprint_indent(fp, indent); fprint_impl(fp, node->value.func_def.decl, 0);
        fprint_indent(fp, indent); fprintf(fp, "\n");
        fprint_impl(fp, node->value.func_def.block, indent);
        break;

    case NODE_STMT_COMPOUND:
    {
        fprint_indent(fp, indent); fprintf(fp, "{\n");
        Vector* stmts = node->value.stmt_compound.stmts;
        for(size_t i=0; i<vector_len(stmts); ++i) {
            Node** n = (Node**)vector_at(stmts, i);
            fprint_impl(fp, *n, indent + 1);
        }
        fprint_indent(fp, indent); fprintf(fp, "}\n");
        break;
    }

    case NODE_STMT_EXPR:
        if (node->value.stmt_expr.expr) {
            fprint_indent(fp, indent); fprint_impl(fp, node->value.stmt_expr.expr, 0);
        }
        fprintf(fp, " ;\n");
        break;

    case NODE_STMT_IF:
        fprint_indent(fp, indent); fprintf(fp, "if ( ");
        fprint_impl(fp, node->value.stmt_if.cond, 0);
        fprintf(fp, " )\n");

        fprint_impl(fp, node->value.stmt_if.then_b, indent);

        if (node->value.stmt_if.else_b) {
            fprint_impl(fp, node->value.stmt_if.else_b, indent);
        }
        break;

    case NODE_STMT_JUMP:
        switch(node->value.stmt_jump.kind) {
        case TOK_KIND_RETURN:
            fprint_indent(fp, indent); fprintf(fp, "return ");
            fprint_impl(fp, node->value.stmt_jump.expr, 0);
            fprintf(fp, " ;\n");
            break;

        default:
            assert(0); // TODO: error handling...
            break;
        }
        break;

    case NODE_EXPR_BIN:
        fprint_impl(fp, node->value.expr_bin.lhs, indent);
        token_fprint_buf(fp, node->value.expr_bin.op);
        fprint_impl(fp, node->value.expr_bin.rhs, indent);
        break;

    case NODE_EXPR_POSTFIX:
        switch(node->value.expr_postfix.kind) {
        case NODE_EXPR_POSTFIX_KIND_FUNC_CALL:
            fprint_impl(fp, node->value.expr_postfix.lhs, indent);
            fprintf(fp, "(");
            if (node->value.expr_postfix.rhs) {
                fprint_impl(fp, node->value.expr_postfix.rhs, indent);
            }
            fprintf(fp, ")");
            break;

        default:
            assert(0); // TODO: error handling...
        }
        break;

    case NODE_LIT_INT:
        fprintf(fp, "%d", node->value.lit_int.v);
        break;

    case NODE_LIT_STRING:
        fprintf(fp, "\"%s\"", node->value.lit_string.v);
        break;

    case NODE_ID:
        token_fprint_buf(fp, node->value.id.tok);
        break;

    case NODE_ARGS_LIST:
    {
        Vector* args = node->value.args_list.args;
        for(size_t i=0; i<vector_len(args); ++i) {
            if (i != 0) {
                fprintf(fp, ", ");
            }
            Node** n = (Node**)vector_at(args, i);
            fprint_impl(fp, *n, 0);
        }
        break;
    }

    case NODE_DECLARATOR:
        fprint_impl(fp, node->value.declarator.node, 0);
        break;

    case NODE_DIRECT_DECLARATOR:
        fprint_impl(fp, node->value.direct_declarator.base, 0);
        switch(node->value.direct_declarator.kind) {
        case NODE_DIRECT_DECLARATOR_KIND_BASE:
            break; // DO NOTHING

        case NODE_DIRECT_DECLARATOR_KIND_PARAM_TYPE_LIST:
            fprintf(fp, "(");
            fprint_impl(fp, node->value.direct_declarator.args[0], 0);
            fprintf(fp, ")");
            break;

        default:
            assert(0); // TODO: error handling...
        }
        break;

    case NODE_PARAM_DECL:
        fprint_impl(fp, node->value.param_decl.spec, 0);
        if (node->value.param_decl.decl) {
            fprintf(fp, " ");
            fprint_impl(fp, node->value.param_decl.decl, 0);
        }
        break;

    case NODE_PARAM_LIST:
    {
        Vector* params = node->value.param_list.params;
        for(size_t i=0; i<vector_len(params); ++i) {
            if (i != 0) {
                fprintf(fp, ", ");
            }
            Node** n = (Node**)vector_at(params, i);
            fprint_impl(fp, *n, 0);
        }
        break;
    }

    default:
        fprintf(stderr, "Unknown kind: %d\n", node->kind);
        assert(0); // TODO: error handling...
        break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x39ac(%rip), %r12      # 0x63e0
pushq $0x1
popq %r13
pushq $0x3
popq %rbp
movl (%r15), %edx
cmpq $0xf, %rdx
ja 0x2e4c
movslq (%r12,%rdx,4), %rax
addq %r12, %rax
jmpq *%rax
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2f0b
movq 0x8(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2a19
pushq $0x20
popq %rdi
movq %rbx, %rsi
callq 0x10f0
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2f0b
movq 0x10(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2a19
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2f0b
pushq $0xa
popq %rdi
movq %rbx, %rsi
callq 0x10f0
jmp 0x2ac1
movq 0x10(%r15), %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x2a19
movq 0x8(%r15), %rsi
movq %rbx, %rdi
callq 0x18e4
movq 0x18(%r15), %r15
jmp 0x2a3b
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2f0b
leaq 0x394e(%rip), %rdi      # 0x642a
pushq $0x5
popq %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x11c0
movq 0x8(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2a19
leaq 0x3931(%rip), %rdi      # 0x6430
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x11c0
movq 0x10(%r15), %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x2a19
movq 0x18(%r15), %r15
testq %r15, %r15
jne 0x2a3b
jmp 0x2e3d
addq $0x8, %r15
jmp 0x2b5c
movq 0x8(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2a19
cmpq $0x0, 0x10(%r15)
je 0x2e3d
addq $0x10, %r15
pushq $0x20
popq %rdi
movq %rbx, %rsi
callq 0x10f0
movq (%r15), %r15
xorl %r14d, %r14d
jmp 0x2a3b
movq 0x8(%r15), %r14
xorl %r15d, %r15d
leaq 0x3a34(%rip), %r12      # 0x65a9
pushq $0x2
popq %r13
pushq $0x1
popq %rbp
movq %r14, %rdi
callq 0x29db
cmpq %rax, %r15
jae 0x2e3d
testq %r15, %r15
je 0x2ba3
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x11c0
movq %r14, %rdi
movq %r15, %rsi
callq 0x29c6
movq (%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2a19
incq %r15
jmp 0x2b7c
movq 0x8(%r15), %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x18e4
movq 0x8(%r15), %rdx
leaq 0x3884(%rip), %rsi      # 0x6469
movq %rbx, %rdi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1120
cmpq $0x0, 0x8(%r15)
je 0x2c1d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2f0b
movq 0x8(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2a19
leaq 0x3802(%rip), %rdi      # 0x6426
pushq $0x3
jmp 0x2d07
cmpl $0x0, 0x8(%r15)
jne 0x2e83
movq 0x10(%r15), %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x2a19
pushq $0x28
popq %rdi
movq %rbx, %rsi
callq 0x10f0
movq 0x18(%r15), %rsi
testq %rsi, %rsi
je 0x2e24
movq %rbx, %rdi
movl %r14d, %edx
jmp 0x2e1f
movq 0x8(%r15), %r15
xorl %r12d, %r12d
movq %r15, %rdi
callq 0x29db
cmpq %rax, %r12
jae 0x2e3d
movq %r15, %rdi
movq %r12, %rsi
callq 0x29c6
movq (%rax), %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x2a19
incq %r12
jmp 0x2c6f
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2f0b
leaq 0x3770(%rip), %rdi      # 0x6420
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11c0
movq 0x8(%r15), %r15
leal 0x1(%r14), %ebp
xorl %r12d, %r12d
movq %r15, %rdi
callq 0x29db
cmpq %rax, %r12
jae 0x2cf3
movq %r15, %rdi
movq %r12, %rsi
callq 0x29c6
movq (%rax), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x2a19
incq %r12
jmp 0x2cc9
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2f0b
leaq 0x371e(%rip), %rdi      # 0x6423
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
jmp 0x2db3
movq 0x8(%r15), %r14
xorl %r15d, %r15d
leaq 0x388b(%rip), %r12      # 0x65a9
pushq $0x2
popq %r13
pushq $0x1
popq %rbp
movq %r14, %rdi
callq 0x29db
cmpq %rax, %r15
jae 0x2e3d
testq %r15, %r15
je 0x2d4c
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x11c0
movq %r14, %rdi
movq %r15, %rsi
callq 0x29c6
movq (%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2a19
incq %r15
jmp 0x2d25
cmpl $0x19, 0x8(%r15)
jne 0x2ea2
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2f0b
leaq 0x36ae(%rip), %rdi      # 0x6434
pushq $0x7
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
movq 0x10(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2a19
leaq 0x3679(%rip), %rdi      # 0x6426
pushq $0x3
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11c0
movl 0x8(%r15), %edx
leaq 0x3b81(%rip), %rsi      # 0x6955
movq %rbx, %rdi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1120
movq 0x10(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2a19
movl 0x8(%r15), %eax
testl %eax, %eax
je 0x2e3d
cmpl $0x1, %eax
jne 0x2ebf
pushq $0x28
popq %rdi
movq %rbx, %rsi
callq 0x10f0
movq 0x18(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2a19
pushq $0x29
popq %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10f0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x81a5(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x3611(%rip), %rsi      # 0x646e
xorl %eax, %eax
callq 0x1120
leaq 0x39d3(%rip), %rdi      # 0x683e
leaq 0x35ca(%rip), %rsi      # 0x643c
leaq 0x35ca(%rip), %rcx      # 0x6443
movl $0xd1, %edx
callq 0x10d0
leaq 0x39b4(%rip), %rdi      # 0x683e
leaq 0x35ab(%rip), %rsi      # 0x643c
leaq 0x35ab(%rip), %rcx      # 0x6443
movl $0x88, %edx
callq 0x10d0
leaq 0x3995(%rip), %rdi      # 0x683e
leaq 0x358c(%rip), %rsi      # 0x643c
leaq 0x358c(%rip), %rcx      # 0x6443
pushq $0x71
popq %rdx
callq 0x10d0
leaq 0x3978(%rip), %rdi      # 0x683e
leaq 0x356f(%rip), %rsi      # 0x643c
leaq 0x356f(%rip), %rcx      # 0x6443
movl $0xb6, %edx
callq 0x10d0