// File: /workspace/github_cpp_makefile_star2_O1/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, -0x6c(%rbp)
movl %r8d, -0x70(%rbp)
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %rbx
callq 0x127b6
leaq 0x18(%rbx), %rdi
movq %rdi, -0x50(%rbp)
callq 0x127b6
leaq 0x30(%rbx), %rdi
movq %rdi, -0x58(%rbp)
callq 0x120c0
leaq 0x48(%rbx), %rdi
movq %rdi, -0x88(%rbp)
callq 0x127b6
leaq 0x60(%rbx), %rdi
movq %rdi, -0x80(%rbp)
callq 0x127b6
leaq 0x78(%rbx), %rdi
movq %rdi, -0x78(%rbp)
callq 0x127b6
movq %rbx, -0x68(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1599a
movq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x1599a
movq -0x58(%rbp), %rdi
movq %r12, %rsi
callq 0x15b00
movq -0x68(%rbp), %rdi
callq 0x12b54
movq %rax, %r13
movq -0x50(%rbp), %rdi
callq 0x12b54
movq %rax, -0x38(%rbp)
movq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x124ac
movq %rax, -0x90(%rbp)
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x15cb4
movq %rax, %rdi
callq 0x12b54
movq %rax, -0x48(%rbp)
cmpl $0x2, %r13d
movl $0x1, %ebx
cmovgel %r13d, %ebx
decl %ebx
movq -0x68(%rbp), %r15
subq $0x1, %rbx
jb 0x1a026
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 0x19fb8
movl $0x10, %edi
callq 0x41b0
movq %rax, %r14
leaq 0xaafd(%rip), %rsi      # 0x24b00
movq %rax, %rdi
callq 0x4150
movq 0x20fde(%rip), %rsi     # 0x3aff0
movq 0x20f87(%rip), %rdx     # 0x3afa0
movq %r14, %rdi
callq 0x4560
jmp 0x1a0a7
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 0x1a0a7
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 0x1a03e
movl $0x10, %edi
callq 0x41b0
movq %rax, %r14
leaq 0xaac3(%rip), %rsi      # 0x24b4c
movq %rax, %rdi
callq 0x4150
movq 0x20f58(%rip), %rsi     # 0x3aff0
movq 0x20f01(%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 0x18048
leaq -0x29(%rbp), %rdi
callq 0x5a80
movl %ebx, %eax
movq -0x90(%rbp), %r14
xorl %r14d, %eax
movl %r15d, %ecx
movq -0x48(%rbp), %rdx
xorl %edx, %ecx
orl %eax, %ecx
movq %rbx, -0x60(%rbp)
jne 0x1a195
testl %ebx, %ebx
jle 0x1a243
movq -0x38(%rbp), %rbx
movl %ebx, %eax
movq %rax, -0x48(%rbp)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, -0x60(%rbp)
andq %rax, %rbx
xorl %r15d, %r15d
leaq -0xa8(%rbp), %r12
xorl %r13d, %r13d
cmpl $0x0, -0x38(%rbp)
jle 0x1a183
xorl %r14d, %r14d
movq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x1d19c
movq %rax, %rdi
movq %r14, %rsi
callq 0x1d1be
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq (%r15,%r14), %rsi
movq %r12, %rdi
callq 0x1d1be
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
incq %r14
cmpq %r14, %rbx
jne 0x1a146
incq %r13
addq -0x48(%rbp), %r15
cmpq -0x60(%rbp), %r13
jne 0x1a13d
jmp 0x1a243
cmpl %r14d, %r15d
jne 0x1a2be
cmpl %edx, %ebx
jne 0x1a2be
cmpb $0x0, -0x70(%rbp)
je 0x1a2be
cmpb $0x0, -0x6c(%rbp)
je 0x1a1c9
movq 0x20df3(%rip), %rdi     # 0x3afb0
leaq 0xa9d4(%rip), %rsi      # 0x24b98
callq 0x4360
testl %ebx, %ebx
jle 0x1a243
movq -0x38(%rbp), %rbx
movl %ebx, %eax
movq %rax, -0x48(%rbp)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, -0x60(%rbp)
andq %rax, %rbx
xorl %r15d, %r15d
leaq -0xa8(%rbp), %r12
xorl %r13d, %r13d
cmpl $0x0, -0x38(%rbp)
jle 0x1a236
xorl %r14d, %r14d
movq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x1d19c
movq %rax, %rdi
movq %r13, %rsi
callq 0x1d1be
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq (%r15,%r14), %rsi
movq %r12, %rdi
callq 0x1d1be
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
incq %r14
cmpq %r14, %rbx
jne 0x1a1f9
incq %r13
addq -0x48(%rbp), %r15
cmpq -0x60(%rbp), %r13
jne 0x1a1f0
leaq -0x100(%rbp), %rdi
leaq -0xa8(%rbp), %r8
movq -0x68(%rbp), %rdx
movq %rdx, %rsi
movq -0x50(%rbp), %rcx
callq 0x1a3be
leaq -0xf8(%rbp), %rsi
movq -0x88(%rbp), %rdi
callq 0x1599a
leaq -0xe0(%rbp), %rsi
movq -0x80(%rbp), %rdi
callq 0x1599a
leaq -0xc8(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x1599a
leaq -0x100(%rbp), %rdi
callq 0x1d1e0
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 0x1a2ea
movq -0x48(%rbp), %rax
cmpl %eax, -0x38(%rbp)
jne 0x1a2fb
leaq 0xaa10(%rip), %rsi      # 0x24cf0
movq %r13, %rdi
callq 0x4150
jmp 0x1a30a
leaq 0xa92b(%rip), %rsi      # 0x24c1c
movq %r13, %rdi
callq 0x4150
jmp 0x1a30a
leaq 0xa984(%rip), %rsi      # 0x24c86
movq %r13, %rdi
callq 0x4150
movq 0x20cdf(%rip), %rsi     # 0x3aff0
movq 0x20c88(%rip), %rdx     # 0x3afa0
movq %r13, %rdi
callq 0x4560
jmp 0x1a324
jmp 0x1a324
movq %rax, %r12
movq %r13, %rdi
callq 0x4270
jmp 0x1a371
jmp 0x1a36e
jmp 0x1a36e
movq %rax, %r12
leaq -0x29(%rbp), %rdi
callq 0x5a80
jmp 0x1a37d
movq %rax, %r12
leaq -0x100(%rbp), %rdi
callq 0x1d1e0
jmp 0x1a371
jmp 0x1a35a
jmp 0x1a35a
jmp 0x1a35f
movq %rax, %r12
jmp 0x1a37d
movq %rax, %r12
movq %r14, %rdi
callq 0x4270
jmp 0x1a37d
jmp 0x1a36e
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 0x1048a
movq -0x50(%rbp), %rdi
callq 0x53c6
movq -0x68(%rbp), %rdi
callq 0x53c6
movq %r12, %rdi
callq 0x45a0