// File: /workspace/github_c_makefile_star2_O1/ryvnf[P]czc/codegen.c
// Function: func_def_to_c
struct rope *func_def_to_c(struct ast *ast)
{
    struct ast *decl_ast = ast_ast(ast, 0);

    struct ast *block_ast = ast_ast(ast, 1);
    const char *name = ast_s(ast_ast(decl_ast, 0));

    struct sym *sym = scope_get_sym(current_scope, name);
    assert(sym->tag == DECL_SYM);
    struct decl_sym *decl = (struct decl_sym *)sym;
    struct ast *func_type_ast = ast_ast(decl_ast, 1);
    struct ast *param_list_ast = ast_ast(func_type_ast, 0);

    size_t n_param_asts;
    struct ast **param_asts = ast_asts(param_list_ast, &n_param_asts);

    zc_func_ret_type = func_type(decl->type)->ret;

    push_scope();

    struct rope *rope = rope_new_s(name);
    rope = rope_new_tree(rope, lparen_rope);
    if (n_param_asts == 0) {
        rope = rope_new_tree(rope, rope_new_s("void"));
    } else {
        for (size_t i = 0; i < n_param_asts; ++i) {
            struct ast *param_ast = param_asts[i];
            struct rope *c_param;

            if (param_ast->tag == DECL) {
                struct sym *decl = sym_from_ast(param_ast);
                scope_add_sym(current_scope, ast_s(ast_ast(param_ast, 0)), decl);
                c_param = decl_to_c((struct decl_sym *)decl);
            } else {
                const char *tmpname = "_";
                struct type *type = type_from_ast(param_ast);
                c_param = type_to_c(rope_new_s(tmpname), type);
            }

            rope = rope_new_tree(rope, c_param);

            if (i != n_param_asts - 1)
                rope = rope_new_tree(rope, rope_new_s(", "));
        }
    }
    rope = rope_new_tree(rope, rparen_rope);
    rope = type_to_c(rope, func_type(decl->type)->ret);
    rope = rope_new_tree(rope, sp_rope);
    rope = rope_new_tree(rope, func_body_to_c(block_ast));
    rope = rope_new_tree(rope, nl_rope);
    rope = rope_new_tree(nl_rope, rope);

    pop_scope();

    return rope;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
xorl %esi, %esi
callq 0x27c8
movq %rax, %r15
movl $0x1, %esi
movq %rbx, %rdi
callq 0x27c8
movq %rax, %r14
movq %r15, %rdi
xorl %esi, %esi
callq 0x27c8
movq %rax, %rdi
callq 0x26d0
movq %rax, %r12
leaq 0xf951(%rip), %rbx      # 0x13de0
movq (%rbx), %rdi
movq %rax, %rsi
callq 0xb310
cmpl $0x1, (%rax)
jne 0x4698
movq %rax, %rbp
movl $0x1, %esi
movq %r15, %rdi
callq 0x27c8
movq %rax, %rdi
xorl %esi, %esi
callq 0x27c8
movq %rsp, %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x2805
movq %rax, %r15
movq 0x18(%rbp), %rdi
callq 0xbc0b
movq 0x8(%rax), %rax
leaq 0xf90e(%rip), %rcx      # 0x13df0
movq %rax, (%rcx)
movq (%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x10, %edx
callq 0xb2b4
movq %rax, (%rbx)
movq %r12, %rdi
callq 0xb15d
leaq 0xed97(%rip), %rsi      # 0x132a0
movq %rax, %rdi
callq 0xb136
movq %rax, %r12
cmpq $0x0, (%r13)
movq %r14, 0x10(%rsp)
movq %rbp, 0x8(%rsp)
je 0x45ee
cmpq $0x0, (%rsp)
je 0x4608
xorl %ebp, %ebp
movq (%r15,%rbp,8), %rbx
cmpl $0x4000, (%rbx)         # imm = 0x4000
jne 0x4589
movq %rbx, %rdi
callq 0xb6f9
movq %rax, %r14
leaq 0xf88c(%rip), %rax      # 0x13de0
movq (%rax), %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0x27c8
movq %rax, %rdi
callq 0x26d0
movq %r13, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0xb2ff
movq 0x10(%r14), %rdi
callq 0xb15d
movq 0x18(%r14), %rsi
movq %rax, %rdi
jmp 0x45a6
movq %rbx, %rdi
callq 0xbc78
movq %rax, %rbx
leaq 0x9299(%rip), %rdi      # 0xd834
callq 0xb15d
movq %rax, %rdi
movq %rbx, %rsi
callq 0x348a
movq %r12, %rdi
movq %rax, %rsi
callq 0xb136
movq %rax, %r12
movq (%rsp), %rax
decq %rax
cmpq %rax, %rbp
je 0x45df
leaq 0x926a(%rip), %rdi      # 0xd836
callq 0xb15d
movq %r12, %rdi
movq %rax, %rsi
callq 0xb136
movq %rax, %r12
incq %rbp
cmpq (%rsp), %rbp
jb 0x4536
jmp 0x4608
leaq 0x99ef(%rip), %rdi      # 0xdfe4
callq 0xb15d
movq %r12, %rdi
movq %rax, %rsi
callq 0xb136
movq %rax, %r12
leaq 0xecb1(%rip), %rsi      # 0x132c0
movq %r12, %rdi
callq 0xb136
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0xbc0b
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x348a
leaq 0xf045(%rip), %rsi      # 0x13680
movq %rax, %rdi
callq 0xb136
movq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0x4126
movq %rbx, %rdi
movq %rax, %rsi
callq 0xb136
leaq 0xf03e(%rip), %rbx      # 0x136a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0xb136
movq %rbx, %rdi
movq %rax, %rsi
callq 0xb136
leaq 0xf761(%rip), %rdx      # 0x13de0
movq (%rdx), %rcx
movq 0x10(%rcx), %rcx
movq %rcx, (%rdx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8b0d(%rip), %rdi      # 0xd1ac
leaq 0x9161(%rip), %rsi      # 0xd807
leaq 0x9164(%rip), %rcx      # 0xd811
leaq 0x9172(%rip), %r8       # 0xd826
movl $0x282, %edx            # imm = 0x282
xorl %eax, %eax
callq 0x4f1c