// File: /workspace/github_cpp_makefile_star2_O3/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 0x12b22
movq %rax, %r12
movq %r14, -0x40(%rbp)
leaq 0x18(%r14), %rdi
movq %rdi, -0x48(%rbp)
callq 0x12b22
movq %rax, -0x58(%rbp)
movslq %eax, %r15
leaq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x181b0
leaq 0x23947(%rip), %rdx     # 0x3b350
leaq -0x80(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rcx
callq 0x181ba
movslq %r12d, %r15
leaq -0x2c(%rbp), %r14
movq %r14, %rdi
callq 0x18214
leaq -0x80(%rbp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rcx
callq 0x1821e
leaq -0x2c(%rbp), %rdi
callq 0x188fc
leaq -0x80(%rbp), %rdi
callq 0x18278
leaq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x190f4
movl $0x0, (%r15)
movq %r12, -0x50(%rbp)
testl %r12d, %r12d
movq -0x40(%rbp), %r12
jle 0x17fc1
leaq 0x30(%r12), %r15
xorl %eax, %eax
leaq -0x80(%rbp), %r14
movl $0x0, -0x2c(%rbp)
cmpl $0x0, -0x58(%rbp)
jle 0x17e11
leaq -0x30(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x18367
movq %rax, -0x80(%rbp)
movslq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x1838a
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x1839c
movq %rax, %rdi
movq %r14, %rsi
callq 0x183aa
movslq -0x30(%rbp), %rsi
movq %r12, %rdi
callq 0x539c
movq %rax, %r12
movslq -0x2c(%rbp), %rsi
movq -0x48(%rbp), %rdi
callq 0x539c
movq %r12, %rdi
movq %rax, %rsi
callq 0x183bd
movsd %xmm0, -0x80(%rbp)
movsd %xmm1, -0x78(%rbp)
movslq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x1838a
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x1839c
leaq 0x8(%rax), %rdi
movq %r14, %r13
movq %r14, %rsi
callq 0x183e8
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x1838a
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x1839c
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x18(%rax)
movl -0x30(%rbp), %r14d
testl %r14d, %r14d
je 0x17bed
movq -0x40(%rbp), %rdi
callq 0x12b22
decl %eax
movslq -0x30(%rbp), %r12
cmpl %eax, %r14d
jne 0x17c32
testl %r12d, %r12d
je 0x17bed
movq -0x40(%rbp), %r14
movq %r14, %rdi
callq 0x12b22
decl %eax
cmpl %eax, %r12d
movq %r14, %r12
jne 0x17cac
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
decq %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x17c8a
movl $0x1, %esi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
jmp 0x17c81
incq %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
decq %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
mulsd 0xcd5f(%rip), %xmm0     # 0x249e0
movsd %xmm0, -0x38(%rbp)
movq -0x40(%rbp), %r12
movslq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x1838a
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x1839c
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x20(%rax)
movl -0x2c(%rbp), %r14d
testl %r14d, %r14d
je 0x17d3c
movq -0x48(%rbp), %rdi
callq 0x12b22
decl %eax
cmpl %eax, %r14d
jne 0x17d83
movl -0x2c(%rbp), %r14d
testl %r14d, %r14d
je 0x17d3c
movq -0x48(%rbp), %rdi
callq 0x12b22
decl %eax
cmpl %eax, %r14d
movq %r13, %r14
jne 0x17dfd
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
decq %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x17ddb
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
incq %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
jmp 0x17dd3
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
incq %rsi
movq %rax, %rdi
callq 0x539c
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x15c9c
movslq -0x2c(%rbp), %rsi
decq %rsi
movq %rax, %rdi
callq 0x539c
movsd -0x38(%rbp), %xmm0
subsd (%rax), %xmm0
mulsd 0xcc0d(%rip), %xmm0     # 0x249e0
movsd %xmm0, -0x38(%rbp)
movq %r13, %r14
movslq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x1838a
movslq -0x2c(%rbp), %rsi
movq %rax, %rdi
callq 0x1839c
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x28(%rax)
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
cmpl -0x58(%rbp), %eax
jl 0x17a8b
movl -0x30(%rbp), %eax
incl %eax
movl %eax, -0x30(%rbp)
cmpl -0x50(%rbp), %eax
jl 0x17a7a
movq -0x50(%rbp), %rcx
testl %ecx, %ecx
jle 0x17fc1
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rcx
movq -0x58(%rbp), %r13
andq %rax, %r13
movq %r13, -0x48(%rbp)
xorl %r15d, %r15d
movq %rcx, -0x50(%rbp)
movq -0x40(%rbp), %r14
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x0, -0x58(%rbp)
jle 0x17fb2
leaq 0x1(%r15), %rax
movq %rax, -0x60(%rbp)
leaq -0x1(%r15), %rax
movq %rax, -0x68(%rbp)
xorl %r12d, %r12d
testq %r15, %r15
je 0x17edf
movq %r14, %rdi
callq 0x12b22
addl %r13d, %eax
cmpq %rax, %r15
jne 0x17f29
movq %r14, %rdi
callq 0x12b22
addl %r13d, %eax
cmpq %rax, %r15
jne 0x17f98
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1838a
movq %rax, %rdi
movq %r12, %rsi
callq 0x1839c
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rbx, %rdi
movq -0x68(%rbp), %rsi
callq 0x1838a
movq %rax, %rdi
movq %r12, %rsi
callq 0x1839c
movsd -0x38(%rbp), %xmm0
subsd 0x28(%rax), %xmm0
jmp 0x17f73
movl $0x1, %esi
movq %rbx, %rdi
callq 0x1838a
movq %rax, %rdi
movq %r12, %rsi
callq 0x1839c
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1838a
movq %rax, %rdi
movq %r12, %rsi
callq 0x1839c
movsd -0x38(%rbp), %xmm0
subsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
xorl %esi, %esi
jmp 0x17f7b
movq %rbx, %rdi
movq -0x60(%rbp), %rsi
callq 0x1838a
movq %rax, %rdi
movq %r12, %rsi
callq 0x1839c
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rbx, %rdi
movq -0x68(%rbp), %rsi
callq 0x1838a
movq %rax, %rdi
movq %r12, %rsi
callq 0x1839c
movsd -0x38(%rbp), %xmm0
subsd 0x28(%rax), %xmm0
mulsd 0xca6d(%rip), %xmm0     # 0x249e0
movsd %xmm0, -0x38(%rbp)
movq %r15, %rsi
movq %rbx, %rdi
callq 0x1838a
movq %rax, %rdi
movq %r12, %rsi
callq 0x1839c
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x30(%rax)
incq %r12
cmpq %r12, -0x48(%rbp)
jne 0x17e6c
movq -0x60(%rbp), %rax
movq %rax, %r15
movq -0x50(%rbp), %rcx
jmp 0x17fb8
incq %r15
movq %r15, %rax
cmpq %rcx, %rax
jne 0x17e4f
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x2c(%rbp), %rdi
callq 0x188fc
leaq -0x80(%rbp), %rdi
callq 0x18278
jmp 0x17fed
movq %rax, %r14
leaq -0x30(%rbp), %rdi
callq 0x190f4
jmp 0x18005
jmp 0x17ffa
movq %rax, %r14
movq %rbx, %rdi
callq 0x18314
movq %r14, %rdi
callq 0x45a0
nop