// File: /workspace/github_cpp_makefile_star2_O3/jamesgrimmett[P]orbital_determination/ex10-2_linear_least_squares.cc
// Function: fill_ata_atb(std::vector<double, std::allocator<double>>, std::vector<double, std::allocator<double>>)
std::tuple< std::vector<std::vector<double> >, std::vector<double> > 
            fill_ata_atb(std::vector<double> xobs_, std::vector<double> yobs_) {
  int i;
  // Fill the matrix components of the general solution, as shown in Vallado
  // Exercise 10-2.

  // The two components of the general solution (A^T * A, and A^T * B)
  std::vector<std::vector<double> > ata_ = {{0.0, 0.0},{0.0, 0.0}};
  std::vector<double> atb_ = {0.0, 0.0};
  // fill ata and atb
  for ( i = 0; i < xobs_.size(); i++ ) {
    ata_[0][0] += 1.0;
    ata_[0][1] += xobs_[i];
    ata_[1][0] += xobs_[i];
    ata_[1][1] += pow(xobs_[i], 2);

    atb_[0] += yobs_[i];
    atb_[1] += xobs_[i] * yobs_[i];
  }
  return std::make_tuple(ata_, atb_);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
xorpd %xmm0, %xmm0
leaq 0x60(%rsp), %rsi
movapd %xmm0, (%rsi)
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rcx
movl $0x2, %edx
callq 0x29dc
leaq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsi)
leaq 0x6(%rsp), %rcx
movl $0x2, %edx
callq 0x29dc
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x5(%rsp), %rcx
movl $0x2, %edx
callq 0x2cb2
movl $0x30, %r12d
movq -0x10(%rsp,%r12), %rdi
testq %rdi, %rdi
je 0x23a9
movq (%rsp,%r12), %rsi
subq %rdi, %rsi
callq 0x10f0
addq $-0x18, %r12
jne 0x2393
xorpd %xmm0, %xmm0
leaq 0x60(%rsp), %rsi
movapd %xmm0, (%rsi)
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rcx
movl $0x2, %edx
callq 0x29dc
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
je 0x2479
sarq $0x3, %rcx
movq 0x38(%rsp), %rsi
movq (%rsi), %rdx
movq 0x18(%rsi), %rsi
movq (%r14), %rdi
movq 0x8(%rsp), %r8
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %r9d, %r9d
movsd 0x1c95(%rip), %xmm0     # 0x40a0
movsd (%rdx), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rdx)
movsd (%rax,%r9,8), %xmm1
addsd 0x8(%rdx), %xmm1
movsd %xmm1, 0x8(%rdx)
movsd (%rax,%r9,8), %xmm1
addsd (%rsi), %xmm1
movsd %xmm1, (%rsi)
movsd (%rax,%r9,8), %xmm1
mulsd %xmm1, %xmm1
addsd 0x8(%rsi), %xmm1
movsd %xmm1, 0x8(%rsi)
movsd (%rdi,%r9,8), %xmm1
addsd (%r8), %xmm1
movsd %xmm1, (%r8)
movsd (%rax,%r9,8), %xmm1
mulsd (%rdi,%r9,8), %xmm1
addsd 0x8(%r8), %xmm1
movsd %xmm1, 0x8(%r8)
incq %r9
cmpq %r9, %rcx
jne 0x240b
leaq 0x38(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x2e2c
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x24a2
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
leaq 0x38(%rsp), %rdi
callq 0x2c5e
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x24da
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
jmp 0x24da
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2c5e
jmp 0x252c
movq %rax, %rbx
movl $0x30, %r14d
movq -0x10(%rsp,%r14), %rdi
testq %rdi, %rdi
je 0x2505
movq (%rsp,%r14), %rsi
subq %rdi, %rsi
callq 0x10f0
addq $-0x18, %r14
jne 0x24ef
jmp 0x252c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x252c
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
jmp 0x252c
movq %rax, %rbx
movq %rbx, %rdi
callq 0x1170