// File: /workspace/github_c_makefile_star2_O3/pocari[P]compilerbook-9cc/debug.c
// Function: type_info_helper
int type_info_helper(char *buf, int offset, Type *type) {
  int n = 0;

  #pragma clang diagnostic ignored "-Wswitch"
  switch (type->kind) {
    case TY_VOID:
      n += sprintf(buf + offset, "void");
      break;
    case TY_INT:
      n += sprintf(buf + offset, "int");
      break;
    case TY_CHAR:
      n += sprintf(buf + offset, "char");
      break;
    case TY_SHORT:
      n += sprintf(buf + offset, "short");
      break;
    case TY_LONG:
      n += sprintf(buf + offset, "long");
      break;
    case TY_PTR:
      n += sprintf(buf + offset, "*");
      n += type_info_helper(buf, offset + n, type->ptr_to);
      break;
    case TY_ARRAY:
      // int x[2][3]と宣言された配列の場合
      //
      // TY_ARRAY
      // array_size: 2
      // ptr_to ---------> TY_ARRAY
      //                   array_size: 3
      //                   ptr_to   --------> TY_INT
      //
      // と、「「intのサイズ3の配列」のサイズ2の配列」という構造になるので、
      n += sprintf(buf + offset, "[%ld]", type->array_size);
      n += type_info_helper(buf, offset + n, type->ptr_to);
      break;
    case TY_STRUCT:
      n += sprintf(buf + offset, "struct (size %d) {", type->size);
      for (Member *m = type->members; m; m = m->next) {
        n += type_info_helper(buf, offset + n, m->ty);
        n += sprintf(buf + offset + n, " %s (offset %d)", m->name, m->offset);
        if (m->next) {
          n += sprintf(buf + offset + n, " ");
        }
      }
      n += sprintf(buf + offset + n, "}");
      break;
  }
  return n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r12
movl %esi, %r14d
movq %rdi, %rbx
movabsq $0x100000000, %r13      # imm = 0x100000000
leaq 0x8425(%rip), %rdx      # 0xbf98
leaq 0x8785(%rip), %rsi      # 0xc2ff
xorl %ebp, %ebp
movslq %r14d, %r15
leaq (%rbx,%r15), %rax
shlq $0x20, %r15
jmp 0x3b9e
movw $0x2a, (%rax)
movq 0x10(%r12), %r12
addq %r13, %r15
incl %r14d
incq %rax
incl %ebp
movl (%r12), %ecx
cmpl $0x7, %ecx
je 0x3b89
decl %ecx
cmpl $0x8, %ecx
ja 0x3cea
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
sarq $0x20, %r15
addq %rbx, %r15
movq 0x18(%r12), %rdx
movq %r15, %rdi
movq %rsi, %r15
xorl %eax, %eax
callq 0x21c0
movq %r15, %rsi
leaq 0x83ba(%rip), %rdx      # 0xbf98
addl %eax, %r14d
movq 0x10(%r12), %r12
addl %eax, %ebp
jmp 0x3b7c
sarq $0x20, %r15
movl $0x746e69, (%rbx,%r15)  # imm = 0x746E69
movl $0x3, %eax
jmp 0x3cec
sarq $0x20, %r15
movb $0x0, 0x4(%rbx,%r15)
movl $0x64696f76, (%rbx,%r15) # imm = 0x64696F76
jmp 0x3ce3
sarq $0x20, %r15
movw $0x74, 0x4(%rbx,%r15)
movl $0x726f6873, (%rbx,%r15) # imm = 0x726F6873
movl $0x5, %eax
jmp 0x3cec
sarq $0x20, %r15
addq %rbx, %r15
movl 0x4(%r12), %edx
leaq 0x86bd(%rip), %rsi      # 0xc305
movq %r15, %rdi
xorl %eax, %eax
callq 0x21c0
movl %eax, %r13d
movq 0x20(%r12), %r12
testq %r12, %r12
je 0x3caf
leal (%r14,%r13), %esi
movq 0x8(%r12), %rdx
movq %rbx, %rdi
callq 0x3b4e
addl %r13d, %eax
movslq %eax, %r13
leaq (%r15,%r13), %rdi
movq 0x10(%r12), %rdx
movl 0x18(%r12), %ecx
leaq 0x868d(%rip), %rsi      # 0xc318
xorl %eax, %eax
callq 0x21c0
addl %eax, %r13d
cmpq $0x0, (%r12)
je 0x3caf
movslq %r13d, %r13
movw $0x20, (%r15,%r13)
incl %r13d
movq (%r12), %r12
jmp 0x3c5a
movslq %r13d, %rax
movw $0x7d, (%r15,%rax)
incl %eax
jmp 0x3cec
sarq $0x20, %r15
movb $0x0, 0x4(%rbx,%r15)
movl $0x676e6f6c, (%rbx,%r15) # imm = 0x676E6F6C
jmp 0x3ce3
sarq $0x20, %r15
movb $0x0, 0x4(%rbx,%r15)
movl $0x72616863, (%rbx,%r15) # imm = 0x72616863
movl $0x4, %eax
jmp 0x3cec
xorl %eax, %eax
addl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq