// File: /workspace/github_c_makefile_star2_O3/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 0x27e8
movq %rax, %r15
movl $0x1, %esi
movq %rbx, %rdi
callq 0x27e8
movq %rax, %r14
movq %r15, %rdi
xorl %esi, %esi
callq 0x27e8
movq %rax, %rdi
callq 0x26f0
movq %rax, %r12
leaq 0xf9b7(%rip), %rbx      # 0x13de0
movq (%rbx), %rdi
movq %rax, %rsi
callq 0xb09c
cmpl $0x1, (%rax)
jne 0x462b
movq %rax, %rbp
movq %r14, 0x10(%rsp)
movl $0x1, %esi
movq %r15, %rdi
callq 0x27e8
movq %rax, %rdi
xorl %esi, %esi
callq 0x27e8
movq %rsp, %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x2825
movq %rax, %r15
movq %rbp, 0x8(%rsp)
movq 0x18(%rbp), %rdi
callq 0xb99b
movq 0x8(%rax), %rax
leaq 0xf96a(%rip), %rcx      # 0x13df0
movq %rax, (%rcx)
movq (%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
movl $0x10, %edx
callq 0xb040
movq %rax, (%rbx)
movq %r12, %rdi
callq 0xaee6
leaq 0xedf3(%rip), %rsi      # 0x132a0
movq %rax, %rdi
callq 0xaebf
movq %rax, %r12
cmpq $0x0, (%r13)
je 0x4581
xorl %ebp, %ebp
movq (%r15,%rbp,8), %rbx
cmpl $0x4000, (%rbx)         # imm = 0x4000
jne 0x4518
movq %rbx, %rdi
callq 0xb48c
movq %rax, %r14
leaq 0xf8fd(%rip), %rax      # 0x13de0
movq (%rax), %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0x27e8
movq %rax, %rdi
callq 0x26f0
movq %r13, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0xb08b
movq 0x10(%r14), %rdi
callq 0xaee6
movq 0x18(%r14), %rsi
movq %rax, %rdi
jmp 0x4535
movq %rbx, %rdi
callq 0xba08
movq %rax, %rbx
leaq 0x930a(%rip), %rdi      # 0xd834
callq 0xaee6
movq %rax, %rdi
movq %rbx, %rsi
callq 0x342a
movq %r12, %rdi
movq %rax, %rsi
callq 0xaebf
movq %rax, %r12
movq (%rsp), %rax
leaq -0x1(%rax), %rcx
cmpq %rcx, %rbp
je 0x4573
leaq 0x92da(%rip), %rdi      # 0xd836
callq 0xaee6
movq %r12, %rdi
movq %rax, %rsi
callq 0xaebf
movq %rax, %r12
movq (%rsp), %rax
incq %rbp
cmpq %rax, %rbp
jb 0x44c5
jmp 0x459b
leaq 0x9a5c(%rip), %rdi      # 0xdfe4
callq 0xaee6
movq %r12, %rdi
movq %rax, %rsi
callq 0xaebf
movq %rax, %r12
leaq 0xed1e(%rip), %rsi      # 0x132c0
movq %r12, %rdi
callq 0xaebf
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0xb99b
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x342a
leaq 0xf0b2(%rip), %rsi      # 0x13680
movq %rax, %rdi
callq 0xaebf
movq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0x40c8
movq %rbx, %rdi
movq %rax, %rsi
callq 0xaebf
leaq 0xf0ab(%rip), %rbx      # 0x136a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0xaebf
movq %rbx, %rdi
movq %rax, %rsi
callq 0xaebf
leaq 0xf7ce(%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 0x8b7a(%rip), %rdi      # 0xd1ac
leaq 0x91ce(%rip), %rsi      # 0xd807
leaq 0x91d1(%rip), %rcx      # 0xd811
leaq 0x91df(%rip), %r8       # 0xd826
movl $0x282, %edx            # imm = 0x282
xorl %eax, %eax
callq 0x4eac