// File: salleaffaire[P]MXFParser/klv.cpp
// Function: klv_item::parse_value()
bool klv_item::parse_value() {
   int rval = 0;

   switch (mKey[4]) {
   case KLV_RC_DICTIONARY:
      break;
   case KLV_RC_GROUP:
      if (mKey[5] == KLV_GROUP_UNIVERSAL_SET) {
         if (mKLVList) {
            delete mKLVList;
         }

         mKLVList = new std::list<std::shared_ptr<klv_item>>;
         
         // Initialize Bit Extractor
         bit_extractor be(mValue, mLength, BE_BIG_ENDIAN);
         // Need a KLV parser instance
         klv_parser klvp;
         
         klvp.set_verbosity(true);
         klvp.set_validation(true);
         
         bool klv_ret_val;
         do {
            auto p_klvi = std::shared_ptr<klv_item>(new klv_item);
            klv_ret_val = klvp.get_klv_item(*p_klvi, be);
            if (klv_ret_val) {
               mKLVList->push_back(p_klvi);
            }
            std::cout << "    Bytes left: " << be.get_bytes_left() << std::endl;
         } while (true == klv_ret_val);
      }
      else if (mKey[6] == KLV_GROUP_GLOBAL_SET) {
         
      }
      else if (mKey[6] == KLV_GROUP_LOCAL_SET) {
         
      }
      else if (mKey[6] == KLV_GROUP_VARIABLE_LENGTH_PACK) {
         
      }
      else if (mKey[6] == KLV_GROUP_FIXED_LENGTH_PACK) {
         
      }
      break;
   case KLV_RC_WRAPPER:
      break;           
   case KLV_RC_LABEL:
      break;            
   }
   
   return rval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x60(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x4, %esi
callq 0x5030
movzbl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x58(%rbp)
subl $0x3, %eax
ja 0x3ec0
movq -0x58(%rbp), %rax
leaq 0x83c5(%rip), %rcx      # 0xc00c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x3ec0
movq -0x60(%rbp), %rdi
movl $0x5, %esi
callq 0x5030
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x3e52
movq -0x60(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x3ca5
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x3ca3
movq -0x68(%rbp), %rdi
callq 0x5050
movq -0x68(%rbp), %rdi
movl $0x18, %esi
callq 0x3210
jmp 0x3ca5
movl $0x18, %edi
callq 0x3200
movq %rax, %rdi
movq %rdi, -0x70(%rbp)
callq 0x5070
movq -0x70(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
leaq -0x28(%rbp), %rdi
movl $0x1, %ecx
callq 0x5090
leaq -0x30(%rbp), %rdi
callq 0x5010
jmp 0x3ce7
leaq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x3ee0
jmp 0x3cf7
leaq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x3f00
jmp 0x3d07
jmp 0x3d09
movl $0x28, %edi
callq 0x3200
movq %rax, -0x78(%rbp)
jmp 0x3d19
movq -0x78(%rbp), %rdi
callq 0x3b50
jmp 0x3d24
movq -0x78(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x50d0
jmp 0x3d33
leaq -0x50(%rbp), %rdi
callq 0x5100
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
leaq -0x28(%rbp), %rdx
callq 0x3f20
movb %al, -0x79(%rbp)
jmp 0x3d51
movb -0x79(%rbp), %al
andb $0x1, %al
movb %al, -0x3d(%rbp)
testb $0x1, -0x3d(%rbp)
je 0x3dbe
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x5130
jmp 0x3d72
jmp 0x3dbe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3e44
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x28, %esi
callq 0x3210
jmp 0x3e44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x5190
jmp 0x3e44
movq 0xd213(%rip), %rdi      # 0x10fd8
leaq 0x8250(%rip), %rsi      # 0xc01c
callq 0x31f0
movq %rax, -0x88(%rbp)
jmp 0x3dda
leaq -0x28(%rbp), %rdi
callq 0x5170
movl %eax, -0x8c(%rbp)
jmp 0x3deb
movl -0x8c(%rbp), %esi
movq -0x88(%rbp), %rdi
callq 0x32d0
movq %rax, -0x98(%rbp)
jmp 0x3e06
movq -0x98(%rbp), %rdi
movq 0xd1a4(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x3e1b
leaq -0x50(%rbp), %rdi
callq 0x5190
movb -0x3d(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
movl $0x1, %eax
cmpl %ecx, %eax
je 0x3d09
leaq -0x28(%rbp), %rdi
callq 0x51b0
jmp 0x3eba
leaq -0x28(%rbp), %rdi
callq 0x51b0
jmp 0x3ed2
movq -0x60(%rbp), %rdi
movl $0x6, %esi
callq 0x5030
movzbl (%rax), %eax
cmpl $0x2, %eax
jne 0x3e6a
jmp 0x3eb8
movq -0x60(%rbp), %rdi
movl $0x6, %esi
callq 0x5030
movzbl (%rax), %eax
cmpl $0x3, %eax
jne 0x3e82
jmp 0x3eb6
movq -0x60(%rbp), %rdi
movl $0x6, %esi
callq 0x5030
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0x3e9a
jmp 0x3eb4
movq -0x60(%rbp), %rdi
movl $0x6, %esi
callq 0x5030
movzbl (%rax), %eax
cmpl $0x5, %eax
jne 0x3eb2
jmp 0x3eb2
jmp 0x3eb4
jmp 0x3eb6
jmp 0x3eb8
jmp 0x3eba
jmp 0x3ec0
jmp 0x3ec0
jmp 0x3ec0
cmpl $0x0, -0xc(%rbp)
setne %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x3380
nopl (%rax,%rax)