// File: jamesgrimmett[P]orbital_determination/ex10-2_linear_least_squares.cc
// Function: dot_product(std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>, std::vector<double, std::allocator<double>>)
std::vector<double> dot_product(std::vector<std::vector<double> > a, 
                                  std::vector<double> b) {
  // calculate the dot production of a 2x2 matrix with a 1x2 vector
                          
  std::vector<double> result(2, 0.0);
  std::vector<double> a0 = {a[0][0], a[0][1]};
  std::vector<double> a1 = {a[1][0], a[1][1]};

  result[0] = std::inner_product(a0.begin(),a0.end(),b.begin(),0.0);
  result[1] = std::inner_product(a1.begin(),a1.end(),b.begin(),0.0);

  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdx, -0x118(%rbp)
movq %rsi, -0x110(%rbp)
movq %rdi, -0x100(%rbp)
movq %rdi, %rax
movq %rax, -0x108(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movq $0x0, -0x28(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x36e0
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rcx
movl $0x2, %esi
leaq -0x28(%rbp), %rdx
callq 0x37c0
jmp 0x2e30
leaq -0x29(%rbp), %rdi
callq 0x3780
movq -0x110(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x128(%rbp)
callq 0x3d40
movq -0x128(%rbp), %rsi
movq %rax, %rdi
callq 0x3860
movq -0x110(%rbp), %rdi
movq -0x128(%rbp), %rsi
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
callq 0x3d40
movq %rax, %rdi
movl $0x1, %esi
callq 0x3860
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0x78(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x2, -0x60(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x36e0
movq -0x120(%rbp), %rcx
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x3700
jmp 0x2ecb
leaq -0x79(%rbp), %rdi
callq 0x3780
movq -0x110(%rbp), %rdi
movl $0x1, %esi
movq %rsi, -0x138(%rbp)
callq 0x3d40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3860
movq -0x110(%rbp), %rdi
movq -0x138(%rbp), %rsi
movsd (%rax), %xmm0
movsd %xmm0, -0xb8(%rbp)
callq 0x3d40
movq -0x138(%rbp), %rsi
movq %rax, %rdi
callq 0x3860
movsd (%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
leaq -0xb8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq $0x2, -0xa0(%rbp)
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x36e0
movq -0x130(%rbp), %rcx
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0x3700
jmp 0x2f81
leaq -0xb9(%rbp), %rdi
callq 0x3780
leaq -0x58(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x38f0
movq -0x148(%rbp), %rdi
movq %rax, -0xc8(%rbp)
callq 0x3df0
movq -0x118(%rbp), %rdi
movq %rax, -0xd0(%rbp)
callq 0x38f0
movq %rax, -0xd8(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
xorps %xmm0, %xmm0
callq 0x4030
movsd %xmm0, -0x140(%rbp)
jmp 0x2ff1
movq -0x100(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3860
movsd -0x140(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x98(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x38f0
movq -0x158(%rbp), %rdi
movq %rax, -0xe0(%rbp)
callq 0x3df0
movq -0x118(%rbp), %rdi
movq %rax, -0xe8(%rbp)
callq 0x38f0
movq %rax, -0xf0(%rbp)
movq -0xe0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0xf0(%rbp), %rdx
xorps %xmm0, %xmm0
callq 0x4030
movsd %xmm0, -0x150(%rbp)
jmp 0x3074
movq -0x100(%rbp), %rdi
movl $0x1, %esi
callq 0x3860
movsd -0x150(%rbp), %xmm0
movsd %xmm0, (%rax)
movb $0x1, -0x19(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3b30
leaq -0x58(%rbp), %rdi
callq 0x3b30
testb $0x1, -0x19(%rbp)
jne 0x3129
jmp 0x311d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x3780
jmp 0x3145
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x79(%rbp), %rdi
callq 0x3780
jmp 0x3139
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xb9(%rbp), %rdi
callq 0x3780
jmp 0x3112
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3b30
leaq -0x58(%rbp), %rdi
callq 0x3b30
jmp 0x3139
movq -0x100(%rbp), %rdi
callq 0x3b30
movq -0x108(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x100(%rbp), %rdi
callq 0x3b30
movq -0x38(%rbp), %rdi
callq 0x1140
nop