// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_wasm_parser.c
// Function: wasm_load
static void
wasm_load(ir_unit_t *iu, ir_bb_t *ib, int code, wasm_bytestream_t *wbs)
{
  int type;
  int cast = -1;
  int p = 0;
  switch(code) {
  case 0x28: type = WASM_TYPE_I32; break;
  case 0x29: type = WASM_TYPE_I64; break;
  case 0x2a: type = WASM_TYPE_F32; break;
  case 0x2b: type = WASM_TYPE_F64; break;

    // Load from smaller values and extend

  case 0x2c: type = WASM_TYPE_I32; p = WASM_TYPE_I8;  cast = CAST_SEXT; break;
  case 0x2d: type = WASM_TYPE_I32; p = WASM_TYPE_I8;  cast = CAST_ZEXT; break;
  case 0x2e: type = WASM_TYPE_I32; p = WASM_TYPE_I16; cast = CAST_SEXT; break;
  case 0x2f: type = WASM_TYPE_I32; p = WASM_TYPE_I16; cast = CAST_ZEXT; break;

  case 0x30: type = WASM_TYPE_I64; p = WASM_TYPE_I8;  cast = CAST_SEXT; break;
  case 0x31: type = WASM_TYPE_I64; p = WASM_TYPE_I8;  cast = CAST_ZEXT; break;
  case 0x32: type = WASM_TYPE_I64; p = WASM_TYPE_I16; cast = CAST_SEXT; break;
  case 0x33: type = WASM_TYPE_I64; p = WASM_TYPE_I16; cast = CAST_ZEXT; break;
  case 0x34: type = WASM_TYPE_I64; p = WASM_TYPE_I32; cast = CAST_SEXT; break;
  case 0x35: type = WASM_TYPE_I64; p = WASM_TYPE_I32; cast = CAST_ZEXT; break;

  default:
    parser_error(iu, "Can't handle load 0x%x", code);
  }

  /* int flags =*/ wbs_get_vu32(wbs);
  int offset = wbs_get_vu32(wbs);

  ir_instr_load_t *i = instr_add(ib, sizeof(ir_instr_load_t), IR_IC_LOAD);
  i->ptr = vstack_pop(iu);
  i->immediate_offset = offset;
  i->value_offset.value = -1;
  i->cast = cast;
  i->load_type = p;
  value_alloc_instr_ret(iu, type, &i->super);
  vstack_push(iu, i->super.ii_ret);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x2c(%rbp)
movl -0x14(%rbp), %eax
addl $-0x28, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0xd, %eax
ja 0x21743
movq -0x48(%rbp), %rax
leaq 0x1bbf7(%rip), %rcx     # 0x3d20c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, -0x24(%rbp)
jmp 0x21765
movl $0x2, -0x24(%rbp)
jmp 0x21765
movl $0x3, -0x24(%rbp)
jmp 0x21765
movl $0x4, -0x24(%rbp)
jmp 0x21765
movl $0x1, -0x24(%rbp)
movl $0x5, -0x2c(%rbp)
movl $0x2, -0x28(%rbp)
jmp 0x21765
movl $0x1, -0x24(%rbp)
movl $0x5, -0x2c(%rbp)
movl $0x1, -0x28(%rbp)
jmp 0x21765
movl $0x1, -0x24(%rbp)
movl $0x6, -0x2c(%rbp)
movl $0x2, -0x28(%rbp)
jmp 0x21765
movl $0x1, -0x24(%rbp)
movl $0x6, -0x2c(%rbp)
movl $0x1, -0x28(%rbp)
jmp 0x21765
movl $0x2, -0x24(%rbp)
movl $0x5, -0x2c(%rbp)
movl $0x2, -0x28(%rbp)
jmp 0x21765
movl $0x2, -0x24(%rbp)
movl $0x5, -0x2c(%rbp)
movl $0x1, -0x28(%rbp)
jmp 0x21765
movl $0x2, -0x24(%rbp)
movl $0x6, -0x2c(%rbp)
movl $0x2, -0x28(%rbp)
jmp 0x21765
movl $0x2, -0x24(%rbp)
movl $0x6, -0x2c(%rbp)
movl $0x1, -0x28(%rbp)
jmp 0x21765
movl $0x2, -0x24(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x2, -0x28(%rbp)
jmp 0x21765
movl $0x2, -0x24(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x1, -0x28(%rbp)
jmp 0x21765
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %r8d
leaq 0x1d08a(%rip), %rsi     # 0x3e7dc
movl $0x312, %edx            # imm = 0x312
leaq 0x1d861(%rip), %rcx     # 0x3efbf
movb $0x0, %al
callq 0x18220
movq -0x20(%rbp), %rdi
callq 0x1d450
movq -0x20(%rbp), %rdi
callq 0x1d450
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movl $0x78, %esi
movl $0x4, %edx
callq 0x20c10
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1ea10
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq %rcx, 0x58(%rax)
movl -0x30(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x38(%rbp), %rax
movl $0xffffffff, 0x64(%rax) # imm = 0xFFFFFFFF
movl -0x28(%rbp), %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, 0x74(%rax)
movl -0x2c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x70(%rax)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x38(%rbp), %rdx
callq 0x22410
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x2c(%rax), %rsi
callq 0x1f360
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)