// File: rishabh-battulwar[P]imageprocessing/./include/ImageProc.h
// Function: ImageProc::sobel_edge_detector(Image&, Image&, int)
void ImageProc::sobel_edge_detector(Image &img_orig, Image &img_edge_map, int percentage)
{
	Image img_Gx("bw", img_orig.cols, img_orig.rows);
	Image img_Gy("bw", img_orig.cols, img_orig.rows);
	Image img_modified("bw", img_orig.cols, img_orig.rows);
	int **sobel_opX, **sobel_opY;
	sobel_opX = new int *[3];
	sobel_opY = new int *[3];
	for(int i = 0; i < 3; i++)
	{
		sobel_opX[i] = new int[3];
		sobel_opY[i] = new int[3];
	}

	sobel_opX[0][0] = -1;	sobel_opX[0][1] = 0;	sobel_opX[0][2] = 1;
	sobel_opX[1][0] = -2;	sobel_opX[1][1] = 0;	sobel_opX[1][2] = 2;
	sobel_opX[2][0] = -1;	sobel_opX[2][1] = 0;	sobel_opX[2][2] = 1;

	sobel_opY[0][0] = -1;	sobel_opY[0][1] = -2;	sobel_opY[0][2] = -1;
	sobel_opY[1][0] = 0;	sobel_opY[1][1] = 0;	sobel_opY[1][2] = 0;
	sobel_opY[2][0] = 1;	sobel_opY[2][1] = 2;	sobel_opY[2][2] = 1;
	//int sum = 0;
	int Gx[img_orig.rows][img_orig.cols];
	int Gy[img_orig.rows][img_orig.cols];
	for(int i = 0; i < img_orig.rows; i++)
		for(int j = 0; j < img_orig.cols; j++)
		{
			Gx[i][j] = 0;
			Gy[i][j] = 0;
		}
	int minGx = std::numeric_limits<int>::max();
	int minGy = std::numeric_limits<int>::max();
	int maxGx = std::numeric_limits<int>::min();
	int maxGy = std::numeric_limits<int>::min();
	for(int i = 0; i < img_orig.rows; i++)
		for(int j = 0; j < img_orig.cols; j++)
			for(int k = 0; k < img_orig.channels; k++)
			{
				if((i-1)>=0 && (i+1)<img_orig.rows && (j-1)>=0 && (j+1)<img_orig.cols)
				{
					Gx[i][j] = func_gradient(sobel_opX, img_orig, i, j, k, 3);
					if(Gx[i][j] < minGx) minGx = Gx[i][j];
					if(Gx[i][j] > maxGx) maxGx = Gx[i][j];

					Gy[i][j] = func_gradient(sobel_opY, img_orig, i, j, k, 3);
					if(Gy[i][j] < minGy) minGy = Gy[i][j];
					if(Gy[i][j] > maxGy) maxGy = Gy[i][j];

				}

			}


	//Normalize Gradient values
	int abs_minGx = abs(minGx);
	int abs_minGy = abs(minGy);
	maxGx = maxGx + abs_minGx;
	maxGy = maxGy + abs_minGy;


	for(int i = 0; i < img_orig.rows; i++)
		for(int j = 0; j < img_orig.cols; j++)
		{
			Gx[i][j] = Gx[i][j] + abs_minGx;
			Gx[i][j] = (int)(1.0*Gx[i][j]*255/maxGx);
			Gy[i][j] = Gy[i][j] + abs_minGy;
			Gy[i][j] = (int)(1.0*Gy[i][j]*255/maxGy);
		}

	int nGradient[img_orig.rows][img_orig.cols];
	int min_nGradient = std::numeric_limits<int>::max();
	int max_nGradient = std::numeric_limits<int>::min();
	for(int i = 0; i < img_orig.rows; i++)
		for(int j = 0; j < img_orig.cols; j++)
			for(int k = 0; k < img_orig.channels; k++)
			{
				if((i-1)>=0 && (i+1)<img_orig.rows && (j-1)>=0 && (j+1)<img_orig.cols)
				{
					nGradient[i][j] = (int)sqrt(Gx[i][j]*Gx[i][j] + Gy[i][j]*Gy[i][j]);
					if(nGradient[i][j] < min_nGradient) min_nGradient = nGradient[i][j];
					if(nGradient[i][j] > max_nGradient) max_nGradient = nGradient[i][j];

					img_Gx.setvalue(i,j,k,Gx[i][j]);
					img_Gy.setvalue(i,j,k,Gy[i][j]);
				}

			}

	int abs_min_nGradient = abs(min_nGradient);
	max_nGradient = max_nGradient + abs_min_nGradient;

	for(int i = 0; i < img_orig.rows; i++)
		for(int j = 0; j < img_orig.cols; j++)
		{
			nGradient[i][j] = nGradient[i][j] + abs_min_nGradient;
			nGradient[i][j] = (int)(1.0*nGradient[i][j]*255/max_nGradient);
			img_modified.setvalue(i,j,0,nGradient[i][j]);
		}

	img_Gx.write_image("../output_images/Sobel_gradientInX.raw", img_Gx.cols, img_Gx.rows);
	img_Gy.write_image("../output_images/Sobel_gradientInY.raw", img_Gy.cols, img_Gy.rows);


	int histogram_bins[256], hist_cumulative[256];
	get_histogram(img_modified, histogram_bins);
	get_cumulative_histogram(histogram_bins, hist_cumulative);

	int threshold = (int)(((100-percentage)/100.0)*hist_cumulative[255]);

	for(int i = 0; i < 256; i++)
	{
		if(hist_cumulative[i] > threshold)
		{
			threshold = i-1;
			break;
		}
	}

	for(int i = 0; i < img_modified.rows; i++)
		for(int j = 0; j < img_modified.cols; j++)
			for(int k = 0; k < img_modified.channels; k++)
			{
				if((i-1)>=0 && (i+1)<img_modified.rows && (j-1)>=0 && (j+1)<img_modified.cols)
				{
					if(img_modified.getvalue(i,j,k) < threshold)
						img_edge_map.setvalue(i,j,k,255);
					else
						img_edge_map.setvalue(i,j,k,0);
				}
			}

	img_modified.write_image("../output_images/Sobel_gradient_map.raw", img_modified.cols, img_modified.rows);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x9b0, %rsp            # imm = 0x9B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
movl 0xc(%rax), %ecx
leaq 0xc85d(%rip), %rsi      # 0x1d5d4
movq %rsi, -0x950(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x7eb0
movq -0x950(%rbp), %rsi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
movl 0xc(%rax), %ecx
leaq -0x58(%rbp), %rdi
callq 0x7eb0
jmp 0x10da3
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
movl 0xc(%rax), %ecx
leaq 0xc820(%rip), %rsi      # 0x1d5d4
leaq -0x88(%rbp), %rdi
callq 0x7eb0
jmp 0x10dc2
movl $0x18, %edi
callq 0x2030
movq %rax, -0x958(%rbp)
jmp 0x10dd5
movq -0x958(%rbp), %rax
movq %rax, -0x90(%rbp)
movl $0x18, %edi
callq 0x2030
movq %rax, -0x960(%rbp)
jmp 0x10df6
movq -0x960(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
cmpl $0x3, -0x9c(%rbp)
jge 0x10ec3
movl $0xc, %edi
callq 0x2030
movq %rax, -0x968(%rbp)
jmp 0x10e2e
movq -0x968(%rbp), %rdx
movq -0x90(%rbp), %rax
movslq -0x9c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0xc, %edi
callq 0x2030
movq %rax, -0x970(%rbp)
jmp 0x10e5a
movq -0x970(%rbp), %rdx
movq -0x98(%rbp), %rax
movslq -0x9c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x10e0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x11d9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x11d92
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x1b2c0
jmp 0x11d92
movq -0x90(%rbp), %rax
movq (%rax), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x90(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0x4(%rax)
movq -0x90(%rbp), %rax
movq (%rax), %rax
movl $0x1, 0x8(%rax)
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x0, 0x4(%rax)
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x2, 0x8(%rax)
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rax
movl $0x0, 0x4(%rax)
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rax
movl $0x1, 0x8(%rax)
movq -0x98(%rbp), %rax
movq (%rax), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x98(%rbp), %rax
movq (%rax), %rax
movl $0xfffffffe, 0x4(%rax)  # imm = 0xFFFFFFFE
movq -0x98(%rbp), %rax
movq (%rax), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x0, (%rax)
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x0, 0x4(%rax)
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x0, 0x8(%rax)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rax
movl $0x1, (%rax)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rax
movl $0x2, 0x4(%rax)
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rax
movl $0x1, 0x8(%rax)
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %eax
movl 0xc(%rcx), %ecx
movq %rax, -0x990(%rbp)
movq %rsp, %rdx
movq %rdx, -0xa8(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x988(%rbp)
movq %rdx, %rsp
movq %rcx, -0xb0(%rbp)
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %eax
movl 0xc(%rcx), %ecx
movq %rax, -0x980(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x978(%rbp)
movq %rdx, %rsp
movq %rcx, -0xc0(%rbp)
movq %rax, -0xc8(%rbp)
movl $0x0, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x11142
movl $0x0, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x1112c
movq -0x978(%rbp), %rax
movq -0x980(%rbp), %rdx
movq -0x988(%rbp), %rcx
movq -0x990(%rbp), %rdi
movslq -0xcc(%rbp), %rsi
imulq %rdi, %rsi
shlq $0x2, %rsi
addq %rsi, %rcx
movslq -0xd0(%rbp), %rsi
movl $0x0, (%rcx,%rsi,4)
movslq -0xcc(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xd0(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x110b0
jmp 0x1112e
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x11093
callq 0x1b3a0
movl %eax, -0xd4(%rbp)
callq 0x1b3a0
movl %eax, -0xd8(%rbp)
callq 0x1b3b0
movl %eax, -0xdc(%rbp)
callq 0x1b3b0
movl %eax, -0xe0(%rbp)
movl $0x0, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x1148d
movl $0x0, -0xe8(%rbp)
movl -0xe8(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x11477
movl $0x0, -0xec(%rbp)
movl -0xec(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x11461
movl -0xe4(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jl 0x1144b
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x1144b
movl -0xe8(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jl 0x1144b
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x1144b
movq -0x90(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0xe4(%rbp), %edx
movl -0xe8(%rbp), %ecx
movl -0xec(%rbp), %r8d
movl $0x3, %r9d
callq 0x11db0
movl %eax, -0x994(%rbp)
jmp 0x11246
movq -0x988(%rbp), %rax
movq -0x990(%rbp), %rdx
movl -0x994(%rbp), %edi
movslq -0xe4(%rbp), %rsi
imulq %rdx, %rsi
shlq $0x2, %rsi
movq %rax, %rcx
addq %rsi, %rcx
movslq -0xe8(%rbp), %rsi
movl %edi, (%rcx,%rsi,4)
movslq -0xe4(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xe8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0xd4(%rbp), %eax
jge 0x112cd
movq -0x988(%rbp), %rax
movq -0x990(%rbp), %rdx
movslq -0xe4(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xe8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xd4(%rbp)
movq -0x988(%rbp), %rax
movq -0x990(%rbp), %rdx
movslq -0xe4(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xe8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0xdc(%rbp), %eax
jle 0x1132f
movq -0x988(%rbp), %rax
movq -0x990(%rbp), %rdx
movslq -0xe4(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xe8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xdc(%rbp)
movq -0x98(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0xe4(%rbp), %edx
movl -0xe8(%rbp), %ecx
movl -0xec(%rbp), %r8d
movl $0x3, %r9d
callq 0x11db0
movl %eax, -0x998(%rbp)
jmp 0x11360
movq -0x978(%rbp), %rax
movq -0x980(%rbp), %rdx
movl -0x998(%rbp), %edi
movslq -0xe4(%rbp), %rsi
imulq %rdx, %rsi
shlq $0x2, %rsi
movq %rax, %rcx
addq %rsi, %rcx
movslq -0xe8(%rbp), %rsi
movl %edi, (%rcx,%rsi,4)
movslq -0xe4(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xe8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0xd8(%rbp), %eax
jge 0x113e7
movq -0x978(%rbp), %rax
movq -0x980(%rbp), %rdx
movslq -0xe4(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xe8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xd8(%rbp)
movq -0x978(%rbp), %rax
movq -0x980(%rbp), %rdx
movslq -0xe4(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xe8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0xe0(%rbp), %eax
jle 0x11449
movq -0x978(%rbp), %rax
movq -0x980(%rbp), %rdx
movslq -0xe4(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xe8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xe0(%rbp)
jmp 0x1144b
jmp 0x1144d
movl -0xec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xec(%rbp)
jmp 0x111b2
jmp 0x11463
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0x11195
jmp 0x11479
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x11178
movl -0xd4(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0xf0(%rbp)
movl -0xd8(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0xf4(%rbp)
movl -0xdc(%rbp), %eax
addl -0xf0(%rbp), %eax
movl %eax, -0xdc(%rbp)
movl -0xe0(%rbp), %eax
addl -0xf4(%rbp), %eax
movl %eax, -0xe0(%rbp)
movl $0x0, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x116ac
movl $0x0, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x11696
movq -0x978(%rbp), %rax
movq -0x980(%rbp), %rsi
movq -0x988(%rbp), %rcx
movq -0x990(%rbp), %r8
movslq -0xf8(%rbp), %rdi
imulq %r8, %rdi
shlq $0x2, %rdi
movq %rcx, %rdx
addq %rdi, %rdx
movslq -0xfc(%rbp), %rdi
movl (%rdx,%rdi,4), %r9d
addl -0xf0(%rbp), %r9d
movslq -0xf8(%rbp), %rdi
imulq %r8, %rdi
shlq $0x2, %rdi
movq %rcx, %rdx
addq %rdi, %rdx
movslq -0xfc(%rbp), %rdi
movl %r9d, (%rdx,%rdi,4)
movslq -0xf8(%rbp), %rdi
imulq %r8, %rdi
shlq $0x2, %rdi
movq %rcx, %rdx
addq %rdi, %rdx
movslq -0xfc(%rbp), %rdi
cvtsi2sdl (%rdx,%rdi,4), %xmm1
movsd 0xaccb(%rip), %xmm0     # 0x1c268
mulsd %xmm1, %xmm0
movsd 0xaf1f(%rip), %xmm1     # 0x1c4c8
mulsd %xmm1, %xmm0
cvtsi2sdl -0xdc(%rbp), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %edi
movslq -0xf8(%rbp), %rdx
imulq %r8, %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movslq -0xfc(%rbp), %rdx
movl %edi, (%rcx,%rdx,4)
movslq -0xf8(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x2, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movslq -0xfc(%rbp), %rdx
movl (%rcx,%rdx,4), %edi
addl -0xf4(%rbp), %edi
movslq -0xf8(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x2, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movslq -0xfc(%rbp), %rdx
movl %edi, (%rcx,%rdx,4)
movslq -0xf8(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x2, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movslq -0xfc(%rbp), %rdx
cvtsi2sdl (%rcx,%rdx,4), %xmm1
movsd 0xac22(%rip), %xmm0     # 0x1c268
mulsd %xmm1, %xmm0
movsd 0xae76(%rip), %xmm1     # 0x1c4c8
mulsd %xmm1, %xmm0
cvtsi2sdl -0xe0(%rbp), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movslq -0xf8(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xfc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x114fe
jmp 0x11698
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0x114e1
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %eax
movl 0xc(%rcx), %ecx
movq %rax, -0x9a8(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x9a0(%rbp)
movq %rdx, %rsp
movq %rcx, -0x108(%rbp)
movq %rax, -0x110(%rbp)
callq 0x1b3a0
movl %eax, -0x114(%rbp)
callq 0x1b3b0
movl %eax, -0x118(%rbp)
movl $0x0, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x119c2
movl $0x0, -0x120(%rbp)
movl -0x120(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x119ac
movl $0x0, -0x124(%rbp)
movl -0x124(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x11996
movl -0x11c(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jl 0x11980
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x11980
movl -0x120(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jl 0x11980
movl -0x120(%rbp), %eax
addl $0x1, %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x11980
movq -0x978(%rbp), %rax
movq -0x980(%rbp), %rsi
movq -0x988(%rbp), %rcx
movq -0x990(%rbp), %r8
movslq -0x11c(%rbp), %rdx
movq %rdx, %rdi
imulq %r8, %rdi
leaq (%rcx,%rdi,4), %rdi
movslq -0x120(%rbp), %rcx
movl (%rdi,%rcx,4), %edi
imull %edi, %edi
imulq %rsi, %rdx
leaq (%rax,%rdx,4), %rax
movl (%rax,%rcx,4), %eax
imull %eax, %eax
addl %eax, %edi
callq 0x1b3c0
movsd %xmm0, -0x9b0(%rbp)
jmp 0x11805
movq -0x9a0(%rbp), %rax
movq -0x9a8(%rbp), %rdx
movsd -0x9b0(%rbp), %xmm0
cvttsd2si %xmm0, %edi
movslq -0x11c(%rbp), %rsi
imulq %rdx, %rsi
shlq $0x2, %rsi
movq %rax, %rcx
addq %rsi, %rcx
movslq -0x120(%rbp), %rsi
movl %edi, (%rcx,%rsi,4)
movslq -0x11c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x120(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x114(%rbp), %eax
jge 0x11892
movq -0x9a0(%rbp), %rax
movq -0x9a8(%rbp), %rdx
movslq -0x11c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x120(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x114(%rbp)
movq -0x9a0(%rbp), %rax
movq -0x9a8(%rbp), %rdx
movslq -0x11c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x120(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x118(%rbp), %eax
jle 0x118f4
movq -0x9a0(%rbp), %rax
movq -0x9a8(%rbp), %rdx
movslq -0x11c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x120(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x118(%rbp)
movq -0x988(%rbp), %rax
movq -0x990(%rbp), %r8
movl -0x11c(%rbp), %esi
movl -0x120(%rbp), %edx
movl -0x124(%rbp), %ecx
movslq -0x11c(%rbp), %rdi
imulq %r8, %rdi
shlq $0x2, %rdi
addq %rdi, %rax
movslq -0x120(%rbp), %rdi
movl (%rax,%rdi,4), %r8d
leaq -0x38(%rbp), %rdi
callq 0x83f0
movq -0x980(%rbp), %r8
movq -0x978(%rbp), %rax
movl -0x11c(%rbp), %esi
movl -0x120(%rbp), %edx
movl -0x124(%rbp), %ecx
movslq -0x11c(%rbp), %rdi
imulq %r8, %rdi
shlq $0x2, %rdi
addq %rdi, %rax
movslq -0x120(%rbp), %rdi
movl (%rax,%rdi,4), %r8d
leaq -0x58(%rbp), %rdi
callq 0x83f0
jmp 0x11982
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x11748
jmp 0x11998
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
jmp 0x1172b
jmp 0x119ae
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x1170e
movl -0x114(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x128(%rbp)
movl -0x118(%rbp), %eax
addl -0x128(%rbp), %eax
movl %eax, -0x118(%rbp)
movl $0x0, -0x12c(%rbp)
movl -0x12c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x11b3c
movl $0x0, -0x130(%rbp)
movl -0x130(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x11b26
movq -0x9a0(%rbp), %rax
movq -0x9a8(%rbp), %rdi
movslq -0x12c(%rbp), %rdx
imulq %rdi, %rdx
shlq $0x2, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movslq -0x130(%rbp), %rdx
movl (%rcx,%rdx,4), %esi
addl -0x128(%rbp), %esi
movslq -0x12c(%rbp), %rdx
imulq %rdi, %rdx
shlq $0x2, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movslq -0x130(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movslq -0x12c(%rbp), %rdx
imulq %rdi, %rdx
shlq $0x2, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movslq -0x130(%rbp), %rdx
cvtsi2sdl (%rcx,%rdx,4), %xmm1
movsd 0xa7cc(%rip), %xmm0     # 0x1c268
mulsd %xmm1, %xmm0
movsd 0xaa20(%rip), %xmm1     # 0x1c4c8
mulsd %xmm1, %xmm0
cvtsi2sdl -0x118(%rbp), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %esi
movslq -0x12c(%rbp), %rdx
imulq %rdi, %rdx
shlq $0x2, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movslq -0x130(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movl -0x12c(%rbp), %esi
movl -0x130(%rbp), %edx
movslq -0x12c(%rbp), %rcx
imulq %rdi, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x130(%rbp), %rcx
movl (%rax,%rcx,4), %r8d
leaq -0x88(%rbp), %rdi
xorl %ecx, %ecx
callq 0x83f0
movl -0x130(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x130(%rbp)
jmp 0x11a0e
jmp 0x11b28
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
jmp 0x119f1
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
leaq 0xafbc(%rip), %rsi      # 0x1cb05
leaq -0x38(%rbp), %rdi
callq 0x8150
jmp 0x11b54
movl -0x50(%rbp), %edx
movl -0x4c(%rbp), %ecx
leaq 0xafcb(%rip), %rsi      # 0x1cb2c
leaq -0x58(%rbp), %rdi
callq 0x8150
jmp 0x11b6c
leaq -0x88(%rbp), %rdi
leaq -0x530(%rbp), %rsi
callq 0x11eb0
jmp 0x11b81
leaq -0x530(%rbp), %rdi
leaq -0x930(%rbp), %rsi
callq 0x11f90
jmp 0x11b96
movl $0x64, %eax
subl -0x14(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd 0xa93e(%rip), %xmm1     # 0x1c4e8
divsd %xmm1, %xmm0
cvtsi2sdl -0x534(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x934(%rbp)
movl $0x0, -0x938(%rbp)
cmpl $0x100, -0x938(%rbp)    # imm = 0x100
jge 0x11c14
movslq -0x938(%rbp), %rax
movl -0x930(%rbp,%rax,4), %eax
cmpl -0x934(%rbp), %eax
jle 0x11c01
movl -0x938(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x934(%rbp)
jmp 0x11c14
jmp 0x11c03
movl -0x938(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x938(%rbp)
jmp 0x11bce
movl $0x0, -0x93c(%rbp)
movl -0x93c(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0x11d4a
movl $0x0, -0x940(%rbp)
movl -0x940(%rbp), %eax
cmpl -0x80(%rbp), %eax
jge 0x11d34
movl $0x0, -0x944(%rbp)
movl -0x944(%rbp), %eax
cmpl -0x78(%rbp), %eax
jge 0x11d1e
movl -0x93c(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jl 0x11d08
movl -0x93c(%rbp), %eax
addl $0x1, %eax
cmpl -0x7c(%rbp), %eax
jge 0x11d08
movl -0x940(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jl 0x11d08
movl -0x940(%rbp), %eax
addl $0x1, %eax
cmpl -0x80(%rbp), %eax
jge 0x11d08
movl -0x93c(%rbp), %esi
movl -0x940(%rbp), %edx
movl -0x944(%rbp), %ecx
leaq -0x88(%rbp), %rdi
callq 0x83b0
cmpl -0x934(%rbp), %eax
jge 0x11ce8
movq -0x10(%rbp), %rdi
movl -0x93c(%rbp), %esi
movl -0x940(%rbp), %edx
movl -0x944(%rbp), %ecx
movl $0xff, %r8d
callq 0x83f0
jmp 0x11d06
movq -0x10(%rbp), %rdi
movl -0x93c(%rbp), %esi
movl -0x940(%rbp), %edx
movl -0x944(%rbp), %ecx
xorl %r8d, %r8d
callq 0x83f0
jmp 0x11d08
jmp 0x11d0a
movl -0x944(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x944(%rbp)
jmp 0x11c50
jmp 0x11d20
movl -0x940(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x940(%rbp)
jmp 0x11c37
jmp 0x11d36
movl -0x93c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x93c(%rbp)
jmp 0x11c1e
movl -0x80(%rbp), %edx
movl -0x7c(%rbp), %ecx
leaq 0xadfc(%rip), %rsi      # 0x1cb53
leaq -0x88(%rbp), %rdi
callq 0x8150
jmp 0x11d65
movq -0xa8(%rbp), %rax
movq %rax, %rsp
leaq -0x88(%rbp), %rdi
callq 0x1b2c0
leaq -0x58(%rbp), %rdi
callq 0x1b2c0
leaq -0x38(%rbp), %rdi
callq 0x1b2c0
movq %rbp, %rsp
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x1b2c0
leaq -0x38(%rbp), %rdi
callq 0x1b2c0
movq -0x60(%rbp), %rdi
callq 0x2360
nopl (%rax)