// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x126f4
movq %rax, %r13
leaq 0x18(%r14), %rdi
movq %rdi, -0x48(%rbp)
callq 0x126f4
movq %rax, -0x58(%rbp)
movslq %eax, %r15
leaq -0x30(%rbp), %r12
movq %r12, %rdi
callq 0x17bc6
leaq 0x22ef7(%rip), %rdx     # 0x3a350
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x17bd0
movq %r13, -0x50(%rbp)
movslq %r13d, %r15
leaq -0x2c(%rbp), %r12
movq %r12, %rdi
callq 0x17c2a
leaq -0x70(%rbp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x17c34
leaq -0x2c(%rbp), %rdi
callq 0x182ee
leaq -0x70(%rbp), %r13
movq %r13, %rdi
callq 0x17c8e
leaq -0x30(%rbp), %rdi
callq 0x18ab4
leaq 0x30(%r14), %rax
movq %rax, -0x40(%rbp)
xorl %eax, %eax
movl %eax, -0x30(%rbp)
cmpl -0x50(%rbp), %eax
jge 0x1784b
xorl %eax, %eax
movl %eax, -0x2c(%rbp)
cmpl -0x58(%rbp), %eax
jge 0x17841
leaq -0x30(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x17d79
movq %rax, -0x70(%rbp)
movslq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x17d9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x17daa
movq %rax, %rdi
movq %r13, %rsi
callq 0x17db8
movslq -0x30(%rbp), %rsi
movq %r14, %rdi
callq 0x537c
movq %rax, %r12
movslq -0x2c(%rbp), %rsi
movq -0x48(%rbp), %rdi
callq 0x537c
movq %r12, %rdi
movq %rax, %rsi
callq 0x17dcb
movsd %xmm0, -0x70(%rbp)
movsd %xmm1, -0x68(%rbp)
movslq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x17d9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x17daa
leaq 0x8(%rax), %rdi
movq %r13, %rsi
callq 0x17df6
movslq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x537c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %rbx, %r15
movq %rbx, %rdi
callq 0x17d9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x17daa
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x18(%rax)
movl -0x30(%rbp), %r13d
testl %r13d, %r13d
je 0x17635
movq %r14, %rdi
callq 0x126f4
decl %eax
movslq -0x30(%rbp), %r12
cmpl %eax, %r13d
jne 0x1767c
testl %r12d, %r12d
je 0x17635
movq %r14, %rdi
callq 0x126f4
decl %eax
cmpl %eax, %r12d
leaq -0x70(%rbp), %r13
movq %r15, %rbx
jne 0x176fd
movslq -0x30(%rbp), %rsi
movq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x537c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
decq %rsi
movq %r15, %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x537c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x176db
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x15754
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x537c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x537c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
jmp 0x176cf
incq %r12
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x15754
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x537c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
decq %rsi
movq %rbx, %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x537c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
mulsd 0xc311(%rip), %xmm0     # 0x239e0
movsd %xmm0, -0x38(%rbp)
leaq -0x70(%rbp), %r13
movq %r15, %rbx
movslq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x17d9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x17daa
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x20(%rax)
movl -0x2c(%rbp), %r12d
testl %r12d, %r12d
je 0x17771
movq -0x48(%rbp), %rdi
callq 0x126f4
decl %eax
cmpl %eax, %r12d
jne 0x177bc
movl -0x2c(%rbp), %r12d
testl %r12d, %r12d
je 0x17771
movq -0x48(%rbp), %rdi
callq 0x126f4
decl %eax
cmpl %eax, %r12d
jne 0x17837
movslq -0x30(%rbp), %rsi
movq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x537c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
decq %rsi
jmp 0x177a9
movslq -0x30(%rbp), %rsi
movq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
incq %rsi
movq %rax, %rdi
callq 0x537c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x537c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
jmp 0x17810
movslq -0x30(%rbp), %rsi
movq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
incq %rsi
movq %rax, %rdi
callq 0x537c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15754
movslq -0x2c(%rbp), %rsi
decq %rsi
movq %rax, %rdi
callq 0x537c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
mulsd 0xc1d0(%rip), %xmm0     # 0x239e0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x17d9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x17daa
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x28(%rax)
movl -0x2c(%rbp), %eax
incl %eax
jmp 0x174c3
movl -0x30(%rbp), %eax
incl %eax
jmp 0x174b5
xorl %r12d, %r12d
movq -0x58(%rbp), %rax
testl %eax, %eax
cmovlel %r12d, %eax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
testl %eax, %eax
cmovlel %r12d, %eax
movq %rax, -0x50(%rbp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpq %rax, %r12
je 0x179d7
leaq 0x1(%r12), %rax
movq %rax, -0x48(%rbp)
leaq -0x1(%r12), %rax
movq %rax, -0x40(%rbp)
xorl %r13d, %r13d
cmpq %r13, -0x58(%rbp)
je 0x179ca
testq %r12, %r12
je 0x1790b
movq %r14, %rdi
callq 0x126f4
addl %r15d, %eax
cmpq %rax, %r12
jne 0x17953
movq %r14, %rdi
callq 0x126f4
addl %r15d, %eax
cmpq %rax, %r12
jne 0x179c2
movq %rbx, %rdi
movq %r12, %rsi
callq 0x17d9c
movq %rax, %rdi
movq %r13, %rsi
callq 0x17daa
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
callq 0x17d9c
movq %rax, %rdi
movq %r13, %rsi
callq 0x17daa
movsd -0x38(%rbp), %xmm0
subsd 0x28(%rax), %xmm0
jmp 0x1799d
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x17d9c
movq %rax, %rdi
movq %r13, %rsi
callq 0x17daa
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x17d9c
movq %rax, %rdi
movq %r13, %rsi
callq 0x17daa
movsd -0x38(%rbp), %xmm0
subsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
xorl %esi, %esi
jmp 0x179a5
movq %rbx, %rdi
movq -0x48(%rbp), %rsi
callq 0x17d9c
movq %rax, %rdi
movq %r13, %rsi
callq 0x17daa
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
callq 0x17d9c
movq %rax, %rdi
movq %r13, %rsi
callq 0x17daa
movsd -0x38(%rbp), %xmm0
subsd 0x28(%rax), %xmm0
mulsd 0xc043(%rip), %xmm0     # 0x239e0
movsd %xmm0, -0x38(%rbp)
movq %r12, %rsi
movq %rbx, %rdi
callq 0x17d9c
movq %rax, %rdi
movq %r13, %rsi
callq 0x17daa
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x30(%rax)
incq %r13
jmp 0x1788e
movq -0x48(%rbp), %r12
movq -0x50(%rbp), %rax
jmp 0x17870
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x2c(%rbp), %rdi
callq 0x182ee
leaq -0x70(%rbp), %rdi
callq 0x17c8e
jmp 0x17a03
movq %rax, %r14
leaq -0x30(%rbp), %rdi
callq 0x18ab4
jmp 0x17a1b
jmp 0x17a10
movq %rax, %r14
movq %rbx, %rdi
callq 0x17d2a
movq %r14, %rdi
callq 0x45a0
nop