// File: /workspace/github_c_makefile_star2_O2/cogbee[P]vmir-latest/src/vmir_type.c
// Function: type_print
static int
type_print(char **dst, const ir_unit_t *iu, const ir_type_t *it)
{
  char tmpbuf[128];
  const char *append = "type-???";
  int len = 0;

  switch(it->it_code) {
  case IR_TYPE_VOID:       append = "void"; break;
  case IR_TYPE_INT1:       append = "i1"; break;
  case IR_TYPE_INT8:       append = "i8"; break;
  case IR_TYPE_INT16:      append = "i16"; break;
  case IR_TYPE_INT32:      append = "i32"; break;
  case IR_TYPE_INT64:      append = "i64"; break;
  case IR_TYPE_FLOAT:      append = "float"; break;
  case IR_TYPE_DOUBLE:     append = "double"; break;
  case IR_TYPE_METADATA:   append = "metadata"; break;
  case IR_TYPE_LABEL:      append = "label"; break;
  case IR_TYPE_OPAQUE:     append = "opaque"; break;

  case IR_TYPE_INTx:
    snprintf(tmpbuf, sizeof(tmpbuf), "i%d", it->it_bits);
    return addstr(dst, tmpbuf);

  case IR_TYPE_STRUCT:
    if(it->it_struct.name != NULL) {
      len += addstr(dst, it->it_struct.name);
      return len;
    }

    snprintf(tmpbuf, sizeof(tmpbuf), "struct {");

    len += addstr(dst, tmpbuf);

    for(int i = 0; i < it->it_struct.num_elements; i++) {
      if(i > 0)
        len += addstr(dst, " ");

      len += type_print_id(dst, iu, it->it_struct.elements[i].type);

      snprintf(tmpbuf, sizeof(tmpbuf), " @ %x",
               it->it_struct.elements[i].offset);
      len += addstr(dst, tmpbuf);
    }
    len += addstr(dst, "}");
    return len;

  case IR_TYPE_ARRAY:
    len += addstr(dst, "[ ");

    len += type_print_id(dst, iu, it->it_array.element_type);

    snprintf(tmpbuf, sizeof(tmpbuf), " x %d ]", it->it_array.num_elements);
    len += addstr(dst, tmpbuf);
    return len;

  case IR_TYPE_POINTER:
    if(it->it_pointer.pointee == -1) {
      len += addstr(dst, "void*");
    } else {
      len += type_print_id(dst, iu, it->it_pointer.pointee);
      len += addstr(dst, "*");
    }
    return len;

  case IR_TYPE_FUNCTION:
    len += type_print_id(dst, iu, it->it_function.return_type);
    len += addstr(dst, " (*)(");

    for(int i = 0; i < it->it_function.num_parameters; i++) {
      if(i > 0)
        len += addstr(dst, ", ");

      len += type_print_id(dst, iu, it->it_function.parameters[i]);
    }
    len += addstr(dst, ")");
    return len;
  }

  len += addstr(dst, append);
  return len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
movl (%rdx), %eax
cmpq $0xf, %rax
ja 0xc4f7
movq %rdx, %r14
movq %rsi, %r15
leaq 0x12997(%rip), %rcx     # 0x1ec48
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%r14), %rsi
testq %rsi, %rsi
jne 0xc507
movq %r15, 0x8(%rsp)
movabsq $0x7b20746375727473, %rax # imm = 0x7B20746375727473
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movb $0x0, 0x8(%rsi)
movq %rbx, %rdi
callq 0xc58c
movl %eax, %ebp
xorl %r12d, %r12d
movslq 0x18(%r14), %rax
cmpq %rax, %r12
jge 0xc51d
testq %r12, %r12
je 0xc312
movq %rbx, %rdi
leaq 0x14a6a(%rip), %rsi     # 0x20d75
callq 0xc58c
addl %eax, %ebp
movq 0x8(%rsp), %rsi
movq 0x8(%r14), %rax
movl (%rax,%r12,8), %edx
movq %rbx, %rdi
callq 0xc5cd
movl %eax, %r13d
movq 0x8(%r14), %rax
movl 0x4(%rax,%r12,8), %ecx
movl $0x80, %esi
leaq 0x10(%rsp), %r15
movq %r15, %rdi
leaq 0x13e9f(%rip), %rdx     # 0x201e6
xorl %eax, %eax
callq 0x31a0
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc58c
addl %ebp, %eax
addl %r13d, %eax
incq %r12
movl %eax, %ebp
jmp 0xc2ef
leaq 0x13e60(%rip), %rsi     # 0x201cc
jmp 0xc507
movl 0x8(%r14), %edx
cmpl $-0x1, %edx
je 0xc500
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc5cd
movl %eax, %ebp
leaq 0x13e69(%rip), %rsi     # 0x201fb
jmp 0xc524
leaq 0x13e21(%rip), %rsi     # 0x201bf
jmp 0xc507
movl 0x10(%r14), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc5cd
movl %eax, %r12d
leaq 0x13e41(%rip), %rsi     # 0x201fd
movq %rbx, %rdi
callq 0xc58c
movl %eax, %ebp
addl %r12d, %ebp
xorl %r13d, %r13d
leaq 0x13e30(%rip), %r12     # 0x20203
movslq 0x14(%r14), %rax
cmpq %rax, %r13
jge 0xc408
testq %r13, %r13
je 0xc3ee
movq %rbx, %rdi
movq %r12, %rsi
callq 0xc58c
addl %eax, %ebp
movq 0x8(%r14), %rax
movl (%rax,%r13,4), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc5cd
addl %eax, %ebp
incq %r13
jmp 0xc3d3
leaq 0x13c32(%rip), %rsi     # 0x20041
jmp 0xc524
leaq 0x15c2d(%rip), %rsi     # 0x22048
jmp 0xc507
leaq 0x13d92(%rip), %rsi     # 0x201b9
jmp 0xc507
leaq 0x13d9f(%rip), %rsi     # 0x201d2
jmp 0xc507
leaq 0x13d7d(%rip), %rsi     # 0x201bc
jmp 0xc507
movl 0x8(%r14), %ecx
leaq 0x13d8a(%rip), %rdx     # 0x201d9
leaq 0x10(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x31a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc58c
jmp 0xc52e
leaq 0x13d3a(%rip), %rsi     # 0x201b4
jmp 0xc507
leaq 0x14371(%rip), %rsi     # 0x207f7
jmp 0xc507
leaq 0x13d34(%rip), %rsi     # 0x201c3
jmp 0xc507
leaq 0x14389(%rip), %rsi     # 0x20821
jmp 0xc507
leaq 0x13d4b(%rip), %rsi     # 0x201ec
movq %rbx, %rdi
callq 0xc58c
movl %eax, %ebp
movl 0xc(%r14), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc5cd
movl %eax, %r15d
movl 0x8(%r14), %ecx
leaq 0x13d27(%rip), %rdx     # 0x201ef
leaq 0x10(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x31a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc58c
addl %ebp, %eax
addl %r15d, %eax
jmp 0xc52e
leaq 0x15b6d(%rip), %rsi     # 0x22062
jmp 0xc507
leaq 0x13cad(%rip), %rsi     # 0x201ab
jmp 0xc507
leaq 0x13cf0(%rip), %rsi     # 0x201f7
movq %rbx, %rdi
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc58c
leaq 0x148ad(%rip), %rsi     # 0x20dd1
movq %rbx, %rdi
callq 0xc58c
addl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq