// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, -0x48(%rbp)
movq %rdx, -0x40(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movq %rdi, -0x38(%rbp)
movq $0x0, 0x10(%rdi)
leaq 0x3b33(%rip), %rax      # 0x7184
cmpl $0x3, (%rax)
jl 0x389b
movq %rcx, %r15
movq %rsi, %r13
movl $0x1, %ebx
leaq 0x3b1c(%rip), %rax      # 0x7188
cmpl $0x3, (%rax)
jl 0x3882
movl $0x1, %r12d
movq (%r15,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm0
ucomisd 0x1b0b(%rip), %xmm0     # 0x5198
jne 0x369f
jp 0x369f
movabsq $0x3f1a36e2eb1c432d, %rcx # imm = 0x3F1A36E2EB1C432D
movq %rcx, (%rax,%r12,8)
movq -0x48(%rbp), %rcx
movq (%rcx,%rbx,8), %rcx
movsd (%rcx,%r12,8), %xmm0
divsd (%rax,%r12,8), %xmm0
movsd 0x1abd(%rip), %xmm1     # 0x5178
ucomisd %xmm0, %xmm1
jb 0x3720
ucomisd 0x1ab7(%rip), %xmm0     # 0x5180
jbe 0x3720
movq (%r13,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm0
ucomisd -0x8(%rax,%r12,8), %xmm0
jbe 0x3869
ucomisd 0x8(%rax,%r12,8), %xmm0
jbe 0x3869
movl $0x8, %edi
callq 0x2180
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3c80
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3b06
jmp 0x385b
movsd 0x1a60(%rip), %xmm1     # 0x5188
ucomisd %xmm0, %xmm1
jb 0x3797
ucomisd 0x1a42(%rip), %xmm0     # 0x5178
jbe 0x3797
movq -0x8(%r13,%rbx,8), %rax
movq (%r13,%rbx,8), %rcx
movsd (%rcx,%r12,8), %xmm0
ucomisd -0x8(%rax,%r12,8), %xmm0
jbe 0x3869
movq 0x8(%r13,%rbx,8), %rax
ucomisd 0x8(%rax,%r12,8), %xmm0
jbe 0x3869
movl $0x8, %edi
callq 0x2180
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3c80
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3b06
jmp 0x385b
movsd 0x19e1(%rip), %xmm1     # 0x5180
ucomisd %xmm0, %xmm1
jb 0x380b
ucomisd 0x19e3(%rip), %xmm0     # 0x5190
jbe 0x380b
movq (%r13,%rbx,8), %rax
movq 0x8(%r13,%rbx,8), %rcx
movsd (%rax,%r12,8), %xmm0
ucomisd -0x8(%rcx,%r12,8), %xmm0
jbe 0x3869
movq -0x8(%r13,%rbx,8), %rax
ucomisd 0x8(%rax,%r12,8), %xmm0
jbe 0x3869
movl $0x8, %edi
callq 0x2180
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3c80
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3b06
jmp 0x385b
movq -0x8(%r13,%rbx,8), %rax
movq (%r13,%rbx,8), %rcx
movsd (%rcx,%r12,8), %xmm0
ucomisd (%rax,%r12,8), %xmm0
jbe 0x3869
movq 0x8(%r13,%rbx,8), %rax
ucomisd (%rax,%r12,8), %xmm0
jbe 0x3869
movl $0x8, %edi
callq 0x2180
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3c80
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3b06
movq -0x40(%rbp), %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3d90
incq %r12
leaq 0x3915(%rip), %rax      # 0x7188
movslq (%rax), %rax
decq %rax
cmpq %rax, %r12
jl 0x367b
incq %rbx
leaq 0x38f8(%rip), %rax      # 0x7184
movslq (%rax), %rax
decq %rax
cmpq %rax, %rbx
jl 0x3665
movq -0x38(%rbp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x38b8
jmp 0x38b8
jmp 0x38ce
jmp 0x38ce
jmp 0x38b8
movq %rax, %rbx
movl $0x8, %esi
movq %r14, %rdi
callq 0x2190
jmp 0x38d1
jmp 0x38ce
jmp 0x38ce
movq %rax, %rbx
movq -0x38(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x38e9
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x2280