// File: sorazy[P]canny/canny.cpp
// Function: peak_detection(double**, HashMap*, double**, double**)
vector<Point*> peak_detection(double **mag, HashMap *h, double **x, double **y)
{
	double slope = 0;
	vector<Point*> v;
	for (int i = 1; i < height - 1; i++)
	{
		for (int j = 1; j < width - 1; j++)
		{
			// To avoid dividing by zero
			if (x[i][j] == 0)
				x[i][j] = 0.0001;

			slope = y[i][j] / x[i][j];

			// We're only looking for the peaks. If we're at a peak, store 255 in 'peaks'
			if (slope <= tan(22.5) && slope > tan(-22.5))
			{
				if (mag[i][j] > mag[i][j-1] && mag[i][j] > mag[i][j+1])
				{
					v.push_back(new Point(i, j));
					h->insert(i, j);
				}
			}
			else if (slope <= tan(67.5) && slope > tan(22.5))
			{
				if (mag[i][j] > mag[i-1][j-1] && mag[i][j] > mag[i+1][j+1])
				{
					v.push_back(new Point(i, j));
					h->insert(i, j);
				}
			}
			else if (slope <= tan(-22.5) && slope > tan(-67.5))
			{
				if (mag[i][j] > mag[i+1][j-1] && mag[i][j] > mag[i-1][j+1])
				{
					v.push_back(new Point(i, j));
					h->insert(i, j);
				}
			}
			else
			{
				if (mag[i][j] > mag[i-1][j] && mag[i][j] > mag[i+1][j])
				{
					v.push_back(new Point(i, j));
					h->insert(i, j);
				}
			}
		}
	}

	return v;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x80(%rbp)
movq %rdi, %rax
movq %rax, -0x78(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movb $0x0, -0x31(%rbp)
callq 0x4cf0
movl $0x1, -0x38(%rbp)
movl -0x38(%rbp), %eax
leaq 0x4d08(%rip), %rcx      # 0x9214
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4a7f
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
leaq 0x4cee(%rip), %rcx      # 0x9218
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4a6f
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4574
jp 0x4574
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd 0x1c19(%rip), %xmm0     # 0x6188
movsd %xmm0, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
divsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd 0x1bd8(%rip), %xmm0     # 0x6190
callq 0x20f0
movsd -0x88(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x46f4
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd 0x1bb4(%rip), %xmm0     # 0x6198
callq 0x20f0
movaps %xmm0, %xmm1
movsd -0x90(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x46f4
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x46ef
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x3c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x46ef
movl $0x8, %edi
callq 0x21f0
movq %rax, -0x98(%rbp)
jmp 0x467b
movq -0x98(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0x5630
jmp 0x468f
movq -0x80(%rbp), %rdi
movq -0x98(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x4d10
jmp 0x46a9
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0x5850
jmp 0x46ba
jmp 0x46ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4a9f
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x8, %esi
callq 0x2200
jmp 0x4a9f
jmp 0x4a5f
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd 0x1a97(%rip), %xmm0     # 0x61a0
callq 0x20f0
movsd -0xa0(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x483a
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd 0x1a5b(%rip), %xmm0     # 0x6190
callq 0x20f0
movaps %xmm0, %xmm1
movsd -0xa8(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x483a
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x4835
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x3c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x4835
movl $0x8, %edi
callq 0x21f0
movq %rax, -0xb0(%rbp)
jmp 0x47d2
movq -0xb0(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0x5630
jmp 0x47e6
movq -0x80(%rbp), %rdi
movq -0xb0(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x4d10
jmp 0x4800
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0x5850
jmp 0x4811
jmp 0x4835
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x8, %esi
callq 0x2200
jmp 0x4a9f
jmp 0x4a5d
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd 0x1949(%rip), %xmm0     # 0x6198
callq 0x20f0
movsd -0xb8(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x4980
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd 0x192d(%rip), %xmm0     # 0x61a8
callq 0x20f0
movaps %xmm0, %xmm1
movsd -0xc0(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4980
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x497b
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x3c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x497b
movl $0x8, %edi
callq 0x21f0
movq %rax, -0xc8(%rbp)
jmp 0x4918
movq -0xc8(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0x5630
jmp 0x492c
movq -0x80(%rbp), %rdi
movq -0xc8(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x68(%rbp), %rsi
callq 0x4d10
jmp 0x4946
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0x5850
jmp 0x4957
jmp 0x497b
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x8, %esi
callq 0x2200
jmp 0x4a9f
jmp 0x4a5b
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x4a59
movq -0x10(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x4a59
movl $0x8, %edi
callq 0x21f0
movq %rax, -0xd0(%rbp)
jmp 0x49f9
movq -0xd0(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0x5630
jmp 0x4a0d
movq -0x80(%rbp), %rdi
movq -0xd0(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x70(%rbp), %rsi
callq 0x4d10
jmp 0x4a27
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0x5850
jmp 0x4a38
jmp 0x4a59
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x8, %esi
callq 0x2200
jmp 0x4a9f
jmp 0x4a5b
jmp 0x4a5d
jmp 0x4a5f
jmp 0x4a61
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4520
jmp 0x4a71
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4502
movb $0x1, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
jne 0x4a92
movq -0x80(%rbp), %rdi
callq 0x3790
movq -0x78(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x3790
movq -0x50(%rbp), %rdi
callq 0x2370
nopw %cs:(%rax,%rax)