// File: /workspace/github_cpp_makefile_star2_O1/ke6jjj[P]r-dat/BasicGroup.cc
// Function: BasicGroup::AddSubFrame(DDSGroup1 const&)
bool
BasicGroup::AddSubFrame(const DDSGroup1& frame)
{
  //
  // Make certain that this sub-frame belongs to this group.
  //
  if (frame.BasicGroupID() != mBasicGroupID) {
    printf("Attempt to add sub-frame to wrong basic group!\n");
    return false;
  }

  //
  // Don't dump sub-frame zero, if you ever encounter one.
  //
  if (frame.SubFrameID() == 0)
    return true;

  //
  // ECC frames get special treatment.
  //
  bool is_ecc = frame.IsECCFrame();
    
  //
  // Derive pointers into the appropriate place in out data to capture
  // this new frame.
  // 
  uint8_t *data_existing;
  bool *valid_existing;
  if (!is_ecc) {
    //
    // Normal data frame. Frames are numbered starting at 1 and are
    // about 5k in size.
    //
    size_t pos = DDSGroup1::kSize * (frame.SubFrameID() - 1);
    data_existing = &mData[pos];
    valid_existing = &mDataIsValid[pos];
  } else {
    //
    // ECC frames go into their own buffer.
    //
    data_existing = &mECCData[0];
    valid_existing = &mECCDataIsValid[0];
  }
  
  //
  // Get pointers to the frame data and validity buffer.
  //
  const DDSGroup1::DataArray& data = frame.Data();
  const DDSGroup1::ValidArray& valid = frame.Valid();
  
  //
  // Incorporate the frame's data as long as it is better than the existing
  // data.
  //
  for (size_t i = 0; i < DDSGroup1::kSize; i++) {
    if (valid[i] && !valid_existing[i]) {
      //
      // New valid data that replaces invalid data. Use it!
      //
      data_existing[i] = data[i];
      valid_existing[i] = true;
    } else if (valid[i] && valid_existing[i]) {
      //
      // We already have data at this spot. Check to make sure that the
      // update is the same.
      //
      if (data[i] != data_existing[i]) {
        //
        // Oh oh, mistmatch.
        //
        printf("Reread mismatch at Basic Group %d, SubGroup %d, offset %zd"
               ". Old/New = %02x/%02x. Keeping existing data.\n",
               frame.BasicGroupID(), frame.SubFrameID(), i, data_existing[i],
               data[i]);
      }
    } else if (!valid[i] && !valid_existing[i]) {
      //
      // Existing data is invalid and incoming data is also marked invalid,
      // but the incoming data likely has more information than the existing.
      // Sometimes entire blocks get marked invalid due to error detection
      // but a good deal of the block is actually correct. We have enough
      // storage space to represent the data invalidity yet retain the likely
      // correct data.
      //
      // Copy in the supposedly invalid data.
      //
      data_existing[i] = data[i];
      valid_existing[i] = valid[i];
    }
  }
  
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %r15
movq %rsi, %rdi
callq 0x66f0
movl (%r15), %ecx
movl %eax, 0x14(%rsp)
movl %ecx, 0x10(%rsp)
cmpl %ecx, %eax
jne 0x6c93
movq %r14, %rdi
callq 0x6708
testb %al, %al
je 0x6d78
movq %r14, %rdi
callq 0x6700
testb %al, %al
je 0x6ca4
leaq 0x3dd54(%r15), %rbx
addq $0x3f3d0, %r15          # imm = 0x3F3D0
jmp 0x6ccb
leaq 0x3e82(%rip), %rdi      # 0xab1c
callq 0x21b0
jmp 0x6d78
movq %r14, %rdi
callq 0x6708
movzbl %al, %eax
imulq $0x167c, %rax, %rax     # imm = 0x167C
leaq (%rax,%r15), %rbx
addq $-0x1678, %rbx          # imm = 0xE988
addq %rax, %r15
addq $0x1d830, %r15          # imm = 0x1D830
movq %r14, %rdi
callq 0x66e4
movq %rax, %r12
movq %r14, %rdi
callq 0x66e8
movq %rax, %r13
xorl %ebp, %ebp
movb (%r13,%rbp), %al
cmpb $0x1, %al
jne 0x6d51
cmpb $0x0, (%r15,%rbp)
je 0x6d3f
testb %al, %al
je 0x6d51
cmpb $0x1, (%r15,%rbp)
jne 0x6d4d
movb (%r12,%rbp), %al
cmpb (%rbx,%rbp), %al
je 0x6d68
movq %r14, %rdi
callq 0x66f0
movl %eax, 0xc(%rsp)
movq %r14, %rdi
callq 0x6708
movzbl %al, %edx
movzbl (%rbx,%rbp), %r8d
movzbl (%r12,%rbp), %r9d
leaq 0x3d84(%rip), %rdi      # 0xaab3
movl 0xc(%rsp), %esi
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2040
jmp 0x6d68
movb (%r12,%rbp), %al
movb %al, (%rbx,%rbp)
movb $0x1, (%r15,%rbp)
jmp 0x6d68
testb %al, %al
jne 0x6d68
cmpb $0x0, (%r15,%rbp)
jne 0x6d68
movb (%r12,%rbp), %al
movb %al, (%rbx,%rbp)
movb (%r13,%rbp), %al
movb %al, (%r15,%rbp)
incq %rbp
cmpq $0x167c, %rbp           # imm = 0x167C
jne 0x6ce3
movl 0x10(%rsp), %eax
cmpl %eax, 0x14(%rsp)
sete %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq