// File: /workspace/github_cpp_makefile_star2_O2/ke6jjj[P]r-dat/DATFrame.cc
// Function: DATFrame::FillFromTrackPair(Track const&, Track const&)
void
DATFrame::FillFromTrackPair(const Track& A, const Track& B)
{
  bool everything_ok = true;

  //
  // Retrieve pointers to the data and meta-data in the A and B tracks passed
  // by the caller.
  //
  const Track::DataArray& a_bytes = A.Data();
  const Track::DataArray& b_bytes = B.Data();
  const Track::ValidityArray& a_valid = A.DataValid();
  const Track::ValidityArray& b_valid = B.DataValid();
  
  //
  // De-multiplex the bytes from the A and B tracks into their respective
  // positions in the frame.
  //
  // (Taken from DDS spec Section 9.3.4 G4 Sub-Group, there is likely the same
  // logic specified in the DAT Conference Standard as well).
  //
  for (size_t column = 0; column < 2; column++) {
    for (size_t word = 0; word < 1456; word++) {
      size_t source_block =
                                 (word %  52) + 
                            75 * (word %   2) +
                                 (word / 832);
      size_t u = (column + 1) % 2;
      size_t source_byte =
                            2  * (u + word /  52)     -
                                 (    word /  52) % 2 -
                            32 * (    word / 832);
      
      if ((word % 2) == 0) {
        mData[word][column]   = a_bytes[source_block][source_byte];
        mData[word][column+2] = b_bytes[source_block][source_byte];
        mDataIsValid[word][column]   = a_valid[source_block][source_byte];
        mDataIsValid[word][column+2] = b_valid[source_block][source_byte];
      } else {
        mData[word][column]   = b_bytes[source_block][source_byte];
        mData[word][column+2] = a_bytes[source_block][source_byte];
        mDataIsValid[word][column]   = b_valid[source_block][source_byte];
        mDataIsValid[word][column+2] = a_valid[source_block][source_byte];
      }
      everything_ok = everything_ok && mDataIsValid[word][column] &&
                      mDataIsValid[word][column+2];
    }
  }

  //
  // Gather up error statistics from the two constituent tracks.
  //
  mC1Errors = A.C1Errors() + B.C1Errors();
  mC1UncorrectableErrors = A.C1UncorrectableErrors() +
                           B.C1UncorrectableErrors();
  mC2UncorrectableErrors = A.C2UncorrectableErrors() +
                           B.C2UncorrectableErrors();

  if (mC2UncorrectableErrors && everything_ok) {
    //
    // This is supposed to be impossible.
    //
    printf("Inconsistency in C2 errors and erasures!!\n");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x3460
movq %rax, 0x20(%rsp)
movq %r14, %rdi
callq 0x3460
movq %rax, %r13
movq %r15, (%rsp)
movq %r15, %rdi
callq 0x3468
movq %rax, %r12
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0x3468
movq %rax, %r8
movq %rbx, 0x10(%rsp)
leaq 0x16c2(%rbx), %rdi
movb $0x1, %bl
xorl %r11d, %r11d
pushq $0x34
popq %r9
movw $0x34, %r10w
cmpq $0x2, %r11
je 0x58e0
movq %r11, 0x18(%rsp)
xorq $0x1, %r11
xorl %esi, %esi
movq %rsi, %rax
xorl %edx, %edx
divq %r9
cmpq $0x5b0, %rsi            # imm = 0x5B0
je 0x58d0
movl %esi, %edx
andl $0x1, %edx
imulq $0x4b, %rdx, %r14
imulq $0x34, %rax, %rax
subq %rax, %r14
xorl %r15d, %r15d
cmpq $0x340, %rsi            # imm = 0x340
setae %r15b
addq %r15, %r14
addq %rsi, %r14
movl %esi, %eax
xorl %edx, %edx
divw %r10w
movzwl %ax, %edx
leaq (%r11,%rdx), %rax
addq %rax, %rax
andl $0x1, %edx
shll $0x5, %r15d
orq %rdx, %r15
subq %r15, %rax
testb $0x1, %sil
movq %r13, %rdx
movq 0x20(%rsp), %r15
cmoveq %r15, %rdx
cmoveq %r13, %r15
movq %r8, %rcx
cmoveq %r12, %rcx
movq %r12, %rbp
cmoveq %r8, %rbp
shlq $0x5, %r14
addq %r14, %rdx
movb (%rax,%rdx), %dl
movb %dl, -0x16c2(%rdi,%rsi,4)
addq %r14, %r15
movb (%rax,%r15), %dl
movb %dl, -0x16c0(%rdi,%rsi,4)
addq %r14, %rcx
movb (%rax,%rcx), %cl
movb %cl, -0x2(%rdi,%rsi,4)
addq %rbp, %r14
movzbl (%rax,%r14), %eax
movb %al, (%rdi,%rsi,4)
andb %cl, %bl
testb $0x1, %bl
jne 0x58c6
xorl %eax, %eax
incq %rsi
movl %eax, %ebx
jmp 0x580f
movq 0x18(%rsp), %r11
incq %r11
incq %rdi
jmp 0x57fa
movq (%rsp), %r15
movq %r15, %rdi
callq 0x3812
movq %rax, %r12
movq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x3812
addq %r12, %rax
movq 0x10(%rsp), %r14
movq %rax, 0x2d80(%r14)
movq %r15, %rdi
callq 0x381a
movq %rax, %r12
movq %r13, %rdi
callq 0x381a
addq %r12, %rax
movq %rax, 0x2d88(%r14)
movq %r15, %rdi
callq 0x3822
movq %rax, %r15
movq %r13, %rdi
callq 0x3822
addq %r15, %rax
movq %rax, 0x2d90(%r14)
je 0x5966
testb $0x1, %bl
je 0x5966
leaq 0x3b2d(%rip), %rdi      # 0x9480
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21c0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop