// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x1ee20
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x60(%rbp)
subq $0xb, %rax
ja 0x39118
movq -0x60(%rbp), %rax
leaq 0x5217(%rip), %rcx      # 0x3df80
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x261a0
movq -0x68(%rbp), %rdi
movq -0x8(%rbp), %rdx
movzbl %al, %esi
callq 0x19240
jmp 0x39185
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x261a0
movq -0x70(%rbp), %rdi
movq -0x8(%rbp), %rdx
movzwl %ax, %esi
callq 0x19280
jmp 0x39185
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x261a0
movq -0x78(%rbp), %rdi
movl %eax, %esi
movq -0x8(%rbp), %rdx
callq 0x192c0
jmp 0x39185
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x322d0
movq -0x80(%rbp), %rdi
movq %rax, %rsi
movq -0x8(%rbp), %rdx
callq 0x19300
jmp 0x39185
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x84(%rbp)
subl $0x1, %eax
je 0x38e68
jmp 0x38e2c
movl -0x84(%rbp), %eax
addl $-0x2, %eax
subl $0x1, %eax
ja 0x38e90
jmp 0x38e3c
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x261a0
movq -0x90(%rbp), %rdi
movl %eax, %esi
movq -0x8(%rbp), %rdx
callq 0x192c0
jmp 0x38eb5
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rdi
callq 0x323e0
movq -0x98(%rbp), %rdi
movl %eax, %esi
movq -0x8(%rbp), %rdx
callq 0x192c0
jmp 0x38eb5
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %r8d
leaq 0x5327(%rip), %rsi      # 0x3e1c9
movl $0x289, %edx            # imm = 0x289
leaq 0x849d(%rip), %rcx      # 0x4134b
movb $0x0, %al
callq 0x18220
jmp 0x39185
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x1ecd0
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
subl $0x7, %eax
je 0x38ef9
jmp 0x38edc
movl -0x9c(%rbp), %eax
subl $0x9, %eax
je 0x38f27
jmp 0x38ee9
movl -0x9c(%rbp), %eax
subl $0xb, %eax
je 0x38f13
jmp 0x38fd5
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rsi
movslq -0x28(%rbp), %rdx
callq 0x3330
jmp 0x38ffa
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rdx
xorl %esi, %esi
callq 0x31f0
jmp 0x38ffa
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl 0x30(%rax), %eax
cmpl -0x24(%rbp), %eax
jne 0x38f3f
jmp 0x38f5e
leaq 0x8436(%rip), %rdi      # 0x4137c
leaq 0x527c(%rip), %rsi      # 0x3e1c9
movl $0x299, %edx            # imm = 0x299
leaq 0x8439(%rip), %rcx      # 0x41392
callq 0x31c0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x38fd3
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,8), %esi
callq 0x20ee0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x48(%rbp), %rcx
callq 0x38d20
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x1ecd0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x38f71
jmp 0x38ffa
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %r8d
leaq 0x51e2(%rip), %rsi      # 0x3e1c9
movl $0x2a4, %edx            # imm = 0x2A4
leaq 0x83e4(%rip), %rcx      # 0x413d7
movb $0x0, %al
callq 0x18220
jmp 0x39185
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x1ecd0
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xa0(%rbp)
subl $0x9, %eax
je 0x39046
jmp 0x39021
movl -0xa0(%rbp), %eax
subl $0xb, %eax
jne 0x390f1
jmp 0x39032
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rdx
xorl %esi, %esi
callq 0x31f0
jmp 0x39116
movq -0x38(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl 0x30(%rax), %eax
cmpl -0x24(%rbp), %eax
jne 0x3905e
jmp 0x3907d
leaq 0x8317(%rip), %rdi      # 0x4137c
leaq 0x515d(%rip), %rsi      # 0x3e1c9
movl $0x2b1, %edx            # imm = 0x2B1
leaq 0x831a(%rip), %rcx      # 0x41392
callq 0x31c0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x390ef
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl (%rax,%rcx,8), %esi
callq 0x20ee0
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x4c(%rbp), %rcx
movslq 0x4(%rax,%rcx,8), %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x4c(%rbp), %rcx
movl (%rax,%rcx,8), %edx
movq -0x58(%rbp), %rcx
callq 0x38d20
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x39090
jmp 0x39116
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %r8d
leaq 0x50c6(%rip), %rsi      # 0x3e1c9
movl $0x2bb, %edx            # imm = 0x2BB
leaq 0x82f7(%rip), %rcx      # 0x41406
movb $0x0, %al
callq 0x18220
jmp 0x39185
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4760
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x24(%rax), %esi
callq 0x22560
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %r8
movq -0xa8(%rbp), %r9
leaq 0x505b(%rip), %rsi      # 0x3e1c9
movl $0x2c2, %edx            # imm = 0x2C2
leaq 0x82bc(%rip), %rcx      # 0x41436
movq %rax, (%rsp)
movb $0x0, %al
callq 0x18220
addq $0xc0, %rsp
popq %rbp
retq
nop