// File: /workspace/github_c_makefile_star2_O2/cogbee[P]vmir-latest/src/vmir.c
// Function: initialize_global
static void
initialize_global(ir_unit_t *iu, void *addr,
                  int dstty_index, const ir_value_t *c)
{
  int x, size;
  ir_valuetype_t *ivt;
  const ir_type_t *dstty = type_get(iu, dstty_index);

  switch(dstty->it_code) {
  case IR_TYPE_INT1:
  case IR_TYPE_INT8:
    mem_wr8(addr, value_get_const32(iu, c), iu);
    break;
  case IR_TYPE_INT16:
    mem_wr16(addr, value_get_const32(iu, c), iu);
    break;
  case IR_TYPE_INT32:
  case IR_TYPE_FLOAT:
    mem_wr32(addr, value_get_const32(iu, c), iu);
    break;
  case IR_TYPE_INT64:
  case IR_TYPE_DOUBLE:
    mem_wr64(addr, value_get_const64(iu, c), iu);
    break;

  case IR_TYPE_POINTER:
    switch(c->iv_class) {
    case IR_VC_GLOBALVAR:
    case IR_VC_CONSTANT:
      mem_wr32(addr, value_get_const32(iu, c), iu);
      break;
    case IR_VC_FUNCTION:
      mem_wr32(addr, value_function_addr(c), iu);
      break;

    default:
      parser_error(iu, "Unable to initialize pointer from value class %d",
                   c->iv_class);
    }
    break;

  case IR_TYPE_ARRAY:
    size = type_sizeof(iu, dstty_index);
    switch(c->iv_class) {
    case IR_VC_DATA:
      memcpy(addr, c->iv_data, size);
      break;
    case IR_VC_ZERO_INITIALIZER:
      memset(addr, 0, size);
      break;
    case IR_VC_AGGREGATE:
      // Iterate over all elements
      x = dstty->it_array.num_elements;
      assert(c->iv_num_values == x);
      ivt = c->iv_data;
      for(int i = 0; i < x; i++) {
        ir_value_t *subvalue = value_get(iu, ivt[i].value);
        initialize_global(iu, addr, dstty->it_array.element_type, subvalue);
        addr += type_sizeof(iu, dstty->it_array.element_type);
      }

      break;
    default:
      parser_error(iu, "Unable to initialize array from value class %d",
                   c->iv_class);
    }
    break;

  case IR_TYPE_STRUCT:
    size = type_sizeof(iu, dstty_index);
    switch(c->iv_class) {
    case IR_VC_ZERO_INITIALIZER:
      memset(addr, 0, size);
      break;
    case IR_VC_AGGREGATE:
      // Iterate over all elements
      x = dstty->it_struct.num_elements;
      assert(c->iv_num_values == x);
      ivt = c->iv_data;
      for(int i = 0; i < x; i++) {
        ir_value_t *subvalue = value_get(iu, ivt[i].value);
        initialize_global(iu, addr + dstty->it_struct.elements[i].offset,
                          dstty->it_struct.elements[i].type, subvalue);
      }
      break;
    default:
      parser_error(iu, "Unable to initialize struct from value class %d",
                   c->iv_class);
    }
    break;

  default:
    parser_error(iu, "Unable to initialize global 0x%x (%s) from %s",
                 addr, type_str(iu, dstty),
                 type_str_index(iu, c->iv_type));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r12
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movl %edx, %esi
callq 0xe719
movq %rax, %r15
movl (%rax), %eax
cmpq $0xb, %rax
ja 0x1c90a
leaq 0x336b(%rip), %rcx      # 0x1facc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
movq %r12, %rsi
callq 0x14006
movb %al, (%rbx)
jmp 0x1c804
movq %r14, %rdi
movq %r12, %rsi
callq 0x19641
movq %rax, (%rbx)
jmp 0x1c804
movq %r14, %rdi
movl %ebp, %esi
callq 0xe68d
movl (%r12), %r8d
cmpl $0xb, %r8d
je 0x1c831
cmpl $0x9, %r8d
je 0x1c8b0
cmpl $0x7, %r8d
jne 0x1c983
movq 0x18(%r12), %rsi
movslq %eax, %rdx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3360
movl (%r12), %r8d
leal -0x2(%r8), %eax
cmpl $0x2, %eax
jae 0x1c899
movq %r14, %rdi
movq %r12, %rsi
callq 0x14006
movl %eax, (%rbx)
jmp 0x1c804
movq %r14, %rdi
movq %r12, %rsi
callq 0x14006
movw %ax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movl %ebp, %esi
callq 0xe68d
movl (%r12), %r8d
cmpl $0x9, %r8d
je 0x1c84c
cmpl $0xb, %r8d
jne 0x1c94c
movslq %eax, %rdx
movq %rbx, %rdi
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3210
movl 0x18(%r15), %r13d
cmpl %r13d, 0x30(%r12)
jne 0x1c964
movq 0x18(%r12), %r12
xorl %ebp, %ebp
testl %r13d, %r13d
cmovlel %ebp, %r13d
cmpq %rbp, %r13
je 0x1c804
movl (%r12,%rbp,8), %esi
movq %r14, %rdi
callq 0x102f1
movq 0x8(%r15), %rcx
movslq 0x4(%rcx,%rbp,8), %rsi
addq %rbx, %rsi
movl (%rcx,%rbp,8), %edx
movq %r14, %rdi
movq %rax, %rcx
callq 0x1c72e
incq %rbp
jmp 0x1c869
cmpl $0x1, %r8d
jne 0x1c99b
movq %r12, %rdi
callq 0x196e0
jmp 0x1c7f2
movl 0x8(%r15), %r13d
cmpl %r13d, 0x30(%r12)
jne 0x1c9b8
movq 0x18(%r12), %r12
xorl %ebp, %ebp
testl %r13d, %r13d
cmovlel %ebp, %r13d
cmpq %rbp, %r13
je 0x1c804
movl (%r12,%rbp,8), %esi
movq %r14, %rdi
callq 0x102f1
movl 0xc(%r15), %edx
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rcx
callq 0x1c72e
movl 0xc(%r15), %esi
movq %r14, %rdi
callq 0xe68d
movl %eax, %eax
addq %rax, %rbx
incq %rbp
jmp 0x1c8cd
movq %r14, %rdi
movq %r15, %rsi
callq 0x408f
movq %rax, %r15
movl 0x24(%r12), %esi
movq %r14, %rdi
callq 0x105cd
movq %rax, (%rsp)
leaq 0x37f5(%rip), %rsi      # 0x20125
leaq 0x69c4(%rip), %rcx      # 0x232fb
movq %r14, %rdi
movl $0x2c2, %edx            # imm = 0x2C2
movq %rbx, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0xbed2
leaq 0x37d2(%rip), %rsi      # 0x20125
leaq 0x6971(%rip), %rcx      # 0x232cb
movq %r14, %rdi
movl $0x2bb, %edx            # imm = 0x2BB
jmp 0x1c9b1
leaq 0x68d6(%rip), %rdi      # 0x23241
leaq 0x37b3(%rip), %rsi      # 0x20125
leaq 0x68de(%rip), %rcx      # 0x23257
movl $0x2b1, %edx            # imm = 0x2B1
callq 0x31e0
leaq 0x379b(%rip), %rsi      # 0x20125
leaq 0x690b(%rip), %rcx      # 0x2329c
movq %r14, %rdi
movl $0x2a4, %edx            # imm = 0x2A4
jmp 0x1c9b1
leaq 0x3783(%rip), %rsi      # 0x20125
leaq 0x6867(%rip), %rcx      # 0x23210
movq %r14, %rdi
movl $0x289, %edx            # imm = 0x289
xorl %eax, %eax
callq 0xbed2
leaq 0x6882(%rip), %rdi      # 0x23241
leaq 0x375f(%rip), %rsi      # 0x20125
leaq 0x688a(%rip), %rcx      # 0x23257
movl $0x299, %edx            # imm = 0x299
callq 0x31e0