// File: /workspace/github_c_makefile_star2_O0/rchiossi[P]dexterity/lib/dex_parser.c
// Function: dx_encodedvalue
DexEncodedValue* dx_encodedvalue(ByteStream* bs, uint32_t offset) {
  DexEncodedValue* res;
  int check;
  int i;

  uint8_t value_type;
  uint8_t value_arg;

  if (bs == NULL) return NULL;

  bsseek(bs,offset);

  DX_ALLOC(DexEncodedValue,res);

  check = bsread(bs,(uint8_t*)&(res->argtype),sizeof(uint8_t));

  res->meta.corrupted = (check != sizeof(uint8_t));
  if (res->meta.corrupted) return res;

  value_type = (res->argtype & 0x1f);
  value_arg  = ((res->argtype >> 5) & 0x7);
	       
  switch (value_type) {
  case 0x00:
    DX_ALLOC_LIST(uint8_t,res->value,1);
    bsread(bs,(uint8_t*) res->value,sizeof(uint8_t));
    break;
  case 0x02:
  case 0x03:
  case 0x04:
  case 0x06:
  case 0x10:
  case 0x11:
  case 0x17:
  case 0x18:
  case 0x19:
  case 0x1a:
  case 0x1b:
    DX_ALLOC_LIST(uint8_t,res->value,value_arg+1);

    for (i=0; i<value_arg+1; i++)
      bsread(bs,(uint8_t*) &(res->value[i]),sizeof(uint8_t));   

    break;
  case 0x1c:
    res->value = (uint8_t*) dx_encodedarray(bs,bs->offset);
    break;
  case 0x1d:
    res->value = (uint8_t*) dx_encodedannotation(bs,bs->offset);
    break;
  case 0x1e:
  case 0x1f:
    res->value = NULL;
  default:
    res->meta.corrupted = true;
    res->value = (uint8_t*) -1;
  }

  return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x8593
movq $0x0, -0x8(%rbp)
jmp 0x8752
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x44f0
movl $0x18, %edi
callq 0x4750
movq %rax, -0x20(%rbp)
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x8, %rsi
movl $0x1, %edx
callq 0x4500
movl %eax, -0x24(%rbp)
movslq -0x24(%rbp), %rax
cmpq $0x1, %rax
setne %cl
movq -0x20(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
movq -0x20(%rbp), %rax
testb $0x1, (%rax)
je 0x8601
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8752
movq -0x20(%rbp), %rax
movb 0x8(%rax), %al
andb $0x1f, %al
movb %al, -0x29(%rbp)
movq -0x20(%rbp), %rax
movzbl 0x8(%rax), %eax
shrl $0x5, %eax
movb %al, -0x2a(%rbp)
movzbl -0x29(%rbp), %eax
movq %rax, -0x38(%rbp)
subq $0x1f, %rax
ja 0x8734
movq -0x38(%rbp), %rax
leaq 0x5b0c(%rip), %rcx      # 0xe144
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x8643
movl $0x1, %edi
callq 0x4750
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movl $0x1, %edx
callq 0x4500
jmp 0x874a
jmp 0x8675
movzbl -0x2a(%rbp), %eax
addl $0x1, %eax
cmpl $0x0, %eax
je 0x86a1
movzbl -0x2a(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x0, %rdi
callq 0x4750
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x86ad
movq -0x20(%rbp), %rax
movq $0x0, 0x10(%rax)
jmp 0x86af
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movzbl -0x2a(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x86ec
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movslq -0x28(%rbp), %rax
addq %rax, %rsi
movl $0x1, %edx
callq 0x4500
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x86b6
jmp 0x874a
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x48c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x874a
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x41a0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x874a
movq -0x20(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
movq -0x20(%rbp), %rax
movq $-0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)