// File: TBody[P]atomicpp/atomicpp/Spline/BivariateBSpline.cpp
// Function: atomicpp::BivariateBSpline::BivariateBSpline(std::vector<double, std::allocator<double>> const&, std::vector<double, std::allocator<double>> const&, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>> const&, bool, bool)
BivariateBSpline::BivariateBSpline(
  const std::vector<double>& _x_values,
  const std::vector<double>& _y_values,
  const std::vector< std::vector<double> > & _z_values,
  const bool auto_transpose /* = true */,
  const bool warn_transpose /* = true */
  ){
  x_values = _x_values;
  y_values = _y_values;
  z_values = _z_values;

  int mx = x_values.size();
  int my = y_values.size();

  int zx_length = z_values.size();
  int zy_length = z_values[0].size();

  for(int i = 0; i < mx-1; ++i){
    if (x_values[i+1] <= x_values[i]){
      throw std::runtime_error("BivariateBSpline initialization error: x_values must be strictly increasing");
    }
  }
  for(int j = 0; j < my-1; ++j){
    if (y_values[j+1] <= y_values[j]){
      throw std::runtime_error("BivariateBSpline initialization error: y_values must be strictly increasing");
    }
  }

  std::vector<double> z_flattened (mx * my, 0.0); //Allocate an empty 1D vector for a flattened (i.e. ravel) of z

  if((mx == zx_length) and (my == zy_length)){
    // Flatten z and allocate it to z_flattened
    for(int i = 0; i < mx; ++i){
      for(int j = 0; j < my; ++j){
        z_flattened.at(my*i + j) = z_values.at(i).at(j);
      }
    }
  } else if((auto_transpose) and (mx == zy_length) and (my == zx_length)){
    // Easy to supply the transpose of z_values, since row and column indices swap
    if(warn_transpose){std::cout << "BivariateBSpline initialization warning: z_values has been transposed to have the correct number of elements in x and y dimensions\n";}
    // Flatten the transpose of z and allocate it to z_flattened
    for(int i = 0; i < mx; ++i){
      for(int j = 0; j < my; ++j){
        z_flattened.at(my*i + j) = z_values.at(j).at(i);
      }
    }
  // Transpose doesn't work - throw an error
  } else if(not(mx == zx_length)){
    throw std::runtime_error("BivariateBSpline initialization error: x dimension of z_values must have the same number of elements as x");
  } else if(not(my == zy_length)){
    throw std::runtime_error("BivariateBSpline initialization error: y dimension of z_values must have the same number of elements as y");
  } else{
    throw std::runtime_error("BivariateBSpline initialization error: unhandled exception");
  }

  // __INIT__ BBSpline

  regrid_return setup_spline = regrid_smth(x_values, y_values, z_flattened);

  tx = setup_spline.tx;
  ty = setup_spline.ty;
  C = setup_spline.C;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movl %r8d, -0x134(%rbp)
movq %rcx, %rax
movl -0x134(%rbp), %ecx
movq %rax, -0x130(%rbp)
movq %rdx, %rax
movq -0x130(%rbp), %rdx
movq %rax, -0x128(%rbp)
movq %rsi, %rax
movq -0x128(%rbp), %rsi
movq %rax, -0x120(%rbp)
movq %rdi, %r8
movq -0x120(%rbp), %rdi
movb %r9b, %al
movq %r8, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
andb $0x1, %cl
movb %cl, -0x21(%rbp)
andb $0x1, %al
movb %al, -0x22(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
movq %rdi, %rax
movq %rax, -0x118(%rbp)
callq 0x1cee0
movq -0xe8(%rbp), %rdi
addq $0x18, %rdi
movq %rdi, -0x110(%rbp)
callq 0x1cee0
movq -0xe8(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x108(%rbp)
callq 0x1c240
movq -0xe8(%rbp), %rdi
addq $0x48, %rdi
movq %rdi, -0x100(%rbp)
callq 0x1cee0
movq -0xe8(%rbp), %rdi
addq $0x60, %rdi
movq %rdi, -0xf8(%rbp)
callq 0x1cee0
movq -0xe8(%rbp), %rdi
addq $0x78, %rdi
movq %rdi, -0xf0(%rbp)
callq 0x1cee0
movq -0xe8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x22380
jmp 0x29ccb
movq -0x118(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x18, %rdi
callq 0x22380
jmp 0x29ce1
movq -0x118(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x30, %rdi
callq 0x225d0
jmp 0x29cf7
movq -0x118(%rbp), %rdi
callq 0x1d4d0
movq -0x118(%rbp), %rdi
movl %eax, -0x38(%rbp)
addq $0x18, %rdi
callq 0x1d4d0
movq -0x118(%rbp), %rdi
movl %eax, -0x3c(%rbp)
addq $0x30, %rdi
callq 0x1c8b0
movq -0x118(%rbp), %rdi
movl %eax, -0x40(%rbp)
addq $0x30, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x22870
movq %rax, %rdi
callq 0x1d4d0
movl %eax, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x29e28
movq -0x118(%rbp), %rdi
movl -0x48(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x5950
movq -0x118(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x140(%rbp)
movslq -0x48(%rbp), %rsi
callq 0x5950
movsd -0x140(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x29e18
movl $0x10, %edi
callq 0x41b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x148(%rbp)
leaq 0xeebc(%rip), %rsi      # 0x38c80
callq 0x4160
jmp 0x29dcb
movq -0x148(%rbp), %rdi
movq 0x25217(%rip), %rsi     # 0x4eff0
movq 0x251c0(%rip), %rdx     # 0x4efa0
callq 0x45b0
jmp 0x2a3a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2a352
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x42b0
jmp 0x2a352
jmp 0x29e1a
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x29d52
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x29efc
movq -0x118(%rbp), %rdi
addq $0x18, %rdi
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x5950
movq -0x118(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x150(%rbp)
addq $0x18, %rdi
movslq -0x4c(%rbp), %rsi
callq 0x5950
movsd -0x150(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x29eec
movl $0x10, %edi
callq 0x41b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x158(%rbp)
leaq 0xee23(%rip), %rsi      # 0x38ccc
callq 0x4160
jmp 0x29eb0
movq -0x158(%rbp), %rdi
movq 0x25132(%rip), %rsi     # 0x4eff0
movq 0x250db(%rip), %rdx     # 0x4efa0
callq 0x45b0
jmp 0x2a3a3
movq -0x158(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x42b0
jmp 0x2a352
jmp 0x29eee
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x29e2f
movl -0x38(%rbp), %eax
movl -0x3c(%rbp), %ecx
imull %ecx, %eax
cltq
movq %rax, -0x168(%rbp)
movq $0x0, -0x70(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x58a0
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rcx
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x26390
jmp 0x29f43
leaq -0x71(%rbp), %rdi
callq 0x5930
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jne 0x2a057
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x2a057
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x2a052
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x2a042
movq -0x118(%rbp), %rdi
addq $0x30, %rdi
movslq -0x78(%rbp), %rsi
callq 0x2f3b0
movq %rax, -0x170(%rbp)
jmp 0x29fa7
movq -0x170(%rbp), %rdi
movslq -0x7c(%rbp), %rsi
callq 0x2f3f0
movq %rax, -0x178(%rbp)
jmp 0x29fc0
movq -0x178(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x188(%rbp)
movl -0x3c(%rbp), %eax
movl -0x78(%rbp), %ecx
imull %ecx, %eax
movl -0x7c(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x2f3f0
movq %rax, -0x180(%rbp)
jmp 0x29ff6
movq -0x180(%rbp), %rax
movsd -0x188(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x29f7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x5930
jmp 0x2a352
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2a349
jmp 0x2a044
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x29f6b
jmp 0x2a2a5
testb $0x1, -0x21(%rbp)
je 0x2a170
movl -0x38(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x2a170
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jne 0x2a170
testb $0x1, -0x22(%rbp)
je 0x2a096
movq 0x24f2a(%rip), %rdi     # 0x4efb0
leaq 0xec8b(%rip), %rsi      # 0x38d18
callq 0x43a0
jmp 0x2a094
jmp 0x2a096
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x2a16b
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x2a15b
movq -0x118(%rbp), %rdi
addq $0x30, %rdi
movslq -0x84(%rbp), %rsi
callq 0x2f3b0
movq %rax, -0x190(%rbp)
jmp 0x2a0e2
movq -0x190(%rbp), %rdi
movslq -0x80(%rbp), %rsi
callq 0x2f3f0
movq %rax, -0x198(%rbp)
jmp 0x2a0fb
movq -0x198(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1a8(%rbp)
movl -0x3c(%rbp), %eax
movl -0x80(%rbp), %ecx
imull %ecx, %eax
movl -0x84(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x2f3f0
movq %rax, -0x1a0(%rbp)
jmp 0x2a134
movq -0x1a0(%rbp), %rax
movsd -0x1a8(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x2a0b3
jmp 0x2a15d
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x2a09d
jmp 0x2a2a3
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
je 0x2a1d9
movl $0x10, %edi
callq 0x41b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1b0(%rbp)
leaq 0xec06(%rip), %rsi      # 0x38d9c
callq 0x4160
jmp 0x2a19d
movq -0x1b0(%rbp), %rdi
movq 0x24e45(%rip), %rsi     # 0x4eff0
movq 0x24dee(%rip), %rdx     # 0x4efa0
callq 0x45b0
jmp 0x2a3a3
movq -0x1b0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x42b0
jmp 0x2a349
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
je 0x2a242
movl $0x10, %edi
callq 0x41b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1b8(%rbp)
leaq 0xec07(%rip), %rsi      # 0x38e06
callq 0x4160
jmp 0x2a206
movq -0x1b8(%rbp), %rdi
movq 0x24ddc(%rip), %rsi     # 0x4eff0
movq 0x24d85(%rip), %rdx     # 0x4efa0
callq 0x45b0
jmp 0x2a3a3
movq -0x1b8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x42b0
jmp 0x2a349
movl $0x10, %edi
callq 0x41b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1c0(%rbp)
leaq 0xec10(%rip), %rsi      # 0x38e70
callq 0x4160
jmp 0x2a267
movq -0x1c0(%rbp), %rdi
movq 0x24d7b(%rip), %rsi     # 0x4eff0
movq 0x24d24(%rip), %rdx     # 0x4efa0
callq 0x45b0
jmp 0x2a3a3
movq -0x1c0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x42b0
jmp 0x2a349
jmp 0x2a2a5
movq -0x118(%rbp), %rdx
movq %rdx, %rcx
addq $0x18, %rcx
leaq -0xe0(%rbp), %rdi
leaq -0x68(%rbp), %r8
movq %rdx, %rsi
callq 0x2a3b0
jmp 0x2a2c8
movq -0x118(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
addq $0x48, %rdi
callq 0x22380
jmp 0x2a2e1
movq -0x118(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
addq $0x60, %rdi
callq 0x22380
jmp 0x2a2fa
movq -0x118(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
addq $0x78, %rdi
callq 0x22380
jmp 0x2a313
leaq -0xe0(%rbp), %rdi
callq 0x2f430
leaq -0x68(%rbp), %rdi
callq 0x59b0
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x2f430
leaq -0x68(%rbp), %rdi
callq 0x59b0
movq -0xf0(%rbp), %rdi
callq 0x59b0
movq -0xf8(%rbp), %rdi
callq 0x59b0
movq -0x100(%rbp), %rdi
callq 0x59b0
movq -0x108(%rbp), %rdi
callq 0x19150
movq -0x110(%rbp), %rdi
callq 0x59b0
movq -0xe8(%rbp), %rdi
callq 0x59b0
movq -0x30(%rbp), %rdi
callq 0x45e0
nopw %cs:(%rax,%rax)