// File: /workspace/github_c_makefile_star2_O1/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, %r15d
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x4145(%rip), %r12      # 0x73d0
leal (,%r15,4), %eax
cmpl $0x2, %eax
movl $0x1, %r13d
movl %eax, 0x4(%rsp)
cmovgel %eax, %r13d
movl (%r14), %edi
cmpq $0xf, %rdi
ja 0x37d8
movslq (%r12,%rdi,4), %rax
addq %r12, %rax
jmpq *%rax
testl %r15d, %r15d
jle 0x33b2
movl %r13d, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x32c6
movq 0x8(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
testl %r15d, %r15d
jle 0x33f6
movl %r13d, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x32fe
jmp 0x33cd
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x3270
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x1c61
movq 0x18(%r14), %r14
jmp 0x32a4
testl %r15d, %r15d
jle 0x3351
movl %r13d, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x3340
movl $0x5, %esi
movl $0x1, %edx
leaq 0x40b8(%rip), %rdi      # 0x741a
movq %rbx, %rcx
callq 0x11b0
movq 0x8(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
movl $0x3, %esi
movl $0x1, %edx
leaq 0x4097(%rip), %rdi      # 0x7420
movq %rbx, %rcx
callq 0x11b0
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x3270
movq 0x18(%r14), %r14
testq %r14, %r14
jne 0x32a4
jmp 0x37c9
movq 0x8(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
movq 0x10(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
testl %r15d, %r15d
jle 0x3404
movl %r13d, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x33e3
jmp 0x3404
movq 0x10(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
movl $0xa, %edi
movq %rbx, %rsi
callq 0x10f0
movq 0x18(%r14), %r14
jmp 0x32a4
movq 0x8(%r14), %r14
xorl %r15d, %r15d
jmp 0x328b
movq 0x8(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
cmpq $0x0, 0x10(%r14)
je 0x37c9
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
movq 0x10(%r14), %r14
xorl %r15d, %r15d
jmp 0x328b
movq 0x8(%r14), %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1c61
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x322b
testq %rax, %rax
je 0x37c9
xorl %r15d, %r15d
leaq 0x4108(%rip), %r12      # 0x7599
testq %r15, %r15
je 0x34ab
movl $0x2, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x11b0
movq %r14, %rdi
movq %r15, %rsi
callq 0x3216
movq (%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
incq %r15
movq %r14, %rdi
callq 0x322b
cmpq %rax, %r15
jb 0x3491
jmp 0x37c9
cmpq $0x0, 0x8(%r14)
je 0x372a
testl %r15d, %r15d
jle 0x3508
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
movl $0x1, %ebp
cmovgel %eax, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x34f7
movq 0x8(%r14), %rsi
jmp 0x3720
cmpl $0x0, 0x8(%r14)
jne 0x37dd
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x3270
movl $0x28, %edi
movq %rbx, %rsi
callq 0x10f0
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0x37ae
movq %rbx, %rdi
movl %r15d, %edx
jmp 0x37a9
movq 0x8(%r14), %rdx
leaq 0x3efe(%rip), %rsi      # 0x7459
movq %rbx, %rdi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x322b
testq %rax, %rax
je 0x37c9
xorl %r15d, %r15d
leaq 0x4007(%rip), %r12      # 0x7599
testq %r15, %r15
je 0x35ac
movl $0x2, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x11b0
movq %r14, %rdi
movq %r15, %rsi
callq 0x3216
movq (%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
incq %r15
movq %r14, %rdi
callq 0x322b
cmpq %rax, %r15
jb 0x3592
jmp 0x37c9
testl %r15d, %r15d
jle 0x35fe
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
movl $0x1, %ebp
cmovgel %eax, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x35ed
leaq 0x3e0b(%rip), %rdi      # 0x7410
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11b0
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x322b
testq %rax, %rax
je 0x3657
leal 0x1(%r15), %ebp
xorl %r12d, %r12d
movq %r14, %rdi
movq %r12, %rsi
callq 0x3216
movq (%rax), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x3270
incq %r12
movq %r14, %rdi
callq 0x322b
cmpq %rax, %r12
jb 0x362f
testl %r15d, %r15d
jle 0x367c
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
movl $0x1, %ebp
cmovgel %eax, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x366b
leaq 0x3d90(%rip), %rdi      # 0x7413
movl $0x2, %esi
jmp 0x3736
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x322b
testq %rax, %rax
je 0x37c9
xorl %r12d, %r12d
movq %r14, %rdi
movq %r12, %rsi
callq 0x3216
movq (%rax), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x3270
incq %r12
movq %r14, %rdi
callq 0x322b
cmpq %rax, %r12
jb 0x36a5
jmp 0x37c9
cmpl $0x19, 0x8(%r14)
jne 0x37fc
testl %r15d, %r15d
jle 0x3703
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
movl $0x1, %ebp
cmovgel %eax, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x36f2
leaq 0x3d1a(%rip), %rdi      # 0x7424
movl $0x7, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11b0
movq 0x10(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
leaq 0x3ce5(%rip), %rdi      # 0x7416
movl $0x3, %esi
movl $0x1, %edx
movq %rbx, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11b0
movl 0x8(%r14), %edx
leaq 0x41e9(%rip), %rsi      # 0x7945
movq %rbx, %rdi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1110
movq 0x10(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
movl 0x8(%r14), %eax
testl %eax, %eax
je 0x37c9
cmpl $0x1, %eax
jne 0x381b
movl $0x28, %edi
movq %rbx, %rsi
callq 0x10f0
movq 0x18(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3270
movl $0x29, %edi
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
callq 0x1257
leaq 0x404a(%rip), %rdi      # 0x782e
leaq 0x3c41(%rip), %rsi      # 0x742c
leaq 0x3c41(%rip), %rcx      # 0x7433
movl $0x88, %edx
callq 0x10d0
leaq 0x402b(%rip), %rdi      # 0x782e
leaq 0x3c22(%rip), %rsi      # 0x742c
leaq 0x3c22(%rip), %rcx      # 0x7433
movl $0x71, %edx
callq 0x10d0
leaq 0x400c(%rip), %rdi      # 0x782e
leaq 0x3c03(%rip), %rsi      # 0x742c
leaq 0x3c03(%rip), %rcx      # 0x7433
movl $0xb6, %edx
callq 0x10d0