// File: /workspace/github_c_makefile_star2_O0/sisshiki1969[P]monocc/src/codegen.c
// Function: gen_fdecl
void gen_fdecl(Node *node) {
  if (!node->lhs) return;
  current_fn = node;

  fprintf(output, "%.*s:\n", node->token->len, node->token->str);
  // Prologue
  fprintf(output, "\tpush rbp\n");
  fprintf(output, "\tmov  rbp, rsp\n");
  int offset = ((node->offset - 1) & (-16)) + 16;
  fprintf(output, "\tsub  rsp, %d\n", offset);
  fprintf(output, "\tmov  [rbp -  8], r12\n");
  fprintf(output, "\tmov  [rbp - 16], r13\n");
  fprintf(output, "\tmov  [rbp - 24], r14\n");
  fprintf(output, "\tmov  [rbp - 32], r15\n");

  if (node->type->variadic) {
    fprintf(output, "\tmov  [rbp - 128], rdi\n");
    fprintf(output, "\tmov  [rbp - 120], rsi\n");
    fprintf(output, "\tmov  [rbp - 112], rdx\n");
    fprintf(output, "\tmov  [rbp - 104], rcx\n");
    fprintf(output, "\tmov  [rbp -  96], r8\n");
    fprintf(output, "\tmov  [rbp -  88], r9\n");
  }

  int len = vec_len(node->nodes);
  Node **params = node->nodes->data;
  for (int i = 0; i < len; i++) {
    fprintf(output, "\tmov  [rbp - %d], %s\n", params[i]->lvar->offset,
            registers[reg_size(type(params[i]))][i]);
  }

  gen_block(node->lhs);

  // Epilogue
  emit_return_label(node);
  fprintf(output, "\tmov  r12, [rbp -  8]\n");
  fprintf(output, "\tmov  r13, [rbp - 16]\n");
  fprintf(output, "\tmov  r14, [rbp - 24]\n");
  fprintf(output, "\tmov  r15, [rbp - 32]\n");
  fprintf(output, "\tmov  rsp, rbp\n");
  fprintf(output, "\tpop  rbp\n");
  fprintf(output, "\tret\n");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x2d0c
jmp 0x3008
movq -0x8(%rbp), %rax
movq %rax, 0x124d1(%rip)     # 0x151e8
leaq 0x124f2(%rip), %rax     # 0x15210
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movl 0x28(%rax), %edx
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x20(%rax), %rcx
leaq 0xc445(%rip), %rsi      # 0xf184
movb $0x0, %al
callq 0x10f0
leaq 0x124c3(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc875(%rip), %rsi      # 0xf5cc
movb $0x0, %al
callq 0x10f0
leaq 0x124ab(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc868(%rip), %rsi      # 0xf5d7
movb $0x0, %al
callq 0x10f0
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
subl $0x1, %eax
andl $-0x10, %eax
addl $0x10, %eax
movl %eax, -0xc(%rbp)
leaq 0x12480(%rip), %rax     # 0x15210
movq (%rax), %rdi
movl -0xc(%rbp), %edx
leaq 0xc84a(%rip), %rsi      # 0xf5e7
movb $0x0, %al
callq 0x10f0
leaq 0x12465(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc841(%rip), %rsi      # 0xf5f6
movb $0x0, %al
callq 0x10f0
leaq 0x1244d(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc840(%rip), %rsi      # 0xf60d
movb $0x0, %al
callq 0x10f0
leaq 0x12435(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc83f(%rip), %rsi      # 0xf624
movb $0x0, %al
callq 0x10f0
leaq 0x1241d(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc83e(%rip), %rsi      # 0xf63b
movb $0x0, %al
callq 0x10f0
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
testb $0x1, 0x38(%rax)
je 0x2ea6
leaq 0x123f3(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc82b(%rip), %rsi      # 0xf652
movb $0x0, %al
callq 0x10f0
leaq 0x123db(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc82b(%rip), %rsi      # 0xf66a
movb $0x0, %al
callq 0x10f0
leaq 0x123c3(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc82b(%rip), %rsi      # 0xf682
movb $0x0, %al
callq 0x10f0
leaq 0x123ab(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc82b(%rip), %rsi      # 0xf69a
movb $0x0, %al
callq 0x10f0
leaq 0x12393(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc82b(%rip), %rsi      # 0xf6b2
movb $0x0, %al
callq 0x10f0
leaq 0x1237b(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc82a(%rip), %rsi      # 0xf6c9
movb $0x0, %al
callq 0x10f0
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x4000
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x2f4a
leaq 0x12335(%rip), %rax     # 0x15210
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x30(%rax), %rax
movl 0x18(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xdda0
movq %rax, %rdi
callq 0x1680
movq -0x28(%rbp), %rdi
movl -0x20(%rbp), %edx
movslq %eax, %rcx
leaq 0x121ee(%rip), %rax     # 0x15110
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0xc7a8(%rip), %rsi      # 0xf6e0
movb $0x0, %al
callq 0x10f0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2ecc
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2990
movq -0x8(%rbp), %rdi
callq 0x13f0
leaq 0x122a9(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc785(%rip), %rsi      # 0xf6f6
movb $0x0, %al
callq 0x10f0
leaq 0x12291(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc784(%rip), %rsi      # 0xf70d
movb $0x0, %al
callq 0x10f0
leaq 0x12279(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc783(%rip), %rsi      # 0xf724
movb $0x0, %al
callq 0x10f0
leaq 0x12261(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc782(%rip), %rsi      # 0xf73b
movb $0x0, %al
callq 0x10f0
leaq 0x12249(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc781(%rip), %rsi      # 0xf752
movb $0x0, %al
callq 0x10f0
leaq 0x12231(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc779(%rip), %rsi      # 0xf762
movb $0x0, %al
callq 0x10f0
leaq 0x12219(%rip), %rax     # 0x15210
movq (%rax), %rdi
leaq 0xc76c(%rip), %rsi      # 0xf76d
movb $0x0, %al
callq 0x10f0
addq $0x30, %rsp
popq %rbp
retq
nop