// File: /workspace/github_c_makefile_star2_O2/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 0x26ce
movq %rax, %r15
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x26ce
movq %rax, %r14
movq %r15, %rdi
xorl %esi, %esi
callq 0x26ce
movq %rax, %rdi
callq 0x25da
movq %rax, %r12
leaq 0xeed2(%rip), %rax      # 0x12de0
movq (%rax), %rdi
movq %r12, %rsi
callq 0xa01a
cmpl $0x1, (%rax)
jne 0x4100
movq %rax, %rbp
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x26ce
movq %rax, %rdi
xorl %esi, %esi
callq 0x26ce
movq %rsp, %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x270b
movq %rax, %r15
movq 0x18(%rbp), %rdi
callq 0xa7dc
movq 0x8(%rax), %rax
leaq 0xee91(%rip), %rcx      # 0x12df0
movq %rax, (%rcx)
callq 0x300b
movq %r12, %rdi
callq 0x9e6c
leaq 0xe32a(%rip), %rsi      # 0x122a0
movq %rax, %rdi
callq 0x9e47
movq %rax, %r12
movq (%r13), %rax
testq %rax, %rax
je 0x405d
movq %rbp, 0x8(%rsp)
movq %r14, 0x10(%rsp)
xorl %ebp, %ebp
cmpq %rax, %rbp
jae 0x4051
movq (%r15,%rbp,8), %rbx
cmpl $0x4000, (%rbx)         # imm = 0x4000
jne 0x3fee
movq %rbx, %rdi
callq 0xa3af
movq %rax, %r14
leaq 0xee1f(%rip), %rax      # 0x12de0
movq (%rax), %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0x26ce
movq %rax, %rdi
callq 0x25da
movq %r13, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0xa009
movq %r14, %rdi
callq 0x338a
jmp 0x4010
movq %rbx, %rdi
callq 0xa849
movq %rax, %rbx
leaq 0x7834(%rip), %rdi      # 0xb834
callq 0x9e6c
movq %rax, %rdi
movq %rbx, %rsi
callq 0x30e4
movq %r12, %rdi
movq %rax, %rsi
callq 0x9e47
movq %rax, %r12
movq (%rsp), %rax
leaq -0x1(%rax), %rcx
cmpq %rcx, %rbp
je 0x4049
leaq 0x7804(%rip), %rdi      # 0xb836
callq 0x9e6c
movq %r12, %rdi
movq %rax, %rsi
callq 0x9e47
movq %rax, %r12
movq (%rsp), %rax
incq %rbp
jmp 0x3f9a
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rbp
jmp 0x4077
leaq 0x7f80(%rip), %rdi      # 0xbfe4
callq 0x9e6c
movq %r12, %rdi
movq %rax, %rsi
callq 0x9e47
movq %rax, %r12
leaq 0xe242(%rip), %rsi      # 0x122c0
movq %r12, %rdi
callq 0x9e47
movq %rax, %rbx
movq 0x18(%rbp), %rdi
callq 0xa7dc
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x30e4
leaq 0xe5db(%rip), %rsi      # 0x12680
movq %rax, %rdi
callq 0x9e47
movq %rax, %rbx
movq %r14, %rdi
callq 0x3c1a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x9e47
leaq 0xe5d6(%rip), %rbx      # 0x126a0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x9e47
movq %rbx, %rdi
movq %rax, %rsi
callq 0x9e47
leaq 0xecf9(%rip), %rdx      # 0x12de0
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 0x70a5(%rip), %rdi      # 0xb1ac
leaq 0x76f9(%rip), %rsi      # 0xb807
leaq 0x76fc(%rip), %rcx      # 0xb811
leaq 0x770a(%rip), %r8       # 0xb826
movl $0x282, %edx            # imm = 0x282
xorl %eax, %eax
callq 0x4918