// File: /workspace/github_c_makefile_star2_O3/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 0x4475(%rip), %r12      # 0x73e0
leal (,%r15,4), %eax
cmpl $0x2, %eax
movl $0x1, %r13d
movl %eax, 0x4(%rsp)
cmovgel %eax, %r13d
movl (%r14), %edi
cmpq $0xf, %rdi
ja 0x34a7
movslq (%r12,%rdi,4), %rax
addq %r12, %rax
jmpq *%rax
testl %r15d, %r15d
jle 0x30a7
movl %r13d, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x2fa6
movq 0x8(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
movl %r13d, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x2fd5
movq 0x10(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
movl %r13d, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x2ff7
jmp 0x30d0
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x2f50
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x1c61
jmp 0x30dd
testl %r15d, %r15d
jle 0x3046
movl %r13d, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x3035
movl $0x5, %esi
movl $0x1, %edx
leaq 0x43d3(%rip), %rdi      # 0x742a
movq %rbx, %rcx
callq 0x11c0
movq 0x8(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
movl $0x3, %esi
movl $0x1, %edx
leaq 0x43b2(%rip), %rdi      # 0x7430
movq %rbx, %rcx
callq 0x11c0
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x2f50
movq 0x18(%r14), %r14
testq %r14, %r14
jne 0x2f84
jmp 0x3498
movq 0x8(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
movq 0x10(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
movl $0xa, %edi
movq %rbx, %rsi
callq 0x10f0
movq 0x18(%r14), %r14
jmp 0x2f84
addq $0x8, %r14
jmp 0x3116
movq 0x8(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
cmpq $0x0, 0x10(%r14)
je 0x3498
addq $0x10, %r14
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
movq (%r14), %r14
xorl %r15d, %r15d
jmp 0x2f6b
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 0x2f0b
testq %rax, %rax
je 0x3498
xorl %r15d, %r15d
leaq 0x444f(%rip), %r12      # 0x75a9
testq %r15, %r15
je 0x3174
movl $0x2, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x11c0
movq %r14, %rdi
movq %r15, %rsi
callq 0x2ef6
movq (%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
incq %r15
movq %r14, %rdi
callq 0x2f0b
cmpq %rax, %r15
jb 0x315a
jmp 0x3498
movq 0x8(%r14), %rsi
testq %rsi, %rsi
je 0x33f9
testl %r15d, %r15d
jle 0x33ef
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
movl $0x1, %ebp
cmovgel %eax, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x31c6
movq 0x8(%r14), %rsi
jmp 0x33ef
cmpl $0x0, 0x8(%r14)
jne 0x34ac
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x2f50
movl $0x28, %edi
movq %rbx, %rsi
callq 0x10f0
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0x347d
movq %rbx, %rdi
movl %r15d, %edx
jmp 0x3478
movq 0x8(%r14), %rdx
leaq 0x423f(%rip), %rsi      # 0x7469
movq %rbx, %rdi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1120
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x2f0b
testq %rax, %rax
je 0x3498
xorl %r15d, %r15d
leaq 0x4348(%rip), %r12      # 0x75a9
testq %r15, %r15
je 0x327b
movl $0x2, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x11c0
movq %r14, %rdi
movq %r15, %rsi
callq 0x2ef6
movq (%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
incq %r15
movq %r14, %rdi
callq 0x2f0b
cmpq %rax, %r15
jb 0x3261
jmp 0x3498
testl %r15d, %r15d
jle 0x32cd
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
movl $0x1, %ebp
cmovgel %eax, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x32bc
leaq 0x414c(%rip), %rdi      # 0x7420
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x2f0b
testq %rax, %rax
je 0x3326
leal 0x1(%r15), %ebp
xorl %r12d, %r12d
movq %r14, %rdi
movq %r12, %rsi
callq 0x2ef6
movq (%rax), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x2f50
incq %r12
movq %r14, %rdi
callq 0x2f0b
cmpq %rax, %r12
jb 0x32fe
testl %r15d, %r15d
jle 0x334b
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
movl $0x1, %ebp
cmovgel %eax, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x333a
leaq 0x40d1(%rip), %rdi      # 0x7423
movl $0x2, %esi
jmp 0x3405
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x2f0b
testq %rax, %rax
je 0x3498
xorl %r12d, %r12d
movq %r14, %rdi
movq %r12, %rsi
callq 0x2ef6
movq (%rax), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x2f50
incq %r12
movq %r14, %rdi
callq 0x2f0b
cmpq %rax, %r12
jb 0x3374
jmp 0x3498
cmpl $0x19, 0x8(%r14)
jne 0x34cb
testl %r15d, %r15d
jle 0x33d2
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
movl $0x1, %ebp
cmovgel %eax, %ebp
movl $0x20, %edi
movq %rbx, %rsi
callq 0x10f0
decl %ebp
jne 0x33c1
leaq 0x405b(%rip), %rdi      # 0x7434
movl $0x7, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movq 0x10(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
leaq 0x4026(%rip), %rdi      # 0x7426
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 0x11c0
movl 0x8(%r14), %edx
leaq 0x452a(%rip), %rsi      # 0x7955
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(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
movl 0x8(%r14), %eax
testl %eax, %eax
je 0x3498
cmpl $0x1, %eax
jne 0x34ea
movl $0x28, %edi
movq %rbx, %rsi
callq 0x10f0
movq 0x18(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2f50
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 0x1267
leaq 0x438b(%rip), %rdi      # 0x783e
leaq 0x3f82(%rip), %rsi      # 0x743c
leaq 0x3f82(%rip), %rcx      # 0x7443
movl $0x88, %edx
callq 0x10d0
leaq 0x436c(%rip), %rdi      # 0x783e
leaq 0x3f63(%rip), %rsi      # 0x743c
leaq 0x3f63(%rip), %rcx      # 0x7443
movl $0x71, %edx
callq 0x10d0
leaq 0x434d(%rip), %rdi      # 0x783e
leaq 0x3f44(%rip), %rsi      # 0x743c
leaq 0x3f44(%rip), %rcx      # 0x7443
movl $0xb6, %edx
callq 0x10d0