// File: /workspace/github_c_makefile_star2_O2/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, %r14
movl %esi, %r15d
movq %rdi, %rbx
leaq 0x6523(%rip), %r13      # 0x9f98
movabsq $0x100000000, %rdx      # imm = 0x100000000
leaq 0x6879(%rip), %rsi      # 0xa2ff
xorl %ebp, %ebp
movslq %r15d, %r12
leaq (%rbx,%r12), %rax
shlq $0x20, %r12
movl (%r14), %ecx
decl %ecx
cmpl $0x8, %ecx
ja 0x3be8
movslq (%r13,%rcx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
movw $0x2a, (%rax)
movq 0x10(%r14), %r14
addq %rdx, %r12
incl %r15d
incq %rax
incl %ebp
jmp 0x3a93
sarq $0x20, %r12
addq %rbx, %r12
movq 0x18(%r14), %rdx
movq %r12, %rdi
movq %rsi, %r12
xorl %eax, %eax
callq 0x21b0
movq %r12, %rsi
movabsq $0x100000000, %rdx      # imm = 0x100000000
addl %eax, %r15d
movq 0x10(%r14), %r14
addl %eax, %ebp
jmp 0x3a88
sarq $0x20, %r12
addq %rbx, %r12
movl 0x4(%r14), %edx
leaq 0x6802(%rip), %rsi      # 0xa305
movq %r12, %rdi
xorl %eax, %eax
callq 0x21b0
movl %eax, %r13d
addq $0x20, %r14
movq (%r14), %r14
testq %r14, %r14
je 0x3b64
leal (%r15,%r13), %esi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0x3a5a
addl %r13d, %eax
movslq %eax, %r13
leaq (%r12,%r13), %rdi
movq 0x10(%r14), %rdx
movl 0x18(%r14), %ecx
leaq 0x67d3(%rip), %rsi      # 0xa318
xorl %eax, %eax
callq 0x21b0
addl %eax, %r13d
cmpq $0x0, (%r14)
je 0x3b14
movslq %r13d, %r13
movw $0x20, (%r12,%r13)
incl %r13d
jmp 0x3b14
movslq %r13d, %rax
movw $0x7d, (%r12,%rax)
incl %eax
jmp 0x3bd7
sarq $0x20, %r12
movb $0x0, 0x4(%rbx,%r12)
movl $0x676e6f6c, (%rbx,%r12) # imm = 0x676E6F6C
jmp 0x3bac
sarq $0x20, %r12
movb $0x0, 0x4(%rbx,%r12)
movl $0x64696f76, (%rbx,%r12) # imm = 0x64696F76
jmp 0x3bac
sarq $0x20, %r12
movb $0x0, 0x4(%rbx,%r12)
movl $0x72616863, (%rbx,%r12) # imm = 0x72616863
pushq $0x4
jmp 0x3bd6
sarq $0x20, %r12
movl $0x746e69, (%rbx,%r12)  # imm = 0x746E69
pushq $0x3
jmp 0x3bd6
sarq $0x20, %r12
movw $0x74, 0x4(%rbx,%r12)
movl $0x726f6873, (%rbx,%r12) # imm = 0x726F6873
pushq $0x5
popq %rax
addl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x3bd7