// File: /workspace/github_cpp_makefile_star2_O3/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 %rcx, %r15
movq %rdx, -0x40(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movq %rdi, -0x38(%rbp)
movq $0x0, 0x10(%rdi)
leaq 0x3b54(%rip), %rax      # 0x717c
movl (%rax), %ecx
cmpl $0x3, %ecx
jl 0x3871
movq %rsi, %r13
leaq 0x3b43(%rip), %rax      # 0x7180
movl (%rax), %eax
movl $0x1, %ebx
cmpl $0x3, %eax
jl 0x385f
movl $0x1, %r12d
movq (%r15,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm1
ucomisd 0x1b3b(%rip), %xmm1     # 0x51a0
jne 0x367f
jp 0x367f
movabsq $0x3f1a36e2eb1c432d, %rcx # imm = 0x3F1A36E2EB1C432D
movq %rcx, (%rax,%r12,8)
movsd 0x1af9(%rip), %xmm1     # 0x5178
movq -0x48(%rbp), %rax
movq (%rax,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm0
divsd %xmm1, %xmm0
movsd 0x1ae7(%rip), %xmm1     # 0x5180
ucomisd %xmm0, %xmm1
jb 0x36fe
ucomisd 0x1ae1(%rip), %xmm0     # 0x5188
jbe 0x36fe
movq (%r13,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm0
ucomisd -0x8(%rax,%r12,8), %xmm0
jbe 0x383c
ucomisd 0x8(%rax,%r12,8), %xmm0
jbe 0x383c
movl $0x8, %edi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3c50
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3acc
jmp 0x382e
movsd 0x1a8a(%rip), %xmm1     # 0x5190
ucomisd %xmm0, %xmm1
jb 0x3775
ucomisd 0x1a6c(%rip), %xmm0     # 0x5180
jbe 0x3775
movq -0x8(%r13,%rbx,8), %rax
movq (%r13,%rbx,8), %rcx
movsd (%rcx,%r12,8), %xmm0
ucomisd -0x8(%rax,%r12,8), %xmm0
jbe 0x383c
movq 0x8(%r13,%rbx,8), %rax
ucomisd 0x8(%rax,%r12,8), %xmm0
jbe 0x383c
movl $0x8, %edi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3c50
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3acc
jmp 0x382e
movsd 0x1a0b(%rip), %xmm1     # 0x5188
ucomisd %xmm0, %xmm1
movq (%r13,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm1
jb 0x37e9
ucomisd 0x1a02(%rip), %xmm0     # 0x5198
jbe 0x37e9
movq 0x8(%r13,%rbx,8), %rax
ucomisd -0x8(%rax,%r12,8), %xmm1
jbe 0x383c
movq -0x8(%r13,%rbx,8), %rax
ucomisd 0x8(%rax,%r12,8), %xmm1
jbe 0x383c
movl $0x8, %edi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3c50
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3acc
jmp 0x382e
movq -0x8(%r13,%rbx,8), %rax
ucomisd (%rax,%r12,8), %xmm1
jbe 0x383c
movq 0x8(%r13,%rbx,8), %rax
ucomisd (%rax,%r12,8), %xmm1
jbe 0x383c
movl $0x8, %edi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3c50
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3acc
movq -0x40(%rbp), %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3d5e
incq %r12
leaq 0x393a(%rip), %rax      # 0x7180
movslq (%rax), %rax
leaq -0x1(%rax), %rcx
cmpq %rcx, %r12
jl 0x3653
leaq 0x391f(%rip), %rcx      # 0x717c
movl (%rcx), %ecx
incq %rbx
leal -0x1(%rcx), %edx
movslq %edx, %rdx
cmpq %rdx, %rbx
jl 0x3644
movq -0x38(%rbp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x388e
jmp 0x388e
jmp 0x38a4
jmp 0x38a4
jmp 0x388e
movq %rax, %rbx
movl $0x8, %esi
movq %r14, %rdi
callq 0x2180
jmp 0x38a7
jmp 0x38a4
jmp 0x38a4
movq %rax, %rbx
movq -0x38(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x38bf
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2270