// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_bitcode_parser.c
// Function: ir_enter_subblock
static void
ir_enter_subblock(ir_unit_t *iu, bcbitstream_t *bs, int outer_id_width)
{
  const uint32_t blockid = read_vbr(bs, 8);
  const uint32_t inner_id_width = read_vbr(bs, 4);
  align_bits32(bs);
  /* const uint32_t blocklen = */ read_bits(bs, 32);

  ir_block_t *ib = calloc(1, sizeof(ir_block_t));

  LIST_INSERT_HEAD(&iu->iu_blocks, ib, ib_link);

  TAILQ_INIT(&ib->ib_scoped_abbrevs);
  ir_blockinfo_t *ibi = blockinfo_find(iu, blockid);

  int valuelistsize = 0;
  rec_handler_t *rh;

  switch(blockid) {
  case BITCODE_BLOCKINFO:
    rh = blockinfo_rec_handler;
    break;
  case BITCODE_MODULE:
    rh = module_rec_handler;
    break;
  case BITCODE_PARAMATTR:
    rh = paramattr_rec_handler;
    break;
  case BITCODE_PARAMATTR_GROUP:
    rh = paramattr_group_rec_handler;
    break;
  case BITCODE_CONSTANTS:
    rh = constants_rec_handler;
    break;
  case BITCODE_FUNCTION:
    valuelistsize = iu->iu_next_value;
    iu->iu_first_func_value = iu->iu_next_value;

    if(iu->iu_vstoffset) {
      bcbitstream_t vstbs = *bs;
      // TODO(why * 8???????????.....the older is * 4)
      vstbs.bytes_offset = iu->iu_vstoffset * 4;
      vstbs.remain = 0;
      // cogbee...... How to parse the vstbs for ahead.
      // ir_parse_blocks(iu, 4, NULL, ibi, &vstbs);
      iu->iu_vstoffset = 0;
    }

    if(iu->iu_current_function == NULL) {
      iu->iu_current_function = TAILQ_FIRST(&iu->iu_functions_with_bodies);
    } else {
      iu->iu_current_function = TAILQ_NEXT(iu->iu_current_function,
                                           if_body_link);
    }

    ir_function_t *f = iu->iu_current_function;

    if(f == NULL)
      parser_error(iu, "Function body without matching function");

    function_prepare_parse(iu, f);
    rh = function_rec_handler;
    break;
  case BITCODE_VALUE_SYMTAB:
    rh = value_symtab_rec_handler;
    break;
  case BITCODE_METADATA:
    rh = metadata_rec_handler;
    break;
  case BITCODE_METADATA_ATTACHMENT:
    rh = metadata_attachment_rec_handler;
    break;
  case BITCODE_TYPES_NEW:
    rh = types_new_rec_handler;
    break;
  case BITCODE_STRTAB_BLOCK_ID:
    rh = strtab_rec_handler;
    break;
  case BITCODE_USELIST:
  case BITCODE_METADATA_KIND_BLOCK_ID:
  case BITCODE_IDENTIFICATION_BLOCK_ID:
  case BITCODE_OPERAND_BUNDLE_TAGS_BLOCK_ID:
  case BITCODE_SYMTAB_BLOCK_ID:
    rh = dummy_rec_handler;
    break;
  case BITCODE_SYNC_SCOPE_NAMES_BLOCK_ID:
    //cogbee...
    rh = dummy_rec_handler;
    break; 
  default:
    parser_error(iu, "Invalid block type %d", blockid);
  }

  ir_parse_blocks(iu, inner_id_width, rh, ibi, bs);

  switch(blockid) {
  case BITCODE_FUNCTION:
    function_process(iu, iu->iu_current_function);

    value_resize(iu, valuelistsize);
    break;

  case BITCODE_CONSTANTS:
    eval_constexprs(iu);
    break;

  case BITCODE_TYPES_NEW:
    types_finalize(iu);
    break;
  }

  block_destroy(ib);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x33b80
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x33b80
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x33b50
movq -0x10(%rbp), %rdi
movl $0x20, %esi
callq 0x17a80
movl $0x1, %edi
movl $0x28, %esi
callq 0x32c0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x140(%rax), %rax
movq -0x28(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
je 0x3322a
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x140(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x140(%rax)
movq -0x8(%rbp), %rcx
addq $0x140, %rcx            # imm = 0x140
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x3324e
movq -0x28(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x28(%rbp), %rcx
addq $0x10, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x33c50
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x18(%rbp), %eax
movq %rax, -0x68(%rbp)
subq $0x1a, %rax
ja 0x3344c
movq -0x68(%rbp), %rax
leaq 0xa9ef(%rip), %rcx      # 0x3dc8c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xa93(%rip), %rax       # 0x33d40
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0xb03(%rip), %rax       # 0x33dc0
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0xc03(%rip), %rax       # 0x33ed0
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0xdb3(%rip), %rax       # 0x34090
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0x10b3(%rip), %rax      # 0x343a0
movq %rax, -0x40(%rbp)
jmp 0x3346e
movq -0x8(%rbp), %rax
movl 0x198(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl 0x198(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x19c(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x578(%rax)
je 0x33364
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl 0x578(%rax), %eax
shll $0x2, %eax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, 0x578(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x1c0(%rax)
jne 0x3338a
movq -0x8(%rbp), %rax
movq 0x1a8(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x1c0(%rax)
jmp 0x333a3
movq -0x8(%rbp), %rax
movq 0x1c0(%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x1c0(%rax)
movq -0x8(%rbp), %rax
movq 0x1c0(%rax), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x333d7
movq -0x8(%rbp), %rdi
leaq 0xd4a0(%rip), %rsi      # 0x40864
movl $0x3ab, %edx            # imm = 0x3AB
leaq 0xd50f(%rip), %rcx      # 0x408df
movb $0x0, %al
callq 0x18220
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x1fd80
leaq 0x1805(%rip), %rax      # 0x34bf0
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0x1ba8(%rip), %rax      # 0x34fa0
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0x1c9b(%rip), %rax      # 0x350a0
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0x1cae(%rip), %rax      # 0x350c0
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0x1cc1(%rip), %rax      # 0x350e0
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0x2164(%rip), %rax      # 0x35590
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0x22b7(%rip), %rax      # 0x356f0
movq %rax, -0x40(%rbp)
jmp 0x3346e
leaq 0x22aa(%rip), %rax      # 0x356f0
movq %rax, -0x40(%rbp)
jmp 0x3346e
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %r8d
leaq 0xd409(%rip), %rsi      # 0x40864
movl $0x3cb, %edx            # imm = 0x3CB
leaq 0xd4a0(%rip), %rcx      # 0x40907
movb $0x0, %al
callq 0x18220
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x40(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %r8
callq 0x17da0
movl -0x18(%rbp), %eax
movl %eax, -0x6c(%rbp)
subl $0xb, %eax
je 0x334c9
jmp 0x33493
movl -0x6c(%rbp), %eax
subl $0xc, %eax
je 0x334a7
jmp 0x3349d
movl -0x6c(%rbp), %eax
subl $0x11, %eax
je 0x334d4
jmp 0x334dd
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x1c0(%rax), %rsi
callq 0x208c0
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x1ccd0
jmp 0x334dd
movq -0x8(%rbp), %rdi
callq 0x35710
jmp 0x334dd
movq -0x8(%rbp), %rdi
callq 0x35780
movq -0x28(%rbp), %rdi
callq 0x35800
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)