// File: /workspace/github_c_makefile_star2_O1/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, %ebp
movq %rdi, %rax
movslq %esi, %rdi
movq %rax, (%rsp)
leaq (%rax,%rdi), %r13
xorl %ebx, %ebx
movl (%r12), %eax
cmpl $0x7, %eax
jne 0x3b91
movw $0x2a, (%r13,%rbx)
movq 0x10(%r12), %r12
incq %rbx
jmp 0x3b76
decl %eax
cmpl $0x8, %eax
ja 0x3cec
leaq 0x83f5(%rip), %rcx      # 0xbf98
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x0, 0x4(%rbx,%r13)
movl $0x64696f76, (%rbx,%r13) # imm = 0x64696F76
jmp 0x3ce5
movq (%rsp), %r14
addq %r14, %rdi
addq %rbx, %rdi
movq 0x18(%r12), %rdx
leaq 0x872a(%rip), %rsi      # 0xc2ff
xorl %eax, %eax
callq 0x21c0
movl %eax, %r15d
addl %ebx, %ebp
addl %eax, %ebp
movq 0x10(%r12), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x3b56
addl %ebx, %r15d
addl %eax, %r15d
movl %r15d, %ebx
jmp 0x3cf0
movl $0x746e69, (%rbx,%r13)  # imm = 0x746E69
movl $0x3, %eax
jmp 0x3cee
movw $0x74, 0x4(%rbx,%r13)
movl $0x726f6873, (%rbx,%r13) # imm = 0x726F6873
movl $0x5, %eax
jmp 0x3cee
movq (%rsp), %rax
addq %rbx, %rax
addq %rax, %rdi
movl 0x4(%r12), %edx
leaq 0x86c3(%rip), %rsi      # 0xc305
xorl %eax, %eax
callq 0x21c0
movl %eax, %r15d
movq 0x20(%r12), %r12
testq %r12, %r12
je 0x3cb6
movl %ebp, %ebp
addq %rbx, %rbp
leaq (%rbx,%r13), %r14
leal (%r15,%rbp), %esi
movq 0x8(%r12), %rdx
movq (%rsp), %rdi
callq 0x3b56
addl %r15d, %eax
movslq %eax, %r15
leaq (%r14,%r15), %rdi
movq 0x10(%r12), %rdx
movl 0x18(%r12), %ecx
leaq 0x868c(%rip), %rsi      # 0xc318
xorl %eax, %eax
callq 0x21c0
addl %eax, %r15d
cmpq $0x0, (%r12)
je 0x3cad
movslq %r15d, %r15
leaq (%r15,%r13), %rax
movw $0x20, (%rbx,%rax)
incl %r15d
movq (%r12), %r12
testq %r12, %r12
jne 0x3c5f
movslq %r15d, %rax
addq %rax, %r13
movw $0x7d, (%rbx,%r13)
incl %eax
jmp 0x3cee
movb $0x0, 0x4(%rbx,%r13)
movl $0x72616863, (%rbx,%r13) # imm = 0x72616863
jmp 0x3ce5
movb $0x0, 0x4(%rbx,%r13)
movl $0x676e6f6c, (%rbx,%r13) # imm = 0x676E6F6C
movl $0x4, %eax
jmp 0x3cee
xorl %eax, %eax
addl %eax, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq