// File: /workspace/github_c_makefile_star2_O3/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
movl %edx, %r8d
movq %rdi, %r14
movl %edx, %eax
cmpq %rax, 0x170(%rdi)
jbe 0x21806
movq %rcx, %r12
movq %rsi, %rbx
movq 0x168(%r14), %rcx
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %r15
movl (%r15), %eax
cmpq $0xb, %rax
ja 0x21823
leaq 0x3330(%rip), %rcx      # 0x24958
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
movq %r12, %rsi
callq 0x16a31
movb %al, (%rbx)
jmp 0x217df
movq %r14, %rdi
movq %r12, %rsi
callq 0x1d7d6
movq %rax, (%rbx)
jmp 0x217df
movq %r14, %rdi
movl %r8d, %esi
callq 0xf5f0
movl (%r12), %r8d
cmpl $0xb, %r8d
je 0x216f6
cmpl $0x9, %r8d
je 0x21784
cmpl $0x7, %r8d
jne 0x2189c
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 0x2176d
movq %r14, %rdi
movq %r12, %rsi
callq 0x16a31
movl %eax, (%rbx)
jmp 0x217df
movq %r14, %rdi
movq %r12, %rsi
callq 0x16a31
movw %ax, (%rbx)
jmp 0x217df
movq %r14, %rdi
movl %r8d, %esi
callq 0xf5f0
movl (%r12), %r8d
cmpl $0x9, %r8d
je 0x21711
cmpl $0xb, %r8d
jne 0x21865
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 0x2187d
testl %r13d, %r13d
jle 0x217df
movq 0x18(%r12), %r12
xorl %ebp, %ebp
movl (%r12,%rbp,8), %r8d
cmpq %r8, 0x188(%r14)
jbe 0x217ee
movq 0x180(%r14), %rax
movq (%rax,%r8,8), %rcx
movq 0x8(%r15), %rax
movslq 0x4(%rax,%rbp,8), %rsi
addq %rbx, %rsi
movl (%rax,%rbp,8), %edx
movq %r14, %rdi
callq 0x215df
incq %rbp
cmpq %rbp, %r13
jne 0x21730
jmp 0x217df
cmpl $0x1, %r8d
jne 0x218b7
movq 0x30(%r12), %rax
movl 0x34(%rax), %eax
jmp 0x216bd
movl 0x8(%r15), %r13d
cmpl %r13d, 0x30(%r12)
jne 0x218d2
testl %r13d, %r13d
jle 0x217df
movq 0x18(%r12), %r12
xorl %ebp, %ebp
movl (%r12,%rbp,8), %r8d
cmpq %r8, 0x188(%r14)
jbe 0x217ee
movq 0x180(%r14), %rax
movq (%rax,%r8,8), %rcx
movl 0xc(%r15), %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x215df
movl 0xc(%r15), %esi
movq %r14, %rdi
callq 0xf5f0
movl %eax, %eax
addq %rax, %rbx
incq %rbp
cmpq %rbp, %r13
jne 0x2179f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3d7b(%rip), %rsi      # 0x25570
leaq 0x4528(%rip), %rcx      # 0x25d24
movq %r14, %rdi
movl $0x143, %edx            # imm = 0x143
jmp 0x2181c
leaq 0x42af(%rip), %rsi      # 0x25abc
leaq 0x42e1(%rip), %rcx      # 0x25af5
movq %r14, %rdi
movl $0x7c, %edx
xorl %eax, %eax
callq 0xca98
movq %r14, %rdi
movq %r15, %rsi
callq 0x415e
movq %rax, %r15
movl 0x24(%r12), %esi
movq %r14, %rdi
callq 0x120fa
movq %rax, (%rsp)
leaq 0x37ac(%rip), %rsi      # 0x24ff5
leaq 0x6940(%rip), %rcx      # 0x28190
movq %r14, %rdi
movl $0x2c2, %edx            # imm = 0x2C2
movq %rbx, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0xca98
leaq 0x3789(%rip), %rsi      # 0x24ff5
leaq 0x68ed(%rip), %rcx      # 0x28160
movq %r14, %rdi
movl $0x2bb, %edx            # imm = 0x2BB
jmp 0x2181c
leaq 0x6852(%rip), %rdi      # 0x280d6
leaq 0x376a(%rip), %rsi      # 0x24ff5
leaq 0x685a(%rip), %rcx      # 0x280ec
movl $0x2b1, %edx            # imm = 0x2B1
callq 0x31e0
leaq 0x3752(%rip), %rsi      # 0x24ff5
leaq 0x6887(%rip), %rcx      # 0x28131
movq %r14, %rdi
movl $0x2a4, %edx            # imm = 0x2A4
jmp 0x2181c
leaq 0x3737(%rip), %rsi      # 0x24ff5
leaq 0x67e0(%rip), %rcx      # 0x280a5
movq %r14, %rdi
movl $0x289, %edx            # imm = 0x289
jmp 0x21804
leaq 0x67fd(%rip), %rdi      # 0x280d6
leaq 0x3715(%rip), %rsi      # 0x24ff5
leaq 0x6805(%rip), %rcx      # 0x280ec
movl $0x299, %edx            # imm = 0x299
callq 0x31e0