// File: salleaffaire[P]MXFParser/./mxf_base.hpp
// Function: mxf_file::decode_header_partition_pack(klv_item&)
int decode_header_partition_pack(klv_item &klv) {
      int rval = 0;
      
      bit_extractor be(klv.mValue, klv.mLength, BE_BIG_ENDIAN);
      
      m_header.m_hpp.m_major_version      = be.get_bits(16);
      m_header.m_hpp.m_minor_version      = be.get_bits(16);
      m_header.m_hpp.m_kag_size           = be.get_bits(32);
      m_header.m_hpp.m_this_partition     = be.get_64bits();
      m_header.m_hpp.m_previous_partition = be.get_64bits();
      m_header.m_hpp.m_footer_partition   = be.get_64bits();
      m_header.m_hpp.m_header_byte_count  = be.get_64bits();
      m_header.m_hpp.m_index_byte_count   = be.get_64bits();
      m_header.m_hpp.m_index_sid          = be.get_bits(32);
      m_header.m_hpp.m_body_offset        = be.get_64bits();
      m_header.m_hpp.m_body_sid           = be.get_bits(32);
      
      // UL of operational Pattern
      for (int i=0;i<16;++i) {
         m_header.m_hpp.m_operational_pattern.mKey[i] = be.get_bits(8);
      }

      // UL Batch - Skip the 8 bytes 
      be.get_64bits();
      
      uint32_t nunmber_of_ul = be.get_bytes_left();
      m_header.m_hpp.m_essence_containers = new Key<16>[nunmber_of_ul];

      for (int j=0;j<nunmber_of_ul;j++) {
         for (int i=0;i<16;++i) {
            m_header.m_hpp.m_essence_containers[j].mKey[i] = be.get_bits(8);
         }  
      }

      
#if 1
      
      std::cout << "  Major Version        = " << hex_to_string(m_header.m_hpp.m_major_version)
                << std::endl;
      std::cout << "  Minor Version        = " << hex_to_string(m_header.m_hpp.m_minor_version)
                << std::endl;
      std::cout << "  KAG Size             = " << hex_to_string(m_header.m_hpp.m_kag_size)
                << std::endl;
      std::cout << "  This Partition #     = " << hex_to_string(m_header.m_hpp.m_this_partition)
                << std::endl;
      std::cout << "  Previous Partition # = " << hex_to_string(m_header.m_hpp.m_previous_partition)
                << std::endl;
      std::cout << "  Footer Partition #   = " << hex_to_string(m_header.m_hpp.m_footer_partition)
                << std::endl;
      std::cout << "  Header Byte Count    = " << hex_to_string(m_header.m_hpp.m_header_byte_count)
                << std::endl;
      std::cout << "  Index Byte Count     = " << hex_to_string(m_header.m_hpp.m_index_byte_count)
                << std::endl;
      std::cout << "  Index SID            = " << hex_to_string(m_header.m_hpp.m_index_sid)
                << std::endl;
      std::cout << "  Body Offset          = " << hex_to_string(m_header.m_hpp.m_body_offset)
                << std::endl;
      std::cout << "  Body SID             = " << hex_to_string(m_header.m_hpp.m_body_sid)
                << std::endl;
      
#endif

      return rval;
   }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
leaq -0x30(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
movl $0x1, %ecx
callq 0x5090
movq -0x1c0(%rbp), %rdi
movl $0x10, %esi
callq 0x51c0
movl %eax, -0x1b4(%rbp)
jmp 0x76ee
movq -0x1c8(%rbp), %rax
movl -0x1b4(%rbp), %ecx
movw %cx, 0x18(%rax)
leaq -0x30(%rbp), %rdi
movl $0x10, %esi
callq 0x51c0
movl %eax, -0x1cc(%rbp)
jmp 0x7715
movq -0x1c8(%rbp), %rax
movl -0x1cc(%rbp), %ecx
movw %cx, 0x1a(%rax)
leaq -0x30(%rbp), %rdi
movl $0x20, %esi
callq 0x51c0
movl %eax, -0x1d0(%rbp)
jmp 0x773c
movq -0x1c8(%rbp), %rax
movl -0x1d0(%rbp), %ecx
movl %ecx, 0x1c(%rax)
leaq -0x30(%rbp), %rdi
callq 0x9220
movq %rax, -0x1d8(%rbp)
jmp 0x775e
movq -0x1c8(%rbp), %rax
movq -0x1d8(%rbp), %rcx
movq %rcx, 0x20(%rax)
leaq -0x30(%rbp), %rdi
callq 0x9220
movq %rax, -0x1e0(%rbp)
jmp 0x7782
movq -0x1c8(%rbp), %rax
movq -0x1e0(%rbp), %rcx
movq %rcx, 0x28(%rax)
leaq -0x30(%rbp), %rdi
callq 0x9220
movq %rax, -0x1e8(%rbp)
jmp 0x77a6
movq -0x1c8(%rbp), %rax
movq -0x1e8(%rbp), %rcx
movq %rcx, 0x30(%rax)
leaq -0x30(%rbp), %rdi
callq 0x9220
movq %rax, -0x1f0(%rbp)
jmp 0x77ca
movq -0x1c8(%rbp), %rax
movq -0x1f0(%rbp), %rcx
movq %rcx, 0x38(%rax)
leaq -0x30(%rbp), %rdi
callq 0x9220
movq %rax, -0x1f8(%rbp)
jmp 0x77ee
movq -0x1c8(%rbp), %rax
movq -0x1f8(%rbp), %rcx
movq %rcx, 0x40(%rax)
leaq -0x30(%rbp), %rdi
movl $0x20, %esi
callq 0x51c0
movl %eax, -0x1fc(%rbp)
jmp 0x7816
movq -0x1c8(%rbp), %rax
movl -0x1fc(%rbp), %ecx
movl %ecx, 0x48(%rax)
leaq -0x30(%rbp), %rdi
callq 0x9220
movq %rax, -0x208(%rbp)
jmp 0x7838
movq -0x1c8(%rbp), %rax
movq -0x208(%rbp), %rcx
movq %rcx, 0x50(%rax)
leaq -0x30(%rbp), %rdi
movl $0x20, %esi
callq 0x51c0
movl %eax, -0x20c(%rbp)
jmp 0x7860
movq -0x1c8(%rbp), %rax
movl -0x20c(%rbp), %ecx
movl %ecx, 0x58(%rax)
movl $0x0, -0x40(%rbp)
cmpl $0x10, -0x40(%rbp)
jge 0x78c6
leaq -0x30(%rbp), %rdi
movl $0x8, %esi
callq 0x51c0
movl %eax, -0x210(%rbp)
jmp 0x7893
movq -0x1c8(%rbp), %rax
movl -0x210(%rbp), %ecx
movb %cl, %dl
movslq -0x40(%rbp), %rcx
movb %dl, 0x5c(%rax,%rcx)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x7877
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x7fa9
leaq -0x30(%rbp), %rdi
callq 0x9220
jmp 0x78d1
leaq -0x30(%rbp), %rdi
callq 0x5170
movl %eax, -0x214(%rbp)
jmp 0x78e2
movl -0x214(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, %edi
shlq $0x4, %rdi
callq 0x3040
movq %rax, -0x220(%rbp)
jmp 0x7902
movq -0x1c8(%rbp), %rax
movq -0x220(%rbp), %rcx
movq %rcx, 0x70(%rax)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0x7983
movl $0x0, -0x4c(%rbp)
cmpl $0x10, -0x4c(%rbp)
jge 0x7976
leaq -0x30(%rbp), %rdi
movl $0x8, %esi
callq 0x51c0
movl %eax, -0x224(%rbp)
jmp 0x7946
movq -0x1c8(%rbp), %rax
movl -0x224(%rbp), %ecx
movb %cl, %dl
movq 0x70(%rax), %rax
movslq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x4c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x792a
jmp 0x7978
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x791b
movq 0x964e(%rip), %rdi      # 0x10fd8
leaq 0x4a5c(%rip), %rsi      # 0xc3ed
callq 0x31f0
movq %rax, -0x230(%rbp)
jmp 0x799f
movq -0x1c8(%rbp), %rax
movzwl 0x18(%rax), %esi
leaq -0x70(%rbp), %rdi
callq 0x93d0
jmp 0x79b5
movq -0x230(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x31d0
movq %rax, -0x238(%rbp)
jmp 0x79ce
movq -0x238(%rbp), %rdi
movq 0x95dc(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x79e3
leaq -0x70(%rbp), %rdi
callq 0x33c8
movq 0x95e5(%rip), %rdi      # 0x10fd8
leaq 0x4a0d(%rip), %rsi      # 0xc407
callq 0x31f0
movq %rax, -0x240(%rbp)
jmp 0x7a08
movq -0x1c8(%rbp), %rax
movzwl 0x1a(%rax), %esi
leaq -0x90(%rbp), %rdi
callq 0x93d0
jmp 0x7a21
movq -0x240(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x31d0
movq %rax, -0x248(%rbp)
jmp 0x7a3d
movq -0x248(%rbp), %rdi
movq 0x956d(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x7a52
leaq -0x90(%rbp), %rdi
callq 0x33c8
movq 0x9573(%rip), %rdi      # 0x10fd8
leaq 0x49b5(%rip), %rsi      # 0xc421
callq 0x31f0
movq %rax, -0x250(%rbp)
jmp 0x7a7a
movq -0x1c8(%rbp), %rax
movl 0x1c(%rax), %esi
leaq -0xb0(%rbp), %rdi
callq 0x9540
jmp 0x7a92
movq -0x250(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x31d0
movq %rax, -0x258(%rbp)
jmp 0x7aae
movq -0x258(%rbp), %rdi
movq 0x94fc(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x7ac3
leaq -0xb0(%rbp), %rdi
callq 0x33c8
movq 0x9502(%rip), %rdi      # 0x10fd8
leaq 0x495e(%rip), %rsi      # 0xc43b
callq 0x31f0
movq %rax, -0x260(%rbp)
jmp 0x7aeb
movq -0x1c8(%rbp), %rax
movq 0x20(%rax), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x9690
jmp 0x7b04
movq -0x260(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x31d0
movq %rax, -0x268(%rbp)
jmp 0x7b20
movq -0x268(%rbp), %rdi
movq 0x948a(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x7b35
leaq -0xd0(%rbp), %rdi
callq 0x33c8
movq 0x9490(%rip), %rdi      # 0x10fd8
leaq 0x4906(%rip), %rsi      # 0xc455
callq 0x31f0
movq %rax, -0x270(%rbp)
jmp 0x7b5d
movq -0x1c8(%rbp), %rax
movq 0x28(%rax), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x9690
jmp 0x7b76
movq -0x270(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x31d0
movq %rax, -0x278(%rbp)
jmp 0x7b92
movq -0x278(%rbp), %rdi
movq 0x9418(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x7ba7
leaq -0xf0(%rbp), %rdi
callq 0x33c8
movq 0x941e(%rip), %rdi      # 0x10fd8
leaq 0x48ae(%rip), %rsi      # 0xc46f
callq 0x31f0
movq %rax, -0x280(%rbp)
jmp 0x7bcf
movq -0x1c8(%rbp), %rax
movq 0x30(%rax), %rsi
leaq -0x110(%rbp), %rdi
callq 0x9690
jmp 0x7be8
movq -0x280(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x31d0
movq %rax, -0x288(%rbp)
jmp 0x7c04
movq -0x288(%rbp), %rdi
movq 0x93a6(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x7c19
leaq -0x110(%rbp), %rdi
callq 0x33c8
movq 0x93ac(%rip), %rdi      # 0x10fd8
leaq 0x4856(%rip), %rsi      # 0xc489
callq 0x31f0
movq %rax, -0x290(%rbp)
jmp 0x7c41
movq -0x1c8(%rbp), %rax
movq 0x38(%rax), %rsi
leaq -0x130(%rbp), %rdi
callq 0x9690
jmp 0x7c5a
movq -0x290(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x31d0
movq %rax, -0x298(%rbp)
jmp 0x7c76
movq -0x298(%rbp), %rdi
movq 0x9334(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x7c8b
leaq -0x130(%rbp), %rdi
callq 0x33c8
movq 0x933a(%rip), %rdi      # 0x10fd8
leaq 0x47fe(%rip), %rsi      # 0xc4a3
callq 0x31f0
movq %rax, -0x2a0(%rbp)
jmp 0x7cb3
movq -0x1c8(%rbp), %rax
movq 0x40(%rax), %rsi
leaq -0x150(%rbp), %rdi
callq 0x9690
jmp 0x7ccc
movq -0x2a0(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x31d0
movq %rax, -0x2a8(%rbp)
jmp 0x7ce8
movq -0x2a8(%rbp), %rdi
movq 0x92c2(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x7cfd
leaq -0x150(%rbp), %rdi
callq 0x33c8
movq 0x92c8(%rip), %rdi      # 0x10fd8
leaq 0x47a6(%rip), %rsi      # 0xc4bd
callq 0x31f0
movq %rax, -0x2b0(%rbp)
jmp 0x7d25
movq -0x1c8(%rbp), %rax
movl 0x48(%rax), %esi
leaq -0x170(%rbp), %rdi
callq 0x9540
jmp 0x7d3d
movq -0x2b0(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x31d0
movq %rax, -0x2b8(%rbp)
jmp 0x7d59
movq -0x2b8(%rbp), %rdi
movq 0x9251(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x7d6e
leaq -0x170(%rbp), %rdi
callq 0x33c8
movq 0x9257(%rip), %rdi      # 0x10fd8
leaq 0x474f(%rip), %rsi      # 0xc4d7
callq 0x31f0
movq %rax, -0x2c0(%rbp)
jmp 0x7d96
movq -0x1c8(%rbp), %rax
movq 0x50(%rax), %rsi
leaq -0x190(%rbp), %rdi
callq 0x9690
jmp 0x7daf
movq -0x2c0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x31d0
movq %rax, -0x2c8(%rbp)
jmp 0x7dcb
movq -0x2c8(%rbp), %rdi
movq 0x91df(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x7de0
leaq -0x190(%rbp), %rdi
callq 0x33c8
movq 0x91e5(%rip), %rdi      # 0x10fd8
leaq 0x46f7(%rip), %rsi      # 0xc4f1
callq 0x31f0
movq %rax, -0x2d0(%rbp)
jmp 0x7e08
movq -0x1c8(%rbp), %rax
movl 0x58(%rax), %esi
leaq -0x1b0(%rbp), %rdi
callq 0x9540
jmp 0x7e20
movq -0x2d0(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x31d0
movq %rax, -0x2d8(%rbp)
jmp 0x7e3c
movq -0x2d8(%rbp), %rdi
movq 0x916e(%rip), %rsi      # 0x10fb8
callq 0x3230
jmp 0x7e51
leaq -0x1b0(%rbp), %rdi
callq 0x33c8
movl -0x14(%rbp), %eax
movl %eax, -0x2dc(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x51b0
movl -0x2dc(%rbp), %eax
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x33c8
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x33c8
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x33c8
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x33c8
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x33c8
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x33c8
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x33c8
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x33c8
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x33c8
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x33c8
jmp 0x7fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x33c8
leaq -0x30(%rbp), %rdi
callq 0x51b0
movq -0x38(%rbp), %rdi
callq 0x3380
nopl (%rax,%rax)