// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_bitcode_instr.c
// Function: parse_extractval
static void
parse_extractval(ir_unit_t *iu, unsigned int argc, const int64_t *argv)
{
  ir_bb_t *ib = iu->iu_current_bb;

  ir_valuetype_t base = instr_get_vtp(iu, &argc, &argv);
  const int num_indicies = argc;
  int current_type_index = base.type;

  ir_instr_extractval_t *ii = instr_add(ib,
                                        sizeof(ir_instr_extractval_t) +
                                        sizeof(int) * num_indicies,
                                        IR_IC_EXTRACTVAL);
  ii->num_indicies = num_indicies;
  ii->value = base;

  for(int i = 0; i < num_indicies; i++) {
    ir_type_t *ty = type_get(iu, current_type_index);
    int idx = argv[i];
    ii->indicies[i] = idx;
    switch(ty->it_code) {
    default:
      parser_error(iu, "Bad type %s into struct in extractval", type_str(iu, ty));

    case IR_TYPE_STRUCT:
      if(idx >= ty->it_struct.num_elements)
        parser_error(iu, "Bad index %d into struct in extractval", idx);
      current_type_index = ty->it_struct.elements[idx].type;
      break;
    case IR_TYPE_ARRAY:
      current_type_index = ty->it_array.element_type;
      break;
    }
  }

  value_alloc_instr_ret(iu, current_type_index, &ii->super);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x1c8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xc(%rbp), %rsi
leaq -0x18(%rbp), %rdx
callq 0x37a40
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x2c(%rbp), %rsi
shlq $0x2, %rsi
addq $0x68, %rsi
movl $0x10, %edx
callq 0x20c10
movq %rax, -0x38(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, 0x58(%rax)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x37782
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x1ee20
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,8), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %edx
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, 0x64(%rax,%rcx,4)
movq -0x48(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x50(%rbp)
testl %eax, %eax
je 0x37726
jmp 0x376e6
movl -0x50(%rbp), %eax
subl $0xa, %eax
je 0x37768
jmp 0x376f0
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x4760
movq -0x58(%rbp), %rdi
movq %rax, %r8
leaq 0x95ac(%rip), %rsi      # 0x40cbf
movl $0x2f5, %edx            # imm = 0x2F5
leaq 0x97e5(%rip), %rcx      # 0x40f04
movb $0x0, %al
callq 0x18220
movl -0x4c(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jl 0x37754
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %r8d
leaq 0x957e(%rip), %rsi      # 0x40cbf
movl $0x2f9, %edx            # imm = 0x2F9
leaq 0x97dd(%rip), %rcx      # 0x40f2a
movb $0x0, %al
callq 0x18220
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x4c(%rbp), %rcx
movl (%rax,%rcx,8), %eax
movl %eax, -0x30(%rbp)
jmp 0x37772
movq -0x48(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x37774
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3769e
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
movq -0x38(%rbp), %rdx
callq 0x22410
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)