// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %r9d, -0x64(%rbp)
movl %r8d, -0x68(%rbp)
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %rbx
callq 0x12366
leaq 0x18(%rbx), %rdi
movq %rdi, -0x50(%rbp)
callq 0x12366
leaq 0x30(%rbx), %rdi
movq %rdi, -0x58(%rbp)
callq 0x11c9c
leaq 0x48(%rbx), %rdi
movq %rdi, -0x88(%rbp)
callq 0x12366
leaq 0x60(%rbx), %rdi
movq %rdi, -0x80(%rbp)
callq 0x12366
leaq 0x78(%rbx), %rdi
movq %rdi, -0x78(%rbp)
callq 0x12366
movq %rbx, -0x60(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x15448
movq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x15448
movq -0x58(%rbp), %rdi
movq %r12, %rsi
callq 0x155ae
movq -0x60(%rbp), %rdi
callq 0x126f4
movq %rax, -0x98(%rbp)
movl %eax, %r12d
movq -0x50(%rbp), %rdi
callq 0x126f4
movq %rax, -0x38(%rbp)
movl %eax, %ebx
movq -0x58(%rbp), %r15
movq %r15, %rdi
callq 0x12068
movq %rax, -0x90(%rbp)
xorl %r14d, %r14d
movq %r15, %rdi
xorl %esi, %esi
callq 0x15754
movq %rax, %rdi
callq 0x126f4
movq %rax, -0x70(%rbp)
cmpl $0x2, %r12d
pushq $0x1
popq %r15
movq %r12, -0x48(%rbp)
cmovgel %r12d, %r15d
decl %r15d
movq -0x60(%rbp), %r12
subq $0x1, %r15
jb 0x19982
leaq 0x1(%r14), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x537c
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x537c
movsd (%rax), %xmm0
ucomisd -0x40(%rbp), %xmm0
movq %r13, %r14
jb 0x19919
pushq $0x10
popq %rdi
callq 0x41b0
movq %rax, %r14
leaq 0xa19e(%rip), %rsi      # 0x23b00
movq %rax, %rdi
callq 0x4150
movq 0x2067f(%rip), %rsi     # 0x39ff0
movq 0x20628(%rip), %rdx     # 0x39fa0
movq %r14, %rdi
callq 0x4560
jmp 0x199fe
cmpl $0x2, %ebx
pushq $0x1
popq %r12
cmovgel %ebx, %r12d
decl %r12d
xorl %r14d, %r14d
movq -0x50(%rbp), %r15
subq $0x1, %r12
jb 0x199fe
leaq 0x1(%r14), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x537c
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x537c
movsd (%rax), %xmm0
ucomisd -0x40(%rbp), %xmm0
movq %r13, %r14
jb 0x19997
pushq $0x10
popq %rdi
callq 0x41b0
movq %rax, %r14
leaq 0xa16c(%rip), %rsi      # 0x23b4c
movq %rax, %rdi
callq 0x4150
movq 0x20601(%rip), %rsi     # 0x39ff0
movq 0x205aa(%rip), %rdx     # 0x39fa0
movq %r14, %rdi
callq 0x4560
movq -0x98(%rbp), %rax
imull -0x38(%rbp), %eax
movslq %eax, %r14
leaq -0x108(%rbp), %r12
andq $0x0, (%r12)
leaq -0x29(%rbp), %r13
movq %r13, %rdi
callq 0x531c
leaq -0xb0(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x17a40
leaq -0x29(%rbp), %rdi
callq 0x5a64
movq -0x48(%rbp), %r14
movl %r14d, %eax
movq -0x90(%rbp), %r15
xorl %r15d, %eax
movl %ebx, %ecx
movq -0x70(%rbp), %rdx
xorl %edx, %ecx
orl %eax, %ecx
jne 0x19ada
xorl %r15d, %r15d
testl %ebx, %ebx
cmovlel %r15d, %ebx
movslq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
testl %r14d, %r14d
cmovlel %r15d, %r14d
movq %r14, -0x48(%rbp)
leaq -0xb0(%rbp), %r12
xorl %r13d, %r13d
cmpq -0x48(%rbp), %r13
je 0x19b86
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x19ad1
movq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x1c960
movq %rax, %rdi
movq %r14, %rsi
callq 0x1c982
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq (%r15,%r14), %rsi
movq %r12, %rdi
callq 0x1c982
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
incq %r14
jmp 0x19a92
incq %r13
addq -0x38(%rbp), %r15
jmp 0x19a85
cmpl %r15d, %ebx
jne 0x19c01
cmpl %edx, %r14d
jne 0x19c01
cmpb $0x0, -0x68(%rbp)
je 0x19c01
cmpb $0x0, -0x64(%rbp)
je 0x19b0f
movq 0x204ad(%rip), %rdi     # 0x39fb0
leaq 0xa08e(%rip), %rsi      # 0x23b98
callq 0x4360
xorl %r15d, %r15d
testl %ebx, %ebx
cmovlel %r15d, %ebx
movslq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
testl %r14d, %r14d
cmovlel %r15d, %r14d
movq %r14, -0x48(%rbp)
leaq -0xb0(%rbp), %r12
xorl %r13d, %r13d
cmpq -0x48(%rbp), %r13
je 0x19b86
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x19b7d
movq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x1c960
movq %rax, %rdi
movq %r13, %rsi
callq 0x1c982
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq (%r15,%r14), %rsi
movq %r12, %rdi
callq 0x1c982
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
incq %r14
jmp 0x19b3e
incq %r13
addq -0x38(%rbp), %r15
jmp 0x19b35
leaq -0x108(%rbp), %rdi
leaq -0xb0(%rbp), %r8
movq -0x60(%rbp), %rdx
movq %rdx, %rsi
movq -0x50(%rbp), %rcx
callq 0x19cfc
leaq -0x100(%rbp), %rsi
movq -0x88(%rbp), %rdi
callq 0x15448
leaq -0xe8(%rbp), %rsi
movq -0x80(%rbp), %rdi
callq 0x15448
leaq -0xd0(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x15448
leaq -0x108(%rbp), %rdi
callq 0x1c9a4
leaq -0xb0(%rbp), %rdi
callq 0x53a6
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x41b0
movq %rax, %r13
cmpl %r15d, %r14d
jne 0x19c27
cmpl -0x70(%rbp), %ebx
jne 0x19c38
leaq 0xa0d3(%rip), %rsi      # 0x23cf0
movq %r13, %rdi
callq 0x4150
jmp 0x19c47
leaq 0x9fee(%rip), %rsi      # 0x23c1c
movq %r13, %rdi
callq 0x4150
jmp 0x19c47
leaq 0xa047(%rip), %rsi      # 0x23c86
movq %r13, %rdi
callq 0x4150
movq 0x203a2(%rip), %rsi     # 0x39ff0
movq 0x2034b(%rip), %rdx     # 0x39fa0
movq %r13, %rdi
callq 0x4560
jmp 0x19c61
jmp 0x19c61
movq %rax, %r12
movq %r13, %rdi
callq 0x4270
jmp 0x19cae
jmp 0x19cab
jmp 0x19cab
movq %rax, %r12
leaq -0x29(%rbp), %rdi
callq 0x5a64
jmp 0x19cba
movq %rax, %r12
leaq -0x108(%rbp), %rdi
callq 0x1c9a4
jmp 0x19cae
jmp 0x19c97
jmp 0x19c97
jmp 0x19c9c
movq %rax, %r12
jmp 0x19cba
movq %rax, %r12
movq %r14, %rdi
callq 0x4270
jmp 0x19cba
jmp 0x19cab
movq %rax, %r12
leaq -0xb0(%rbp), %rdi
callq 0x53a6
movq -0x78(%rbp), %rdi
callq 0x53a6
movq -0x80(%rbp), %rdi
callq 0x53a6
movq -0x88(%rbp), %rdi
callq 0x53a6
movq -0x58(%rbp), %rdi
callq 0x100f2
movq -0x50(%rbp), %rdi
callq 0x53a6
movq -0x60(%rbp), %rdi
callq 0x53a6
movq %r12, %rdi
callq 0x45a0
nop