// File: jamesgrimmett[P]orbital_determination/ex10-2_linear_least_squares.cc
// Function: main
int main() {

  int i, ii;

  // The state vector (alpha and beta)
  std::vector<double> state;
  // The inverse of the information matrix (A^T * A)^-1
  // i.e. the covariance matrix without weighting
  std::vector<std::vector<double> > inv;

  // The observed values of x  
  std::vector<double> xobs = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
  // The observed values of y (the observation matrix, b)
  std::vector<double> yobs = {1.0, 1.0, 2.0, 3.0, 3.0, 4.0, 7.0, 6.0};

  // The two components of the general solution (A^T * A, and A^T * b)
  std::vector<std::vector<double> > ata;
  std::vector<double> atb;

  // The expected values after propagation
  std::vector<double> yexp;
  // Residuals (observed - expected). 
  // Must be initialised to <= RMS for first loop 
  std::vector<double> res(xobs.size(), 0.0);
  // Absolute value of residuals. 
  std::vector<double> absres(xobs.size(), 0.0);
  // Root mean square of residuals.
  // Must be initialised  >= residuals for first loop
  double rms = 0.0;
  // Observational variance
  double obs_var;
  // Standard deviation in alpha, beta
  double stdev_a;
  double stdev_b;
 
  // Complete two iterations of the propagate and fit algorithm
  for ( i = 0; i < 2; i++ ) {
    std::cout << "\n********* Loop #" << i + 1 << " *********" <<std::endl;
    // Remove observed value with residuals outside 2*RMS
    // This will have no affect during the first iteration, if initialised 
    // RMS >= residuals.
    for ( ii = 0; ii < xobs.size(); ii++ ) {
      if (std::abs(res[ii]) > 2.0 * rms) {
        std::cout << "Dropping observation " << ii << ": (" << xobs[ii] << "," << yobs[ii] << ")" << std::endl;
        xobs.erase(xobs.begin() + ii);
        yobs.erase(yobs.begin() + ii);
        res.erase(res.begin() + ii);
        ii--;
      }
    }

    // Fill the matrices for the general solution
    tie(ata, atb) = fill_ata_atb(xobs, yobs);
    // Calculate the covariance matrix (A^T * A)*-1
    inv = inverse(ata);
    // Calculate the state vector
    state = dot_product(inv, atb);

    std::cout << "ATA matrix  " << ata[0][0] << "  " << ata[0][1] << std::endl;
    std::cout << "            " << ata[1][0] << "  " << ata[1][1] << std::endl;
    std::cout << "ATb matrix  " << atb[0] << "  " << atb[1] << std::endl; 
  
    // Propagate the x observations with the state to find the expected y values
    yexp = propagate(state, xobs);

    std::cout << "\nCalculated Y values" << std::endl;
    for ( ii = 0; ii < yexp.size(); ii++ ) {
      std::cout << yexp[ii] << " ";
    }
    std::cout << std::endl;

    // Calculate the residuals
    res = residuals(yobs, yexp);
    std::transform(res.begin(), res.end(), absres.begin(),
                         static_cast<float (*)(float)>(&std::abs));

    std::cout << "\nResidual values" << std::endl;
    for ( ii = 0; ii < res.size(); ii++ ) {
      std::cout << absres[ii] << " ";
    }
    std::cout << std::endl;

    // Calculate the RMS of the residuals
    rms = root_mean_sq(res);

    std::cout << "\nRMS: " << rms << std::endl;

    // Standard deviation in alpha and beta are taken from the covariance matrix
    stdev_a = std::sqrt(inv[0][0]);
    stdev_b = std::sqrt(inv[1][1]);

    // Without a weighting matrix, observational variance is estimated as:
    obs_var = std::sqrt(pow(rms, 2.0) * res.size() / (res.size() - 1.0)); 

    std::cout << "\nState:" << std::endl;
    std::cout << "alpha " << state[0] << " +/- " << obs_var * stdev_a << std::endl;
    std::cout << "beta  " << state[1] << " +/- " << obs_var * stdev_b << std::endl;
 
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x670, %rsp            # imm = 0x670
movl $0x0, -0x4(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x36a0
leaq -0x40(%rbp), %rdi
callq 0x36c0
movups 0x5dc5(%rip), %xmm0     # 0x7090
movaps %xmm0, -0x80(%rbp)
movups 0x5daa(%rip), %xmm0     # 0x7080
movaps %xmm0, -0x90(%rbp)
movups 0x5d8c(%rip), %xmm0     # 0x7070
movaps %xmm0, -0xa0(%rbp)
movups 0x5d6e(%rip), %xmm0     # 0x7060
movaps %xmm0, -0xb0(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x8, -0x60(%rbp)
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x408(%rbp)
callq 0x36e0
movq -0x408(%rbp), %rcx
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x3700
jmp 0x1339
leaq -0xb1(%rbp), %rdi
callq 0x3780
movups 0x5d84(%rip), %xmm0     # 0x70d0
movaps %xmm0, -0x100(%rbp)
movups 0x5d66(%rip), %xmm0     # 0x70c0
movaps %xmm0, -0x110(%rbp)
movups 0x5d48(%rip), %xmm0     # 0x70b0
movaps %xmm0, -0x120(%rbp)
movups 0x5d2a(%rip), %xmm0     # 0x70a0
movaps %xmm0, -0x130(%rbp)
leaq -0x130(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq $0x8, -0xe8(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x410(%rbp)
callq 0x36e0
movq -0x410(%rbp), %rcx
movq -0xf0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
leaq -0xe0(%rbp), %rdi
callq 0x3700
jmp 0x13cc
leaq -0x131(%rbp), %rdi
callq 0x3780
leaq -0x150(%rbp), %rdi
callq 0x36c0
leaq -0x168(%rbp), %rdi
callq 0x36a0
leaq -0x180(%rbp), %rdi
callq 0x36a0
leaq -0x58(%rbp), %rdi
callq 0x37a0
movq %rax, -0x420(%rbp)
movq $0x0, -0x1a0(%rbp)
leaq -0x1a1(%rbp), %rdi
movq %rdi, -0x418(%rbp)
callq 0x36e0
movq -0x420(%rbp), %rsi
movq -0x418(%rbp), %rcx
leaq -0x198(%rbp), %rdi
leaq -0x1a0(%rbp), %rdx
callq 0x37c0
jmp 0x144d
leaq -0x1a1(%rbp), %rdi
callq 0x3780
leaq -0x58(%rbp), %rdi
callq 0x37a0
movq %rax, -0x430(%rbp)
movq $0x0, -0x1c8(%rbp)
leaq -0x1c9(%rbp), %rdi
movq %rdi, -0x428(%rbp)
callq 0x36e0
movq -0x430(%rbp), %rsi
movq -0x428(%rbp), %rcx
leaq -0x1c0(%rbp), %rdi
leaq -0x1c8(%rbp), %rdx
callq 0x37c0
jmp 0x14aa
leaq -0x1c9(%rbp), %rdi
callq 0x3780
xorps %xmm0, %xmm0
movsd %xmm0, -0x1d8(%rbp)
movl $0x0, -0x8(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x23ee
movq 0x9aff(%rip), %rdi      # 0xafd8
leaq 0x5c00(%rip), %rsi      # 0x70e0
callq 0x10a0
movq %rax, -0x438(%rbp)
jmp 0x14ee
movq -0x438(%rbp), %rdi
movl -0x8(%rbp), %esi
incl %esi
callq 0x1120
movq %rax, -0x440(%rbp)
jmp 0x1508
movq -0x440(%rbp), %rdi
leaq 0x5bdc(%rip), %rsi      # 0x70f2
callq 0x10a0
movq %rax, -0x448(%rbp)
jmp 0x1524
movq -0x448(%rbp), %rdi
movq 0x9a96(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x1539
movl $0x0, -0xc(%rbp)
movslq -0xc(%rbp), %rax
movq %rax, -0x450(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x37a0
movq %rax, %rcx
movq -0x450(%rbp), %rax
cmpq %rcx, %rax
jae 0x18a0
movslq -0xc(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0x3860
movsd (%rax), %xmm0
callq 0x3840
movsd %xmm0, -0x458(%rbp)
jmp 0x158a
movsd -0x458(%rbp), %xmm0
movsd 0x5a6e(%rip), %xmm1     # 0x7008
mulsd -0x1d8(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1890
movq 0x9a25(%rip), %rdi      # 0xafd8
leaq 0x5b43(%rip), %rsi      # 0x70fd
callq 0x10a0
movq %rax, -0x460(%rbp)
jmp 0x15c8
movq -0x460(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x1120
movq %rax, -0x468(%rbp)
jmp 0x15e0
movq -0x468(%rbp), %rdi
leaq 0x5b25(%rip), %rsi      # 0x7113
callq 0x10a0
movq %rax, -0x470(%rbp)
jmp 0x15fc
movslq -0xc(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x3860
movq -0x470(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x1150
movq %rax, -0x478(%rbp)
jmp 0x1622
movq -0x478(%rbp), %rdi
leaq 0x5ae7(%rip), %rsi      # 0x7117
callq 0x10a0
movq %rax, -0x480(%rbp)
jmp 0x163e
movslq -0xc(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x3860
movq -0x480(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x1150
movq %rax, -0x488(%rbp)
jmp 0x1667
movq -0x488(%rbp), %rdi
leaq 0x5b43(%rip), %rsi      # 0x71b8
callq 0x10a0
movq %rax, -0x490(%rbp)
jmp 0x1683
movq -0x490(%rbp), %rdi
movq 0x9937(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x1698
leaq -0x58(%rbp), %rdi
movq %rdi, -0x4a0(%rbp)
callq 0x38f0
movq %rax, -0x208(%rbp)
movslq -0xc(%rbp), %rsi
leaq -0x208(%rbp), %rdi
callq 0x3920
movq %rax, -0x200(%rbp)
leaq -0x1f8(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0x3960
movq -0x4a0(%rbp), %rdi
movq -0x1f8(%rbp), %rsi
callq 0x3880
movq %rax, -0x498(%rbp)
jmp 0x16f5
movq -0x498(%rbp), %rax
movq %rax, -0x210(%rbp)
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x4b0(%rbp)
callq 0x38f0
movq %rax, -0x228(%rbp)
movslq -0xc(%rbp), %rsi
leaq -0x228(%rbp), %rdi
callq 0x3920
movq %rax, -0x220(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x3960
movq -0x4b0(%rbp), %rdi
movq -0x218(%rbp), %rsi
callq 0x3880
movq %rax, -0x4a8(%rbp)
jmp 0x1763
movq -0x4a8(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq -0x198(%rbp), %rdi
movq %rdi, -0x4c0(%rbp)
callq 0x38f0
movq %rax, -0x248(%rbp)
movslq -0xc(%rbp), %rsi
leaq -0x248(%rbp), %rdi
callq 0x3920
movq %rax, -0x240(%rbp)
leaq -0x238(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x3960
movq -0x4c0(%rbp), %rdi
movq -0x238(%rbp), %rsi
callq 0x3880
movq %rax, -0x4b8(%rbp)
jmp 0x17d1
movq -0x4b8(%rbp), %rax
movq %rax, -0x250(%rbp)
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1890
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0xb1(%rbp), %rdi
callq 0x3780
jmp 0x24ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x131(%rbp), %rdi
callq 0x3780
jmp 0x24a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x1a1(%rbp), %rdi
callq 0x3780
jmp 0x2475
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x1c9(%rbp), %rdi
callq 0x3780
jmp 0x2469
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x245d
jmp 0x1892
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1540
leaq -0x298(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x39a0
jmp 0x18b2
leaq -0x2b0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x39a0
jmp 0x18c7
leaq -0x280(%rbp), %rdi
leaq -0x298(%rbp), %rsi
leaq -0x2b0(%rbp), %rdx
callq 0x24d0
jmp 0x18e3
leaq -0x2c0(%rbp), %rdi
movq %rdi, -0x4d8(%rbp)
leaq -0x150(%rbp), %rsi
movq %rsi, -0x4c8(%rbp)
leaq -0x168(%rbp), %rdx
callq 0x3a90
movq -0x4d8(%rbp), %rdi
leaq -0x280(%rbp), %rsi
movq %rsi, -0x4d0(%rbp)
callq 0x3ad0
movq -0x4d0(%rbp), %rdi
callq 0x3b10
leaq -0x2b0(%rbp), %rdi
callq 0x3b30
leaq -0x298(%rbp), %rdi
callq 0x3b30
movq -0x4c8(%rbp), %rsi
leaq -0x2f0(%rbp), %rdi
callq 0x3b90
jmp 0x195e
leaq -0x2d8(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
callq 0x2aa0
jmp 0x1973
leaq -0x40(%rbp), %rdi
movq %rdi, -0x4e0(%rbp)
leaq -0x2d8(%rbp), %rsi
movq %rsi, -0x4e8(%rbp)
callq 0x3c80
movq -0x4e8(%rbp), %rdi
callq 0x3cb0
leaq -0x2f0(%rbp), %rdi
callq 0x3cb0
movq -0x4e0(%rbp), %rsi
leaq -0x320(%rbp), %rdi
callq 0x3b90
jmp 0x19be
leaq -0x338(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x39a0
jmp 0x19d3
leaq -0x308(%rbp), %rdi
leaq -0x320(%rbp), %rsi
leaq -0x338(%rbp), %rdx
callq 0x2dc0
jmp 0x19ef
leaq -0x28(%rbp), %rdi
leaq -0x308(%rbp), %rsi
movq %rsi, -0x4f8(%rbp)
callq 0x3d10
movq -0x4f8(%rbp), %rdi
callq 0x3b30
leaq -0x338(%rbp), %rdi
callq 0x3b30
leaq -0x320(%rbp), %rdi
callq 0x3cb0
movq 0x95a7(%rip), %rdi      # 0xafd8
leaq 0x56e1(%rip), %rsi      # 0x7119
callq 0x10a0
movq %rax, -0x4f0(%rbp)
jmp 0x1a46
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x508(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x3d40
movq -0x508(%rbp), %rsi
movq %rax, %rdi
callq 0x3860
movq -0x4f0(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x1150
movq %rax, -0x500(%rbp)
jmp 0x1a85
movq -0x500(%rbp), %rdi
leaq 0x569d(%rip), %rsi      # 0x7130
callq 0x10a0
movq %rax, -0x510(%rbp)
jmp 0x1aa1
xorl %eax, %eax
movl %eax, %esi
leaq -0x150(%rbp), %rdi
callq 0x3d40
movq %rax, %rdi
movl $0x1, %esi
callq 0x3860
movq -0x510(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x1150
movq %rax, -0x518(%rbp)
jmp 0x1ad7
movq -0x518(%rbp), %rdi
movq 0x94e3(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x1aec
movq 0x94e5(%rip), %rdi      # 0xafd8
leaq 0x562c(%rip), %rsi      # 0x7126
callq 0x10a0
movq %rax, -0x520(%rbp)
jmp 0x1b08
leaq -0x150(%rbp), %rdi
movl $0x1, %esi
callq 0x3d40
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3860
movq -0x520(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x1150
movq %rax, -0x528(%rbp)
jmp 0x1b3e
movq -0x528(%rbp), %rdi
leaq 0x55e4(%rip), %rsi      # 0x7130
callq 0x10a0
movq %rax, -0x530(%rbp)
jmp 0x1b5a
leaq -0x150(%rbp), %rdi
movl $0x1, %esi
movq %rsi, -0x540(%rbp)
callq 0x3d40
movq -0x540(%rbp), %rsi
movq %rax, %rdi
callq 0x3860
movq -0x530(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x1150
movq %rax, -0x538(%rbp)
jmp 0x1b9a
movq -0x538(%rbp), %rdi
movq 0x9420(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x1baf
movq 0x9422(%rip), %rdi      # 0xafd8
leaq 0x5576(%rip), %rsi      # 0x7133
callq 0x10a0
movq %rax, -0x548(%rbp)
jmp 0x1bcb
xorl %eax, %eax
movl %eax, %esi
leaq -0x168(%rbp), %rdi
callq 0x3860
movq -0x548(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x1150
movq %rax, -0x550(%rbp)
jmp 0x1bf4
movq -0x550(%rbp), %rdi
leaq 0x552e(%rip), %rsi      # 0x7130
callq 0x10a0
movq %rax, -0x558(%rbp)
jmp 0x1c10
leaq -0x168(%rbp), %rdi
movl $0x1, %esi
callq 0x3860
movq -0x558(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x1150
movq %rax, -0x560(%rbp)
jmp 0x1c3a
movq -0x560(%rbp), %rdi
movq 0x9380(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x1c4f
leaq -0x368(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x39a0
jmp 0x1c61
leaq -0x380(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x39a0
jmp 0x1c73
leaq -0x350(%rbp), %rdi
leaq -0x368(%rbp), %rsi
leaq -0x380(%rbp), %rdx
callq 0x3150
jmp 0x1c8f
leaq -0x180(%rbp), %rdi
leaq -0x350(%rbp), %rsi
movq %rsi, -0x570(%rbp)
callq 0x3d10
movq -0x570(%rbp), %rdi
callq 0x3b30
leaq -0x380(%rbp), %rdi
callq 0x3b30
leaq -0x368(%rbp), %rdi
callq 0x3b30
movq 0x9304(%rip), %rdi      # 0xafd8
leaq 0x5465(%rip), %rsi      # 0x7140
callq 0x10a0
movq %rax, -0x568(%rbp)
jmp 0x1ce9
movq -0x568(%rbp), %rdi
movq 0x92d1(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x1cfe
movl $0x0, -0xc(%rbp)
movslq -0xc(%rbp), %rax
movq %rax, -0x578(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x37a0
movq %rax, %rcx
movq -0x578(%rbp), %rax
cmpq %rcx, %rax
jae 0x1e66
movslq -0xc(%rbp), %rsi
leaq -0x180(%rbp), %rdi
callq 0x3860
movsd (%rax), %xmm0
movq 0x928e(%rip), %rdi      # 0xafd8
callq 0x1150
movq %rax, -0x580(%rbp)
jmp 0x1d58
movq -0x580(%rbp), %rdi
leaq 0x53cb(%rip), %rsi      # 0x7131
callq 0x10a0
jmp 0x1d6d
jmp 0x1d6f
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1d05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x1dac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x2b0(%rbp), %rdi
callq 0x3b30
leaq -0x298(%rbp), %rdi
callq 0x3b30
jmp 0x245d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x2f0(%rbp), %rdi
callq 0x3cb0
jmp 0x245d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x1e12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x3b30
leaq -0x320(%rbp), %rdi
callq 0x3cb0
jmp 0x245d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x1e55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x380(%rbp), %rdi
callq 0x3b30
leaq -0x368(%rbp), %rdi
callq 0x3b30
jmp 0x245d
movq 0x916b(%rip), %rdi      # 0xafd8
movq 0x9154(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x1e7b
leaq -0x3b0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x39a0
jmp 0x1e90
leaq -0x3c8(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x39a0
jmp 0x1ea5
leaq -0x398(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
leaq -0x3c8(%rbp), %rdx
callq 0x32b0
jmp 0x1ec1
leaq -0x198(%rbp), %rdi
movq %rdi, -0x590(%rbp)
leaq -0x398(%rbp), %rsi
movq %rsi, -0x598(%rbp)
callq 0x3d10
movq -0x598(%rbp), %rdi
callq 0x3b30
leaq -0x3c8(%rbp), %rdi
callq 0x3b30
leaq -0x3b0(%rbp), %rdi
callq 0x3b30
movq -0x590(%rbp), %rdi
callq 0x38f0
movq -0x590(%rbp), %rdi
movq %rax, -0x3d0(%rbp)
callq 0x3df0
movq %rax, -0x3d8(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x38f0
movq %rax, -0x3e0(%rbp)
movq -0x3d0(%rbp), %rdi
movq -0x3d8(%rbp), %rsi
movq -0x3e0(%rbp), %rdx
leaq 0x1ec5(%rip), %rcx      # 0x3e20
callq 0x3d60
movq %rax, -0x588(%rbp)
jmp 0x1f69
movq -0x588(%rbp), %rax
movq %rax, -0x3e8(%rbp)
movq 0x905a(%rip), %rdi      # 0xafd8
leaq 0x51d0(%rip), %rsi      # 0x7155
callq 0x10a0
movq %rax, -0x5a0(%rbp)
jmp 0x1f93
movq -0x5a0(%rbp), %rdi
movq 0x9027(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x1fa8
movl $0x0, -0xc(%rbp)
movslq -0xc(%rbp), %rax
movq %rax, -0x5a8(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x37a0
movq %rax, %rcx
movq -0x5a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x2067
movslq -0xc(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x3860
movsd (%rax), %xmm0
movq 0x8fe4(%rip), %rdi      # 0xafd8
callq 0x1150
movq %rax, -0x5b0(%rbp)
jmp 0x2002
movq -0x5b0(%rbp), %rdi
leaq 0x5121(%rip), %rsi      # 0x7131
callq 0x10a0
jmp 0x2017
jmp 0x2019
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1faf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x2056
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x3c8(%rbp), %rdi
callq 0x3b30
leaq -0x3b0(%rbp), %rdi
callq 0x3b30
jmp 0x245d
movq 0x8f6a(%rip), %rdi      # 0xafd8
movq 0x8f53(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x207c
leaq -0x400(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x39a0
jmp 0x2091
leaq -0x400(%rbp), %rdi
callq 0x3400
movsd %xmm0, -0x5b8(%rbp)
jmp 0x20a7
movsd -0x5b8(%rbp), %xmm0
movsd %xmm0, -0x1d8(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x3b30
movq 0x8f0e(%rip), %rdi      # 0xafd8
leaq 0x5095(%rip), %rsi      # 0x7166
callq 0x10a0
movq %rax, -0x5c0(%rbp)
jmp 0x20df
movq -0x5c0(%rbp), %rdi
movsd -0x1d8(%rbp), %xmm0
callq 0x1150
movq %rax, -0x5c8(%rbp)
jmp 0x20fc
movq -0x5c8(%rbp), %rdi
movq 0x8ebe(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x2111
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x628(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0x620(%rbp)
callq 0x3d40
movq -0x628(%rbp), %rsi
movq %rax, %rdi
callq 0x3860
movsd (%rax), %xmm0
callq 0x1080
movq -0x620(%rbp), %rdi
movsd %xmm0, -0x1e8(%rbp)
movl $0x1, %esi
movq %rsi, -0x618(%rbp)
callq 0x3d40
movq -0x618(%rbp), %rsi
movq %rax, %rdi
callq 0x3860
movsd (%rax), %xmm0
callq 0x1080
movsd %xmm0, -0x1f0(%rbp)
movsd -0x1d8(%rbp), %xmm0
movsd 0x4e74(%rip), %xmm1     # 0x7008
callq 0x1130
movsd %xmm0, -0x610(%rbp)
leaq -0x198(%rbp), %rdi
movq %rdi, -0x608(%rbp)
callq 0x37a0
movsd -0x610(%rbp), %xmm0
movq -0x608(%rbp), %rdi
movq %rax, %xmm1
movaps 0x4e51(%rip), %xmm2     # 0x7020
movaps %xmm2, -0x600(%rbp)
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x4e4e(%rip), %xmm2     # 0x7030
movaps %xmm2, -0x5f0(%rbp)
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x5d8(%rbp)
callq 0x37a0
movaps -0x600(%rbp), %xmm3
movaps -0x5f0(%rbp), %xmm2
movsd -0x5d8(%rbp), %xmm0
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
movsd 0x4dd1(%rip), %xmm2     # 0x7010
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
callq 0x1080
movsd %xmm0, -0x1e0(%rbp)
movq 0x8d7d(%rip), %rdi      # 0xafd8
leaq 0x4f0b(%rip), %rsi      # 0x716d
callq 0x10a0
movq %rax, -0x5d0(%rbp)
jmp 0x2270
movq -0x5d0(%rbp), %rdi
movq 0x8d4a(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x2285
movq 0x8d4c(%rip), %rdi      # 0xafd8
leaq 0x4ee2(%rip), %rsi      # 0x7175
callq 0x10a0
movq %rax, -0x630(%rbp)
jmp 0x22a1
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0x3860
movq -0x630(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x1150
movq %rax, -0x638(%rbp)
jmp 0x22c7
movq -0x638(%rbp), %rdi
leaq 0x4ea7(%rip), %rsi      # 0x717c
callq 0x10a0
movq %rax, -0x640(%rbp)
jmp 0x22e3
movq -0x640(%rbp), %rdi
movsd -0x1e0(%rbp), %xmm0
movsd -0x1e8(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x1150
movq %rax, -0x648(%rbp)
jmp 0x230c
movq -0x648(%rbp), %rdi
movq 0x8cae(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x2321
movq 0x8cb0(%rip), %rdi      # 0xafd8
leaq 0x4e53(%rip), %rsi      # 0x7182
callq 0x10a0
movq %rax, -0x650(%rbp)
jmp 0x233d
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x3860
movq -0x650(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x1150
movq %rax, -0x658(%rbp)
jmp 0x2364
movq -0x658(%rbp), %rdi
leaq 0x4e0a(%rip), %rsi      # 0x717c
callq 0x10a0
movq %rax, -0x660(%rbp)
jmp 0x2380
movq -0x660(%rbp), %rdi
movsd -0x1e0(%rbp), %xmm0
movsd -0x1f0(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x1150
movq %rax, -0x668(%rbp)
jmp 0x23a9
movq -0x668(%rbp), %rdi
movq 0x8c11(%rip), %rsi      # 0xafc8
callq 0x10d0
jmp 0x23be
jmp 0x23c0
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x14c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x3b30
jmp 0x245d
leaq -0x1c0(%rbp), %rdi
callq 0x3b30
leaq -0x198(%rbp), %rdi
callq 0x3b30
leaq -0x180(%rbp), %rdi
callq 0x3b30
leaq -0x168(%rbp), %rdi
callq 0x3b30
leaq -0x150(%rbp), %rdi
callq 0x3cb0
leaq -0xe0(%rbp), %rdi
callq 0x3b30
leaq -0x58(%rbp), %rdi
callq 0x3b30
leaq -0x40(%rbp), %rdi
callq 0x3cb0
leaq -0x28(%rbp), %rdi
callq 0x3b30
movl -0x4(%rbp), %eax
addq $0x670, %rsp            # imm = 0x670
popq %rbp
retq
leaq -0x1c0(%rbp), %rdi
callq 0x3b30
leaq -0x198(%rbp), %rdi
callq 0x3b30
leaq -0x180(%rbp), %rdi
callq 0x3b30
leaq -0x168(%rbp), %rdi
callq 0x3b30
leaq -0x150(%rbp), %rdi
callq 0x3cb0
leaq -0xe0(%rbp), %rdi
callq 0x3b30
leaq -0x58(%rbp), %rdi
callq 0x3b30
leaq -0x40(%rbp), %rdi
callq 0x3cb0
leaq -0x28(%rbp), %rdi
callq 0x3b30
movq -0xc0(%rbp), %rdi
callq 0x1140
nopl (%rax)