// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x70, %rsp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
xorpd %xmm0, %xmm0
leaq 0x60(%rsp), %rsi
movapd %xmm0, (%rsi)
leaq 0x8(%rsp), %r13
leaq 0x7(%rsp), %rcx
movl $0x2, %edx
movq %r13, %rdi
callq 0x2a94
leaq 0x20(%rsp), %r15
leaq 0x50(%rsp), %rsi
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsi)
leaq 0x6(%rsp), %rcx
movl $0x2, %edx
movq %r15, %rdi
callq 0x2a94
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x5(%rsp), %rcx
movl $0x2, %edx
callq 0x2cc4
movl $0x30, %r15d
movq -0x10(%rsp,%r15), %rdi
testq %rdi, %rdi
je 0x2432
movq (%rsp,%r15), %rsi
subq %rdi, %rsi
callq 0x10f0
addq $-0x18, %r15
jne 0x241c
xorpd %xmm0, %xmm0
leaq 0x60(%rsp), %rsi
movapd %xmm0, (%rsi)
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rcx
movl $0x2, %edx
callq 0x2a94
movq (%r12), %rax
movq 0x8(%r12), %rcx
subq %rax, %rcx
je 0x2504
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 0x1bea(%rip), %xmm0     # 0x4080
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 0x2496
leaq 0x38(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x2e3a
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x252d
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
leaq 0x38(%rsp), %rdi
callq 0x2c76
movq %rbx, %rax
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2567
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x10f0
jmp 0x2567
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2c76
jmp 0x25c5
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x1190
movb $0x1, %al
jmp 0x2598
movq %rax, %rbx
xorl %eax, %eax
jmp 0x2598
movq %rax, %rbx
xorl %eax, %eax
movq %r13, %r15
cmpq %r15, %r13
sete %cl
orb %al, %cl
jne 0x25c5
leaq 0x8(%rsp), %r14
movq -0x18(%r15), %rdi
testq %rdi, %rdi
je 0x25bc
movq -0x8(%r15), %rsi
subq %rdi, %rsi
callq 0x10f0
addq $-0x18, %r15
cmpq %r14, %r15
jne 0x25a7
movq %rbx, %rdi
callq 0x1170