// File: /workspace/github_c_makefile_star2_O3/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 0xd117
movq %rdx, %r14
movq %rsi, %r13
leaq 0x16d72(%rip), %rcx     # 0x23c5c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r13, (%rsp)
movq 0x10(%r14), %r13
testq %r13, %r13
je 0xd18a
movq %r13, %rdi
callq 0x3170
movq %rax, %r12
testq %r15, %r15
je 0xd284
movq (%r15), %rdi
movslq %r12d, %r14
movq %r13, %rsi
jmp 0xd057
leaq 0x1816f(%rip), %r14     # 0x2509c
jmp 0xd11e
movl 0x8(%r14), %edx
cmpl $-0x1, %edx
je 0xd14e
movq %r15, %rdi
movq %r13, %rsi
callq 0xd2e5
movl %eax, %r12d
testq %r15, %r15
je 0xd281
movq (%r15), %rax
movb $0x2a, (%rax)
jmp 0xd27e
leaq 0x18127(%rip), %r14     # 0x2508f
jmp 0xd11e
movl 0x10(%r14), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0xd2e5
movl %eax, %ebp
testq %r15, %r15
je 0xcf94
movq (%r15), %rax
movb $0x28, 0x4(%rax)
movl $0x292a2820, (%rax)     # imm = 0x292A2820
addq $0x5, (%r15)
addl $0x5, %ebp
cmpl $0x0, 0x14(%r14)
jle 0xd173
xorl %ebx, %ebx
testq %rbx, %rbx
je 0xcfbd
testq %r15, %r15
je 0xcfba
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 0xd2e5
movl %eax, %r12d
addl %ebp, %r12d
incq %rbx
movslq 0x14(%r14), %rax
movl %r12d, %ebp
cmpq %rax, %rbx
jl 0xcfa4
jmp 0xd176
leaq 0x19eed(%rip), %r14     # 0x26edd
jmp 0xd11e
leaq 0x1808d(%rip), %r14     # 0x25089
jmp 0xd11e
leaq 0x1809a(%rip), %r14     # 0x250a2
jmp 0xd11e
leaq 0x18078(%rip), %r14     # 0x2508c
jmp 0xd11e
movl 0x8(%r14), %ecx
leaq 0x18085(%rip), %rdx     # 0x250a9
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 0xd284
movq (%r15), %rdi
movslq %r12d, %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x3360
addq %r14, (%r15)
jmp 0xd284
leaq 0x18016(%rip), %r14     # 0x25084
jmp 0xd11e
leaq 0x18647(%rip), %r14     # 0x256c1
jmp 0xd11e
leaq 0x1800d(%rip), %r14     # 0x25093
jmp 0xd11e
leaq 0x18659(%rip), %r14     # 0x256eb
jmp 0xd11e
testq %r15, %r15
je 0xd0a8
movq (%r15), %rax
movw $0x205b, (%rax)         # imm = 0x205B
addq $0x2, (%r15)
movl 0xc(%r14), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0xd2e5
movl %eax, %r12d
addl $0x2, %r12d
movl 0x8(%r14), %ecx
leaq 0x17ff3(%rip), %rdx     # 0x250bc
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 0xd106
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 0xd284
leaq 0x19de2(%rip), %r14     # 0x26ef7
jmp 0xd11e
leaq 0x17f5d(%rip), %r14     # 0x2507b
movq %r14, %rdi
callq 0x3170
movq %rax, %r12
testq %r15, %r15
je 0xd284
movq (%r15), %rdi
movq %r15, %rbx
movslq %r12d, %r15
movq %r14, %rsi
movq %r15, %rdx
callq 0x3360
addq %r15, (%rbx)
jmp 0xd284
movl $0x5, %r12d
testq %r15, %r15
je 0xd284
movq (%r15), %rax
movb $0x2a, 0x4(%rax)
movl $0x64696f76, (%rax)     # imm = 0x64696F76
addq $0x5, (%r15)
jmp 0xd284
movl %ebp, %r12d
testq %r15, %r15
je 0xd281
movq (%r15), %rax
movb $0x29, (%rax)
jmp 0xd27e
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 0xd1c3
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 0xd270
xorl %ebx, %ebx
testq %rbx, %rbx
je 0xd1e9
testq %r15, %r15
je 0xd1e7
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 0xd2e5
movl %eax, %ebp
movq 0x8(%r14), %rax
movl 0x4(%rax,%rbx,8), %ecx
movl $0x80, %esi
movq %r12, %rdi
leaq 0x17e98(%rip), %rdx     # 0x250b6
xorl %eax, %eax
callq 0x31a0
movq %r12, %rdi
callq 0x3170
movq %r12, %rsi
movq %rax, %r12
testq %r15, %r15
je 0xd254
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 0xd1d4
jmp 0xd273
movl %ebp, %r12d
testq %r15, %r15
je 0xd281
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