// File: /workspace/github_cpp_makefile_star2_O3/tsoding[P]wcc/src/./wcc_wat_compiler.cpp
// Function: Wat_Compiler::compile_func_body(Block*)
S_Expr *Wat_Compiler::compile_func_body(Block *block)
{
    S_Expr *local_var_def_section = nullptr;
    S_Expr *local_var_def_init = nullptr;

    while (block && block->statement.kind == Statement_Kind::Local_Var_Def) {
        auto var_ident = wat_ident(block->statement.local_var_def.def.name);

        local_var_def_section = append(
            local_var_def_section,
            list(list(atom("local"_sv),
                      var_ident,
                      wat_name_of_type(block->statement.local_var_def.def.type))));

        local_var_def_init = append(
            local_var_def_init,
            list(list(atom("set_local"_sv),
                      var_ident,
                      compile_expression(block->statement.local_var_def.value))));

        block = block->next;
    }

    return append(local_var_def_section, local_var_def_init, compile_block(block));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
xorl %r14d, %r14d
testq %rsi, %rsi
je 0x6566
movq %rsi, %r12
movq $0x0, -0x30(%rbp)
xorl %r15d, %r15d
cmpl $0x0, (%r12)
jne 0x6573
movq 0x10(%r12), %rcx
movq 0x18(%r12), %r8
movl $0x1, %esi
movq %rbx, %rdi
leaq 0x374a(%rip), %rdx      # 0x9b44
callq 0x7b54
movq %rax, %r13
movq %rdx, %r14
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x8296
movq %r15, -0x40(%rbp)
movq %rax, %r15
movl $0x1, %eax
movl %eax, (%r15)
movq %r13, 0x8(%r15)
movq %r14, 0x10(%r15)
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x8296
movq %rax, %r14
movl $0x1, %eax
movl %eax, (%r14)
movq $0x5, 0x8(%r14)
leaq 0x384b(%rip), %rax      # 0x9c9b
movq %rax, 0x10(%r14)
movl 0x20(%r12), %esi
movq %rbx, %rdi
callq 0x4a64
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x7bbe
movq %rax, -0x38(%rbp)
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x8296
movq %rax, %r13
xorl %eax, %eax
movl %eax, (%r13)
movq %r14, 0x8(%r13)
movq -0x38(%rbp), %rax
movq %rax, 0x10(%r13)
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x8296
xorl %ecx, %ecx
movl %ecx, (%rax)
movq %r13, 0x8(%rax)
movq %rcx, 0x10(%rax)
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
movq %rax, %rdx
callq 0x7d14
movq %rax, -0x30(%rbp)
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x8296
movq %rax, %r14
movl $0x1, %eax
movl %eax, (%r14)
movq $0x9, 0x8(%r14)
leaq 0x44da(%rip), %rax      # 0xa9c2
movq %rax, 0x10(%r14)
movq 0x28(%r12), %rsi
movq %rbx, %rdi
callq 0x4f8e
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x7bbe
movq %rax, %r15
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x8296
movq %rax, %r13
xorl %eax, %eax
movl %eax, (%r13)
movq %r14, 0x8(%r13)
movq %r15, 0x10(%r13)
movq (%rbx), %rdi
movl $0x1, %esi
callq 0x8296
xorl %ecx, %ecx
movl %ecx, (%rax)
movq %r13, 0x8(%rax)
xorl %r14d, %r14d
movq %rcx, 0x10(%rax)
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
movq %rax, %rdx
callq 0x7d14
movq %rax, %r15
movq 0x30(%r12), %r12
testq %r12, %r12
jne 0x63d6
jmp 0x6581
xorl %r15d, %r15d
movq $0x0, -0x30(%rbp)
jmp 0x6581
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6318
movq %rax, %r14
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
movq %r15, %rdx
movq %r14, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7d70
nop