// File: /workspace/github_cpp_makefile_star2_O3/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 $0xd8, %rsp
movl %r9d, -0x64(%rbp)
movl %r8d, -0x68(%rbp)
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %rbx
callq 0x12776
leaq 0x18(%rbx), %rdi
movq %rdi, -0x50(%rbp)
callq 0x12776
leaq 0x30(%rbx), %rdi
movq %rdi, -0x58(%rbp)
callq 0x12072
leaq 0x48(%rbx), %rdi
movq %rdi, -0x88(%rbp)
callq 0x12776
leaq 0x60(%rbx), %rdi
movq %rdi, -0x80(%rbp)
callq 0x12776
leaq 0x78(%rbx), %rdi
movq %rdi, -0x78(%rbp)
callq 0x12776
movq %rbx, -0x60(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x15982
movq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x15982
movq -0x58(%rbp), %rdi
movq %r12, %rsi
callq 0x15ae8
movq -0x60(%rbp), %rdi
callq 0x12b22
movq %rax, %r13
movq -0x50(%rbp), %rdi
callq 0x12b22
movq %rax, -0x38(%rbp)
movq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x1246c
movq %rax, -0x90(%rbp)
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x15c9c
movq %rax, %rdi
callq 0x12b22
movq %rax, -0x70(%rbp)
cmpl $0x2, %r13d
movl $0x1, %ebx
cmovgel %r13d, %ebx
decl %ebx
movq -0x60(%rbp), %r15
subq $0x1, %rbx
jb 0x1a012
leaq 0x1(%r14), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x539c
movsd (%rax), %xmm0
ucomisd -0x40(%rbp), %xmm0
movq %r12, %r14
jb 0x19fa4
movl $0x10, %edi
callq 0x41b0
movq %rax, %r14
leaq 0xab11(%rip), %rsi      # 0x24b00
movq %rax, %rdi
callq 0x4150
movq 0x20ff2(%rip), %rsi     # 0x3aff0
movq 0x20f9b(%rip), %rdx     # 0x3afa0
movq %r14, %rdi
callq 0x4560
jmp 0x1a093
movq -0x38(%rbp), %rax
cmpl $0x2, %eax
movl $0x1, %ebx
cmovgel %eax, %ebx
decl %ebx
xorl %r14d, %r14d
movq -0x50(%rbp), %r15
subq $0x1, %rbx
jb 0x1a093
leaq 0x1(%r14), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x539c
movsd (%rax), %xmm0
ucomisd -0x40(%rbp), %xmm0
movq %r12, %r14
jb 0x1a02a
movl $0x10, %edi
callq 0x41b0
movq %rax, %r14
leaq 0xaad7(%rip), %rsi      # 0x24b4c
movq %rax, %rdi
callq 0x4150
movq 0x20f6c(%rip), %rsi     # 0x3aff0
movq 0x20f15(%rip), %rdx     # 0x3afa0
movq %r14, %rdi
callq 0x4560
movl %r13d, %eax
movq -0x38(%rbp), %r15
imull %r15d, %eax
movslq %eax, %r14
leaq -0x100(%rbp), %r12
movq $0x0, (%r12)
movq %r13, %rbx
leaq -0x29(%rbp), %r13
movq %r13, %rdi
callq 0x533c
leaq -0xa8(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1802a
leaq -0x29(%rbp), %rdi
callq 0x5a80
movl %ebx, %eax
movq -0x90(%rbp), %r14
xorl %r14d, %eax
movl %r15d, %ecx
movq -0x70(%rbp), %rdx
xorl %edx, %ecx
orl %eax, %ecx
movq %rbx, -0x48(%rbp)
jne 0x1a176
testl %ebx, %ebx
jle 0x1a21d
movl -0x38(%rbp), %ebx
movq -0x48(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x48(%rbp)
xorl %r15d, %r15d
leaq -0xa8(%rbp), %r12
xorl %r13d, %r13d
cmpl $0x0, -0x38(%rbp)
jle 0x1a165
xorl %r14d, %r14d
movq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x1d0e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x1d102
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq (%r15,%r14), %rsi
movq %r12, %rdi
callq 0x1d102
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
incq %r14
cmpq %r14, %rbx
jne 0x1a128
incq %r13
addq %rbx, %r15
cmpq -0x48(%rbp), %r13
jne 0x1a11f
jmp 0x1a21d
cmpl %r14d, %r15d
jne 0x1a298
cmpl %edx, %ebx
jne 0x1a298
cmpb $0x0, -0x68(%rbp)
je 0x1a298
cmpb $0x0, -0x64(%rbp)
je 0x1a1aa
movq 0x20e12(%rip), %rdi     # 0x3afb0
leaq 0xa9f3(%rip), %rsi      # 0x24b98
callq 0x4360
testl %ebx, %ebx
jle 0x1a21d
movl -0x38(%rbp), %ebx
movq -0x48(%rbp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x48(%rbp)
xorl %r15d, %r15d
leaq -0xa8(%rbp), %r12
xorl %r13d, %r13d
cmpl $0x0, -0x38(%rbp)
jle 0x1a211
xorl %r14d, %r14d
movq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x1d0e0
movq %rax, %rdi
movq %r13, %rsi
callq 0x1d102
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq (%r15,%r14), %rsi
movq %r12, %rdi
callq 0x1d102
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
incq %r14
cmpq %r14, %rbx
jne 0x1a1d4
incq %r13
addq %rbx, %r15
cmpq -0x48(%rbp), %r13
jne 0x1a1cb
leaq -0x100(%rbp), %rdi
leaq -0xa8(%rbp), %r8
movq -0x60(%rbp), %rdx
movq %rdx, %rsi
movq -0x50(%rbp), %rcx
callq 0x1a398
leaq -0xf8(%rbp), %rsi
movq -0x88(%rbp), %rdi
callq 0x15982
leaq -0xe0(%rbp), %rsi
movq -0x80(%rbp), %rdi
callq 0x15982
leaq -0xc8(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x15982
leaq -0x100(%rbp), %rdi
callq 0x1d124
leaq -0xa8(%rbp), %rdi
callq 0x53c6
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x41b0
movq %rax, %r13
cmpl %r14d, %ebx
jne 0x1a2c4
movq -0x70(%rbp), %rax
cmpl %eax, -0x38(%rbp)
jne 0x1a2d5
leaq 0xaa36(%rip), %rsi      # 0x24cf0
movq %r13, %rdi
callq 0x4150
jmp 0x1a2e4
leaq 0xa951(%rip), %rsi      # 0x24c1c
movq %r13, %rdi
callq 0x4150
jmp 0x1a2e4
leaq 0xa9aa(%rip), %rsi      # 0x24c86
movq %r13, %rdi
callq 0x4150
movq 0x20d05(%rip), %rsi     # 0x3aff0
movq 0x20cae(%rip), %rdx     # 0x3afa0
movq %r13, %rdi
callq 0x4560
jmp 0x1a2fe
jmp 0x1a2fe
movq %rax, %r12
movq %r13, %rdi
callq 0x4270
jmp 0x1a34b
jmp 0x1a348
jmp 0x1a348
movq %rax, %r12
leaq -0x29(%rbp), %rdi
callq 0x5a80
jmp 0x1a357
movq %rax, %r12
leaq -0x100(%rbp), %rdi
callq 0x1d124
jmp 0x1a34b
jmp 0x1a334
jmp 0x1a334
jmp 0x1a339
movq %rax, %r12
jmp 0x1a357
movq %rax, %r12
movq %r14, %rdi
callq 0x4270
jmp 0x1a357
jmp 0x1a348
movq %rax, %r12
leaq -0xa8(%rbp), %rdi
callq 0x53c6
movq -0x78(%rbp), %rdi
callq 0x53c6
movq -0x80(%rbp), %rdi
callq 0x53c6
movq -0x88(%rbp), %rdi
callq 0x53c6
movq -0x58(%rbp), %rdi
callq 0x10424
movq -0x50(%rbp), %rdi
callq 0x53c6
movq -0x60(%rbp), %rdi
callq 0x53c6
movq %r12, %rdi
callq 0x45a0