// File: /workspace/github_cpp_makefile_star2_O1/TBody[P]atomicpp/atomicpp/Spline/BicubicSpline.cpp
// Function: atomicpp::BicubicSpline::calculate_grid_coeff()
std::vector<std::vector<interp_data>> BicubicSpline::calculate_grid_coeff(){

	int Lx = x_values.size();
	int Ly = y_values.size();

	std::vector<std::vector<interp_data>>
	grid_coeff(Lx,std::vector<interp_data>(Ly,default_interp_data));

	for(int i=0; i<Lx; ++i){
		for(int j=0; j<Ly; ++j){

			grid_coeff[i][j].coord = std::make_pair(i, j);
			grid_coeff[i][j].datapoint = std::make_pair(x_values[i], y_values[j]);

			// Set the function value
			grid_coeff[i][j].f = z_values[i][j];

			// Treat as though this is a unit grid -- i.e. assume unit spacing
			if((i != 0) and (i != (int)(x_values.size()-1))){
				// Central difference for dx (2 cells)
				grid_coeff[i][j].fdx = (z_values[i+1][j] - z_values[i-1][j])/2;

			} else if (i == 0) {
				// Forward difference for dx (1 cell)
				grid_coeff[i][j].fdx = z_values[i+1][j] - z_values[i][j];

			} else if (i == (int)(x_values.size()-1)){
				// Backward difference for dx (1 cell)
				grid_coeff[i][j].fdx = z_values[i][j] - z_values[i-1][j];
			}

			if((j != 0) and (j != (int)(y_values.size()-1))){
				// Central difference for dy
				grid_coeff[i][j].fdy = (z_values[i][j+1] - z_values[i][j-1])/2;

			} else if (j == 0) {
				// Forward difference for dy
				grid_coeff[i][j].fdy = z_values[i][j+1] - z_values[i][j];

			} else if (j == (int)(y_values.size()-1)){
				// Backward difference for dy
				grid_coeff[i][j].fdy = z_values[i][j] - z_values[i][j-1];	
			}

		}
	}

	//Now that all axial derivatives have been calculated, use these results to calculate the mixed derivatives

	for(int i=0; i<Lx; ++i){
		for(int j=0; j<Ly; ++j){

			if((i != 0) and (i != (int)(x_values.size()-1))){
				// Central difference for dxy
				grid_coeff[i][j].fdxdy = (grid_coeff[i+1][j].fdy - grid_coeff[i-1][j].fdy)/2;

			} else if (i == 0) {
				// Forward difference for dxy
				grid_coeff[i][j].fdxdy = grid_coeff[i+1][j].fdy - grid_coeff[i][j].fdy;

			} else if (i == (int)(x_values.size()-1)){
				// Backward difference for dxy
				grid_coeff[i][j].fdxdy = grid_coeff[i][j].fdy - grid_coeff[i-1][j].fdy;	
			}

			// std::printf("(%d, %d) = (%f, %f) -> [%f, %f, %f, %f]\n", i, j, x_values[i], y_values[j], grid_coeff[i][j].f, grid_coeff[i][j].fdx, grid_coeff[i][j].fdy, grid_coeff[i][j].fdxdy);
		}
	}

	return grid_coeff;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x12b54
movq %rax, %r12
leaq 0x18(%r14), %rdi
movq %rdi, -0x40(%rbp)
callq 0x12b54
movq %rax, -0x48(%rbp)
movslq %eax, %r15
leaq -0x2c(%rbp), %r13
movq %r13, %rdi
callq 0x181ce
leaq 0x238fb(%rip), %rdx     # 0x3b350
leaq -0x68(%rbp), %rdi
movq %r15, %rsi
movq %r13, %rcx
callq 0x181d8
movq %r14, -0x50(%rbp)
movslq %r12d, %r15
leaq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x18232
leaq -0x68(%rbp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rcx
callq 0x1823c
leaq -0x30(%rbp), %rdi
callq 0x1891a
leaq -0x68(%rbp), %rdi
callq 0x18296
leaq -0x2c(%rbp), %r15
movq %r15, %rdi
callq 0x19112
movl $0x0, (%r15)
testl %r12d, %r12d
jle 0x17e4d
movq -0x50(%rbp), %rax
leaq 0x30(%rax), %r15
leaq -0x68(%rbp), %r14
movl $0x0, -0x30(%rbp)
cmpl $0x0, -0x48(%rbp)
jle 0x17e3c
leaq -0x2c(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x18385
movq %r12, %r13
movq %rax, -0x68(%rbp)
movslq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x183a8
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x183ba
movq %rax, %rdi
movq %r14, %rsi
callq 0x183c8
movslq -0x2c(%rbp), %rsi
movq -0x50(%rbp), %rdi
callq 0x539c
movq %rax, %r12
movslq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdi
callq 0x539c
movq %r12, %rdi
movq %rax, %rsi
callq 0x183db
movsd %xmm0, -0x68(%rbp)
movsd %xmm1, -0x60(%rbp)
movslq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x183a8
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x183ba
leaq 0x8(%rax), %rdi
movq %r14, %rsi
callq 0x18406
movslq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x183a8
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x183ba
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x18(%rax)
movl -0x2c(%rbp), %r12d
testl %r12d, %r12d
movq -0x50(%rbp), %r14
je 0x17bc0
movq %r14, %rdi
callq 0x12b54
decl %eax
cmpl %eax, %r12d
jne 0x17c0a
movl -0x2c(%rbp), %r12d
testl %r12d, %r12d
je 0x17c5c
movq %r14, %rdi
callq 0x12b54
decl %eax
cmpl %eax, %r12d
jne 0x17cc6
movslq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x2c(%rbp), %rsi
decq %rsi
jmp 0x17c82
movslq -0x2c(%rbp), %rsi
incq %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x2c(%rbp), %rsi
decq %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
mulsd 0xcd86(%rip), %xmm0     # 0x249e0
jmp 0x17c9f
movl $0x1, %esi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x183a8
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x183ba
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x20(%rax)
movl -0x30(%rbp), %r12d
testl %r12d, %r12d
je 0x17ce3
movq -0x40(%rbp), %rdi
callq 0x12b54
decl %eax
cmpl %eax, %r12d
jne 0x17d66
movl -0x30(%rbp), %r12d
testl %r12d, %r12d
je 0x17db8
movq -0x40(%rbp), %rdi
callq 0x12b54
decl %eax
cmpl %eax, %r12d
movq %r13, %r12
leaq -0x68(%rbp), %r14
jne 0x17e2b
movslq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
decq %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x183a8
jmp 0x17e15
movslq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
incq %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
decq %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
mulsd 0xcc2a(%rip), %xmm0     # 0x249e0
jmp 0x17dfd
movslq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
incq %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x2c(%rbp), %rsi
movq %r15, %rdi
callq 0x15cb4
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x183a8
movq %r13, %r12
leaq -0x68(%rbp), %r14
movslq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x183ba
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x28(%rax)
movl -0x30(%rbp), %eax
incl %eax
movl %eax, -0x30(%rbp)
cmpl -0x48(%rbp), %eax
jl 0x17ad4
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
cmpl %r12d, %eax
jl 0x17ac3
testl %r12d, %r12d
movq -0x50(%rbp), %r14
jle 0x17fe0
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %r12
movq -0x48(%rbp), %r13
andq %rax, %r13
movq %r13, -0x40(%rbp)
xorl %r15d, %r15d
movq %r12, -0x78(%rbp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x0, -0x48(%rbp)
jle 0x17fd0
leaq 0x1(%r15), %rax
movq %rax, -0x80(%rbp)
leaq -0x1(%r15), %rax
movq %rax, -0x70(%rbp)
xorl %r12d, %r12d
testq %r15, %r15
je 0x17f0a
movq %r14, %rdi
callq 0x12b54
addl %r13d, %eax
cmpq %rax, %r15
jne 0x17f54
movq %r14, %rdi
callq 0x12b54
addl %r13d, %eax
cmpq %rax, %r15
jne 0x17fc3
movq %rbx, %rdi
movq %r15, %rsi
callq 0x183a8
movq %rax, %rdi
movq %r12, %rsi
callq 0x183ba
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rbx, %rdi
movq -0x70(%rbp), %rsi
callq 0x183a8
movq %rax, %rdi
movq %r12, %rsi
callq 0x183ba
movsd -0x38(%rbp), %xmm0
subsd 0x28(%rax), %xmm0
jmp 0x17f9e
movl $0x1, %esi
movq %rbx, %rdi
callq 0x183a8
movq %rax, %rdi
movq %r12, %rsi
callq 0x183ba
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x183a8
movq %rax, %rdi
movq %r12, %rsi
callq 0x183ba
movsd -0x38(%rbp), %xmm0
subsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
xorl %esi, %esi
jmp 0x17fa6
movq %rbx, %rdi
movq -0x80(%rbp), %rsi
callq 0x183a8
movq %rax, %rdi
movq %r12, %rsi
callq 0x183ba
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rbx, %rdi
movq -0x70(%rbp), %rsi
callq 0x183a8
movq %rax, %rdi
movq %r12, %rsi
callq 0x183ba
movsd -0x38(%rbp), %xmm0
subsd 0x28(%rax), %xmm0
mulsd 0xca42(%rip), %xmm0     # 0x249e0
movsd %xmm0, -0x38(%rbp)
movq %r15, %rsi
movq %rbx, %rdi
callq 0x183a8
movq %rax, %rdi
movq %r12, %rsi
callq 0x183ba
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x30(%rax)
incq %r12
cmpq %r12, -0x40(%rbp)
jne 0x17e97
incq %r15
movq -0x78(%rbp), %r12
cmpq %r12, %r15
jne 0x17e7a
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x30(%rbp), %rdi
callq 0x1891a
leaq -0x68(%rbp), %rdi
callq 0x18296
jmp 0x1800c
movq %rax, %r14
leaq -0x2c(%rbp), %rdi
callq 0x19112
jmp 0x18024
jmp 0x18019
movq %rax, %r14
movq %rbx, %rdi
callq 0x18332
movq %r14, %rdi
callq 0x45a0