// File: /workspace/github_c_makefile_star2_O2/cogbee[P]vmir-latest/src/vmir_value.c
// Function: value_print
static int
value_print(char **dstp, ir_unit_t *iu, const ir_value_t *iv,
            const ir_type_t *it)
{
  int value = iv->iv_id;
  int len = 0;
  char tmpbuf[64];

  if(it == NULL) {
    if(iv->iv_type < VECTOR_LEN(&iu->iu_types))
      it = &VECTOR_ITEM(&iu->iu_types, iv->iv_type);
  }

  switch(iv->iv_class) {
  case IR_VC_UNDEF:
    len += addstr(dstp, "<undefined>");
    break;

  case IR_VC_CE:
    len += addstr(dstp, "<constexpr>");
    break;

  case IR_VC_AGGREGATE:
    len += type_print(dstp, iu, it);
    len += addstr(dstp, " = {");
    ir_valuetype_t *values = iv->iv_data;
    for(int i = 0; i < iv->iv_num_values; i++) {
      if(i != 0)
        len += addstr(dstp, ", ");
      len += value_print_vt(dstp, iu, values[i]);
    }
    len += addstr(dstp, "}");
    break;

  case IR_VC_DEAD:
    snprintf(tmpbuf, sizeof(tmpbuf), "<dead>%%%d", value);
    len += addstr(dstp, tmpbuf);
    break;

  case IR_VC_ALIAS:
    len += addstr(dstp, "alias -> ");
    len += value_print_id(dstp, iu, iv->iv_reg);
    break;

  case IR_VC_FUNCTION:
    len += addstr(dstp, "function ");
    if(iv->iv_func->if_name != NULL) {
      len += addstr(dstp, iv->iv_func->if_name);
      len += addstr(dstp, "() ");
    }
    len += type_print_id(dstp, iu, iv->iv_func->if_type);
    break;

  case IR_VC_GLOBALVAR:
    len += addstr(dstp, "global ");
    if(iv->iv_gvar->ig_name != NULL) {
      len += addstr(dstp, iv->iv_gvar->ig_name);
      len += addstr(dstp, " ");
    }
    len += type_print(dstp, iu, it);
    snprintf(tmpbuf, sizeof(tmpbuf), " @ 0x%x", iv->iv_gvar->ig_addr);
    len += addstr(dstp, tmpbuf);
    break;

  case IR_VC_TEMPORARY:
    len += addstr(dstp, "(");
    len += type_print(dstp, iu, it);
    snprintf(tmpbuf, sizeof(tmpbuf), ")%%%d", value);
    len += addstr(dstp, tmpbuf);
    break;

  case IR_VC_CONSTANT:
    len += addstr(dstp, "(");
    len += type_print(dstp, iu, it);
    snprintf(tmpbuf, sizeof(tmpbuf), ")%%%d", value);
    len += addstr(dstp, tmpbuf);
    if(it == NULL) {
      len += addstr(dstp, "badtype");
      break;
    }

    switch(it->it_code) {
    case IR_TYPE_INT1:
      snprintf(tmpbuf, sizeof(tmpbuf), "#0x%x", !!iv->iv_u32);
      break;
    case IR_TYPE_INT8:
    case IR_TYPE_INT16:
    case IR_TYPE_INT32:
    case IR_TYPE_POINTER:
      snprintf(tmpbuf, sizeof(tmpbuf), "#0x%x", iv->iv_u32);
      break;
    case IR_TYPE_INT64:
      snprintf(tmpbuf, sizeof(tmpbuf), "#0x%"PRIx64, iv->iv_u64);
      break;
    case IR_TYPE_FLOAT:
      snprintf(tmpbuf, sizeof(tmpbuf), "#%f", iv->iv_float);
      break;
    case IR_TYPE_DOUBLE:
      snprintf(tmpbuf, sizeof(tmpbuf), "#%f", iv->iv_double);
      break;
    default:
      snprintf(tmpbuf, sizeof(tmpbuf), "#?(code-%d)", it->it_code);
      break;
    }
    len += addstr(dstp, tmpbuf);
    break;

  case IR_VC_ZERO_INITIALIZER:
    len += addstr(dstp, "zeroinitializer");
    break;

  case IR_VC_REGFRAME:
    len += addstr(dstp, "(");
    len += type_print(dstp, iu, it);
    snprintf(tmpbuf, sizeof(tmpbuf), ")%%%d{0x%x}", value, iv->iv_reg);
    len += addstr(dstp, tmpbuf);
    break;
  case IR_VC_MACHINEREG:
    len += addstr(dstp, "(");
    len += type_print(dstp, iu, it);
    snprintf(tmpbuf, sizeof(tmpbuf), ")%%%d{r%d}", value, iv->iv_reg);
    len += addstr(dstp, tmpbuf);
    break;
  case IR_VC_DATA:
    {
      len += addstr(dstp, "data [");
      int size = type_sizeof(iu, iv->iv_type);
      for(int i = 0; i < size; i++) {
        if(i)
          len += addstr(dstp, ".");
        snprintf(tmpbuf, sizeof(tmpbuf), "%02x", ((uint8_t *)iv->iv_data)[i]);
        len += addstr(dstp, tmpbuf);
      }
      len += addstr(dstp, "]");
    }
    break;
  }

  if(iv->iv_name != NULL) {
    len += addstr(dstp, "\"");
    len += addstr(dstp, iv->iv_name);
    len += addstr(dstp, "\"");
  }
  return len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbx
testq %rcx, %rcx
jne 0xead7
movslq 0x24(%r13), %rax
cmpq %rax, 0x170(%r15)
jbe 0xead4
imulq $0x28, %rax, %r12
addq 0x168(%r15), %r12
jmp 0xead7
xorl %r12d, %r12d
movl (%r13), %eax
cmpq $0xc, %rax
ja 0xee23
movl 0x20(%r13), %ebp
leaq 0x10374(%rip), %rcx     # 0x1ee64
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x12237(%rip), %rsi     # 0x20d37
jmp 0xeead
leaq 0x122a0(%rip), %rsi     # 0x20dac
jmp 0xeead
leaq 0x126cc(%rip), %rsi     # 0x211e4
movq %rbx, %rdi
callq 0xc58c
movl %eax, %r14d
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xc284
movl %eax, %r12d
addl %r14d, %r12d
leaq 0x12249(%rip), %rdx     # 0x20d87
movq %rsp, %r14
pushq $0x40
popq %rsi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x31a0
jmp 0xee6e
leaq 0x121f8(%rip), %rdx     # 0x20d54
movq %rsp, %r14
pushq $0x40
popq %rsi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x31a0
movq %rbx, %rdi
movq %r14, %rsi
jmp 0xeeb0
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xc284
movl %eax, %r14d
leaq 0x121be(%rip), %rsi     # 0x20d4f
movq %rbx, %rdi
callq 0xc58c
movl %eax, %ebp
addl %r14d, %ebp
movq %r13, %r14
movq 0x18(%r13), %r12
xorl %r13d, %r13d
movslq 0x30(%r14), %rax
cmpq %rax, %r13
jge 0xebdd
testq %r13, %r13
je 0xebc7
movq %rbx, %rdi
leaq 0x11643(%rip), %rsi     # 0x20203
callq 0xc58c
addl %eax, %ebp
movq (%r12,%r13,8), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xef84
addl %eax, %ebp
incq %r13
jmp 0xeba8
leaq 0x121ed(%rip), %rsi     # 0x20dd1
jmp 0xed86
leaq 0x12187(%rip), %rsi     # 0x20d77
movq %rbx, %rdi
callq 0xc58c
movl %eax, %ebp
movq 0x30(%r13), %rax
movq 0x20(%rax), %rsi
testq %rsi, %rsi
je 0xec26
movq %rbx, %rdi
callq 0xc58c
movl %eax, %r14d
leaq 0x1215c(%rip), %rsi     # 0x20d75
movq %rbx, %rdi
callq 0xc58c
addl %eax, %ebp
addl %r14d, %ebp
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xc284
movl %eax, %r14d
addl %ebp, %r14d
movq 0x30(%r13), %rax
movl 0x28(%rax), %ecx
leaq 0x12137(%rip), %rdx     # 0x20d7f
movq %rsp, %r15
pushq $0x40
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x31a0
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc58c
movl %eax, %r15d
addl %r14d, %r15d
jmp 0xef1f
leaq 0x1256f(%rip), %rsi     # 0x211e4
movq %rbx, %rdi
callq 0xc58c
movl %eax, %r14d
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xc284
movl %eax, %r15d
addl %r14d, %r15d
leaq 0x120ec(%rip), %rdx     # 0x20d87
movq %rsp, %r14
pushq $0x40
popq %rsi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x31a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc58c
movl %eax, %ebp
addl %r15d, %ebp
testq %r12, %r12
je 0xeeba
movl (%r12), %ecx
leal -0x2(%rcx), %eax
cmpl $0x9, %eax
ja 0xef72
leaq 0x101bb(%rip), %rdx     # 0x1ee98
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movl 0x30(%r13), %ecx
leaq 0x12357(%rip), %rdx     # 0x21048
movq %rsp, %rdi
pushq $0x40
popq %rsi
xorl %eax, %eax
callq 0x31a0
jmp 0xef0e
leaq 0x120c9(%rip), %rsi     # 0x20dd3
movq %rbx, %rdi
callq 0xc58c
movl %eax, %ebp
movq %r13, %r14
movl 0x24(%r13), %esi
movq %r15, %rdi
callq 0xe68d
movl %eax, %r15d
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
movq %rsp, %r13
xorl %r12d, %r12d
cmpq %r12, %r15
je 0xed7f
testq %r12, %r12
je 0xed50
movq %rbx, %rdi
leaq 0x12401(%rip), %rsi     # 0x2114a
callq 0xc58c
addl %eax, %ebp
movq 0x18(%r14), %rax
movzbl (%rax,%r12), %ecx
movq %r13, %rdi
pushq $0x40
popq %rsi
leaq 0x12074(%rip), %rdx     # 0x20dda
xorl %eax, %eax
callq 0x31a0
movq %rbx, %rdi
movq %r13, %rsi
callq 0xc58c
addl %eax, %ebp
incq %r12
jmp 0xed35
leaq 0x1146f(%rip), %rsi     # 0x201f5
movq %rbx, %rdi
callq 0xc58c
movl %eax, %r15d
addl %ebp, %r15d
movq %r14, %r13
jmp 0xef1f
leaq 0x11fc6(%rip), %rsi     # 0x20d69
movq %rbx, %rdi
callq 0xc58c
movl %eax, %ebp
movq 0x30(%r13), %rax
movq 0x20(%rax), %rsi
testq %rsi, %rsi
je 0xeddd
movq %rbx, %rdi
callq 0xc58c
movl %eax, %r14d
leaq 0x11fa7(%rip), %rsi     # 0x20d73
movq %rbx, %rdi
callq 0xc58c
addl %eax, %ebp
addl %r14d, %ebp
movq 0x30(%r13), %rax
movl 0x10(%rax), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc5cd
jmp 0xef19
leaq 0x123ed(%rip), %rsi     # 0x211e4
movq %rbx, %rdi
callq 0xc58c
movl %eax, %r14d
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xc284
movl %eax, %r12d
addl %r14d, %r12d
movl 0x30(%r13), %r8d
leaq 0x11f9b(%rip), %rdx     # 0x20dbc
jmp 0xee5c
xorl %r15d, %r15d
jmp 0xef1f
leaq 0x123b2(%rip), %rsi     # 0x211e4
movq %rbx, %rdi
callq 0xc58c
movl %eax, %r14d
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xc284
movl %eax, %r12d
addl %r14d, %r12d
movl 0x30(%r13), %r8d
leaq 0x11f6c(%rip), %rdx     # 0x20dc8
movq %rsp, %r14
pushq $0x40
popq %rsi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x31a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc58c
movl %eax, %r15d
addl %r12d, %r15d
jmp 0xef1f
leaq 0x11ed4(%rip), %rsi     # 0x20d5f
movq %rbx, %rdi
callq 0xc58c
movl %eax, %ebp
movl 0x30(%r13), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xea40
jmp 0xef19
leaq 0x11e96(%rip), %rsi     # 0x20d43
movq %rbx, %rdi
callq 0xc58c
movl %eax, %r15d
jmp 0xef1f
leaq 0x11ecc(%rip), %rsi     # 0x20d8d
jmp 0xef11
movq 0x30(%r13), %rcx
leaq 0x11ec7(%rip), %rdx     # 0x20d95
movq %rsp, %rdi
pushq $0x40
popq %rsi
xorl %eax, %eax
callq 0x31a0
jmp 0xef0e
xorl %ecx, %ecx
cmpl $0x0, 0x30(%r13)
setne %cl
jmp 0xecea
cvtss2sd 0x30(%r13), %xmm0
jmp 0xeefa
movsd 0x30(%r13), %xmm0
leaq 0x11e9b(%rip), %rdx     # 0x20d9c
movq %rsp, %rdi
pushq $0x40
popq %rsi
movb $0x1, %al
callq 0x31a0
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xc58c
movl %eax, %r15d
addl %ebp, %r15d
cmpq $0x0, 0x10(%r13)
je 0xef60
leaq 0x1202a(%rip), %r14     # 0x20f57
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc58c
movl %eax, %ebp
addl %r15d, %ebp
movq 0x10(%r13), %rsi
movq %rbx, %rdi
callq 0xc58c
movl %eax, %r12d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc58c
movl %eax, %r15d
addl %ebp, %r15d
addl %r12d, %r15d
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11e27(%rip), %rdx     # 0x20da0
movq %rsp, %rdi
pushq $0x40
popq %rsi
jmp 0xecf7