// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_transform.c
// Function: legalize_aggregate_insertval
static void
legalize_aggregate_insertval(ir_unit_t *iu, ir_instr_insertval_t *ins)
{
  if(ins->num_indicies != 1) {
    parser_error(iu, "Unable to legalize insertval with %d indices",
                 ins->num_indicies);
  }

  const ir_value_t *src = value_get(iu, ins->src.value);
  const ir_value_t *dst = value_get(iu, ins->super.ii_ret.value);

  assert(src->iv_num_values == 0 ||
         src->iv_num_values == dst->iv_num_values);
  const ir_valuetype_t *sv = src->iv_data;
  const ir_valuetype_t *dv = dst->iv_data;
  for(int i = 0; i < dst->iv_num_values; i++) {
    if(i == ins->indicies[0]) {
      insert_move(iu, dv[i], ins->replacement, &ins->super);
    } else if(src->iv_num_values == 0) {
      ir_valuetype_t z = value_create_zero(iu, dv[i].type);
      insert_move(iu, dv[i], z, &ins->super);
    } else {
      insert_move(iu, dv[i], sv[i], &ins->super);
    }
  }
  instr_destroy(&ins->super);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x68(%rax)
je 0x28d30
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x68(%rax), %r8d
leaq 0x166d0(%rip), %rsi     # 0x3f3ed
movl $0xa59, %edx            # imm = 0xA59
leaq 0x16cc9(%rip), %rcx     # 0x3f9f2
movb $0x0, %al
callq 0x18220
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x58(%rax), %esi
callq 0x20ee0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %esi
callq 0x20ee0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x28d72
movq -0x18(%rbp), %rax
movl 0x30(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jne 0x28d74
jmp 0x28d93
leaq 0x16ca4(%rip), %rdi     # 0x3fa1f
leaq 0x1666b(%rip), %rsi     # 0x3f3ed
movl $0xa60, %edx            # imm = 0xA60
leaq 0x16cd5(%rip), %rcx     # 0x3fa63
callq 0x31c0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jge 0x28e6a
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x6c(%rcx), %eax
jne 0x28df1
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movslq -0x34(%rbp), %rsi
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rdx,%rsi,8), %rsi
movq 0x60(%rax), %rdx
callq 0x28130
jmp 0x28e5a
movq -0x18(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x28e33
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %esi
callq 0x20d30
movq %rax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq (%rax,%rdx,8), %rsi
movq -0x3c(%rbp), %rdx
callq 0x28130
jmp 0x28e58
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x34(%rbp), %r8
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq (%rsi,%r8,8), %rsi
movq (%rax,%rdx,8), %rdx
callq 0x28130
jmp 0x28e5a
jmp 0x28e5c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x28db2
movq -0x10(%rbp), %rdi
callq 0x1cad0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)