// File: /workspace/github_c_makefile_star2_O1/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, %r15
movl (%rdx), %eax
cmpq $0xf, %rax
ja 0xd0f3
movq %rdx, %r14
movq %rsi, %r13
leaq 0x16d72(%rip), %rcx     # 0x23c38
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r13, (%rsp)
movq 0x10(%r14), %r13
testq %r13, %r13
je 0xd166
movq %r13, %rdi
callq 0x3170
movq %rax, %r12
testq %r15, %r15
je 0xd260
movq (%r15), %rdi
movslq %r12d, %r14
movq %r13, %rsi
jmp 0xd033
leaq 0x180e3(%rip), %r14     # 0x24fec
jmp 0xd0fa
movl 0x8(%r14), %edx
cmpl $-0x1, %edx
je 0xd12a
movq %r15, %rdi
movq %r13, %rsi
callq 0xd2c1
movl %eax, %r12d
testq %r15, %r15
je 0xd25d
movq (%r15), %rax
movb $0x2a, (%rax)
jmp 0xd25a
leaq 0x1809b(%rip), %r14     # 0x24fdf
jmp 0xd0fa
movl 0x10(%r14), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0xd2c1
movl %eax, %ebp
testq %r15, %r15
je 0xcf70
movq (%r15), %rax
movb $0x28, 0x4(%rax)
movl $0x292a2820, (%rax)     # imm = 0x292A2820
addq $0x5, (%r15)
addl $0x5, %ebp
cmpl $0x0, 0x14(%r14)
jle 0xd14f
xorl %ebx, %ebx
testq %rbx, %rbx
je 0xcf99
testq %r15, %r15
je 0xcf96
movq (%r15), %rax
movw $0x202c, (%rax)         # imm = 0x202C
addq $0x2, (%r15)
addl $0x2, %ebp
movq 0x8(%r14), %rax
movl (%rax,%rbx,4), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0xd2c1
movl %eax, %r12d
addl %ebp, %r12d
incq %rbx
movslq 0x14(%r14), %rax
movl %r12d, %ebp
cmpq %rax, %rbx
jl 0xcf80
jmp 0xd152
leaq 0x19ec7(%rip), %r14     # 0x26e93
jmp 0xd0fa
leaq 0x18001(%rip), %r14     # 0x24fd9
jmp 0xd0fa
leaq 0x1800e(%rip), %r14     # 0x24ff2
jmp 0xd0fa
leaq 0x17fec(%rip), %r14     # 0x24fdc
jmp 0xd0fa
movl 0x8(%r14), %ecx
leaq 0x17ff9(%rip), %rdx     # 0x24ff9
leaq 0x10(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x31a0
movq %r14, %rdi
callq 0x3170
movq %rax, %r12
testq %r15, %r15
je 0xd260
movq (%r15), %rdi
movslq %r12d, %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x3360
addq %r14, (%r15)
jmp 0xd260
leaq 0x17f8a(%rip), %r14     # 0x24fd4
jmp 0xd0fa
leaq 0x185bb(%rip), %r14     # 0x25611
jmp 0xd0fa
leaq 0x17f81(%rip), %r14     # 0x24fe3
jmp 0xd0fa
leaq 0x185cd(%rip), %r14     # 0x2563b
jmp 0xd0fa
testq %r15, %r15
je 0xd084
movq (%r15), %rax
movw $0x205b, (%rax)         # imm = 0x205B
addq $0x2, (%r15)
movl 0xc(%r14), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0xd2c1
movl %eax, %r12d
addl $0x2, %r12d
movl 0x8(%r14), %ecx
leaq 0x17f67(%rip), %rdx     # 0x2500c
leaq 0x10(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x31a0
movq %r14, %rdi
callq 0x3170
movq %rax, %r14
testq %r15, %r15
je 0xd0e2
movq (%r15), %rdi
movq %r15, %rbx
movslq %r14d, %r15
leaq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x3360
addq %r15, (%rbx)
addl %r14d, %r12d
jmp 0xd260
leaq 0x19dbc(%rip), %r14     # 0x26ead
jmp 0xd0fa
leaq 0x17ed1(%rip), %r14     # 0x24fcb
movq %r14, %rdi
callq 0x3170
movq %rax, %r12
testq %r15, %r15
je 0xd260
movq (%r15), %rdi
movq %r15, %rbx
movslq %r12d, %r15
movq %r14, %rsi
movq %r15, %rdx
callq 0x3360
addq %r15, (%rbx)
jmp 0xd260
movl $0x5, %r12d
testq %r15, %r15
je 0xd260
movq (%r15), %rax
movb $0x2a, 0x4(%rax)
movl $0x64696f76, (%rax)     # imm = 0x64696F76
addq $0x5, (%r15)
jmp 0xd260
movl %ebp, %r12d
testq %r15, %r15
je 0xd25d
movq (%r15), %rax
movb $0x29, (%rax)
jmp 0xd25a
movabsq $0x7b20746375727473, %rax # imm = 0x7B20746375727473
leaq 0x10(%rsp), %rdi
movq %rax, (%rdi)
movb $0x0, 0x8(%rdi)
callq 0x3170
movq %rax, %rbp
testq %r15, %r15
je 0xd19f
movq (%r15), %rdi
movslq %ebp, %r12
leaq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x3360
addq %r12, (%r15)
cmpl $0x0, 0x18(%r14)
movq (%rsp), %r13
jle 0xd24c
xorl %ebx, %ebx
testq %rbx, %rbx
je 0xd1c5
testq %r15, %r15
je 0xd1c3
movq (%r15), %rax
movb $0x20, (%rax)
incq (%r15)
incl %ebp
movq %rbp, 0x8(%rsp)
leaq 0x10(%rsp), %r12
movq 0x8(%r14), %rax
movl (%rax,%rbx,8), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0xd2c1
movl %eax, %ebp
movq 0x8(%r14), %rax
movl 0x4(%rax,%rbx,8), %ecx
movl $0x80, %esi
movq %r12, %rdi
leaq 0x17e0c(%rip), %rdx     # 0x25006
xorl %eax, %eax
callq 0x31a0
movq %r12, %rdi
callq 0x3170
movq %r12, %rsi
movq %rax, %r12
testq %r15, %r15
je 0xd230
movq (%r15), %rdi
movq %r15, %r13
movslq %r12d, %r15
movq %r15, %rdx
callq 0x3360
addq %r15, (%r13)
movq %r13, %r15
movq (%rsp), %r13
addl 0x8(%rsp), %ebp
addl %ebp, %r12d
incq %rbx
movslq 0x18(%r14), %rax
movl %r12d, %ebp
cmpq %rax, %rbx
jl 0xd1b0
jmp 0xd24f
movl %ebp, %r12d
testq %r15, %r15
je 0xd25d
movq (%r15), %rax
movb $0x7d, (%rax)
incq (%r15)
incl %r12d
movl %r12d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq