// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2a40
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x2a40
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2a40
movq %rax, %rdi
callq 0x27f0
movq %rax, -0x20(%rbp)
leaq 0x14716(%rip), %rax     # 0x19dd8
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0xf5b0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
je 0x5703
leaq 0xc922(%rip), %rdi      # 0x12004
leaq 0xcf04(%rip), %rsi      # 0x125ed
movl $0x282, %edx            # imm = 0x282
leaq 0xcf02(%rip), %rcx      # 0x125f7
leaq 0xcf10(%rip), %r8       # 0x1260c
movb $0x0, %al
callq 0x6510
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x2a40
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2a40
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2ad0
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x10500
movq 0x8(%rax), %rcx
leaq 0x14691(%rip), %rax     # 0x19de8
movq %rcx, (%rax)
callq 0x3cc0
movq -0x20(%rbp), %rdi
callq 0xf2f0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq 0x13b19(%rip), %rsi     # 0x19290
callq 0xf2a0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x57b6
movq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq 0xdb1b(%rip), %rdi      # 0x132b4
callq 0xf2f0
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0xf2a0
movq %rax, -0x58(%rbp)
jmp 0x58d5
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x58d3
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpl $0x4000, (%rax)         # imm = 0x4000
jne 0x583d
movq -0x68(%rbp), %rdi
callq 0xfc50
movq %rax, -0x78(%rbp)
leaq 0x145dc(%rip), %rax     # 0x19dd8
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x68(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2a40
movq %rax, %rdi
callq 0x27f0
movq -0x98(%rbp), %rdi
movq %rax, %rsi
movq -0x78(%rbp), %rdx
callq 0xf550
movq -0x78(%rbp), %rdi
callq 0x4360
movq %rax, -0x70(%rbp)
jmp 0x5874
leaq 0xcdd6(%rip), %rax      # 0x1261a
movq %rax, -0x80(%rbp)
movq -0x68(%rbp), %rdi
callq 0x10600
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
callq 0xf2f0
movq %rax, %rdi
movq -0x88(%rbp), %rsi
callq 0x3ee0
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0xf2a0
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x58c0
movq -0x58(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq 0xcd74(%rip), %rdi      # 0x1261c
callq 0xf2f0
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0xf2a0
movq %rax, -0x58(%rbp)
jmp 0x58c2
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x57be
jmp 0x58d5
movq -0x58(%rbp), %rdi
leaq 0x139d0(%rip), %rsi     # 0x192b0
callq 0xf2a0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x10500
movq -0xb0(%rbp), %rdi
movq 0x8(%rax), %rsi
callq 0x3ee0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq 0x13d50(%rip), %rsi     # 0x19670
callq 0xf2a0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5190
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
callq 0xf2a0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq 0x13d35(%rip), %rsi     # 0x19690
callq 0xf2a0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rsi
leaq 0x13d21(%rip), %rdi     # 0x19690
callq 0xf2a0
movq %rax, -0x58(%rbp)
callq 0x3cf0
movq -0x58(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)