// File: 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 %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdx, -0x150(%rbp)
movq %rsi, -0x148(%rbp)
movq %rdi, -0x140(%rbp)
movq %rdi, %rax
movq %rax, -0x138(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x1, -0xda(%rbp)
leaq -0x78(%rbp), %rax
movq %rax, -0x130(%rbp)
movq %rax, -0x80(%rbp)
movq $0x0, -0xa0(%rbp)
movq $0x0, -0x98(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0x2, -0x88(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x36e0
movq -0x130(%rbp), %rdi
movq -0x128(%rbp), %rcx
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
callq 0x3700
jmp 0x2581
leaq -0x60(%rbp), %rax
movq %rax, -0x160(%rbp)
movq %rax, -0x80(%rbp)
movq $0x0, -0xd8(%rbp)
movq $0x0, -0xd0(%rbp)
leaq -0xd8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq $0x2, -0xc0(%rbp)
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x36e0
movq -0x160(%rbp), %rdi
movq -0x158(%rbp), %rcx
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0x3700
jmp 0x25f5
movb $0x0, -0xda(%rbp)
leaq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x2, -0x40(%rbp)
leaq -0xdb(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x3e40
movq -0x168(%rbp), %rcx
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x3e60
jmp 0x2639
leaq -0xdb(%rbp), %rdi
callq 0x3ee0
leaq -0x78(%rbp), %rax
movq %rax, -0x178(%rbp)
addq $0x30, %rax
movq %rax, -0x170(%rbp)
movq -0x170(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x180(%rbp)
callq 0x3b30
movq -0x178(%rbp), %rcx
movq -0x180(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x170(%rbp)
jne 0x265b
leaq -0xd9(%rbp), %rdi
callq 0x3780
leaq -0xa1(%rbp), %rdi
callq 0x3780
movq $0x0, -0x118(%rbp)
movq $0x0, -0x110(%rbp)
leaq -0x118(%rbp), %rax
movq %rax, -0x108(%rbp)
movq $0x2, -0x100(%rbp)
leaq -0x119(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x36e0
movq -0x188(%rbp), %rcx
movq -0x108(%rbp), %rsi
movq -0x100(%rbp), %rdx
leaq -0xf8(%rbp), %rdi
callq 0x3700
jmp 0x2709
leaq -0x119(%rbp), %rdi
callq 0x3780
movl $0x0, -0x1c(%rbp)
movq -0x148(%rbp), %rdi
movslq -0x1c(%rbp), %rax
movq %rax, -0x190(%rbp)
callq 0x37a0
movq %rax, %rcx
movq -0x190(%rbp), %rax
cmpq %rcx, %rax
jae 0x2a20
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3d40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3860
movq -0x148(%rbp), %rdi
movsd 0x48aa(%rip), %xmm0     # 0x7018
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movslq -0x1c(%rbp), %rsi
callq 0x3860
movsd (%rax), %xmm0
movsd %xmm0, -0x1c0(%rbp)
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3d40
movq %rax, %rdi
movl $0x1, %esi
callq 0x3860
movsd -0x1c0(%rbp), %xmm0
movq -0x148(%rbp), %rdi
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movslq -0x1c(%rbp), %rsi
callq 0x3860
movsd (%rax), %xmm0
movsd %xmm0, -0x1b8(%rbp)
leaq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x3d40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3860
movsd -0x1b8(%rbp), %xmm0
movq -0x148(%rbp), %rdi
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movslq -0x1c(%rbp), %rsi
callq 0x3860
movsd (%rax), %xmm0
movsd 0x47f1(%rip), %xmm1     # 0x7008
callq 0x1130
movsd %xmm0, -0x1b0(%rbp)
leaq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x3d40
movq %rax, %rdi
movl $0x1, %esi
callq 0x3860
movsd -0x1b0(%rbp), %xmm0
movq -0x150(%rbp), %rdi
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movslq -0x1c(%rbp), %rsi
callq 0x3860
movsd (%rax), %xmm0
movsd %xmm0, -0x1a8(%rbp)
leaq -0xf8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3860
movsd -0x1a8(%rbp), %xmm0
movq -0x148(%rbp), %rdi
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movslq -0x1c(%rbp), %rsi
callq 0x3860
movq -0x150(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x1a0(%rbp)
movslq -0x1c(%rbp), %rsi
callq 0x3860
movsd (%rax), %xmm0
movsd %xmm0, -0x198(%rbp)
leaq -0xf8(%rbp), %rdi
movl $0x1, %esi
callq 0x3860
movsd -0x1a0(%rbp), %xmm0
movsd -0x198(%rbp), %xmm2
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x271c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x29a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x2994
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xdb(%rbp), %rdi
callq 0x3ee0
leaq -0x78(%rbp), %rax
movq %rax, -0x1d0(%rbp)
addq $0x30, %rax
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x3b30
movq -0x1d0(%rbp), %rcx
movq -0x1d8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1c8(%rbp)
jne 0x2961
jmp 0x2994
leaq -0xd9(%rbp), %rdi
callq 0x3780
leaq -0xa1(%rbp), %rdi
callq 0x3780
testb $0x1, -0xda(%rbp)
jne 0x29b7
jmp 0x29fb
movq -0x80(%rbp), %rax
leaq -0x78(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x1e0(%rbp)
je 0x29f9
movq -0x1e0(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x3b30
movq -0x1e8(%rbp), %rax
leaq -0x78(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x1e0(%rbp)
jne 0x29cb
jmp 0x29fb
jmp 0x2a85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x119(%rbp), %rdi
callq 0x3780
jmp 0x2a7c
movq -0x140(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x3f00
jmp 0x2a39
leaq -0xf8(%rbp), %rdi
callq 0x3b30
leaq -0x38(%rbp), %rdi
callq 0x3cb0
movq -0x138(%rbp), %rax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x3b30
leaq -0x38(%rbp), %rdi
callq 0x3cb0
movq -0xb0(%rbp), %rdi
callq 0x1140
nopw %cs:(%rax,%rax)