// File: /workspace/github_cpp_makefile_star2_O2/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)
movq %rsi, %r13
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movq %rdi, -0x38(%rbp)
andq $0x0, 0x10(%rdi)
pushq $0x1
popq %rbx
leaq 0x2f3a(%rip), %rax      # 0x6174
movslq (%rax), %rax
decq %rax
cmpq %rax, %rbx
jge 0x3450
pushq $0x1
popq %r12
leaq 0x2f24(%rip), %rax      # 0x6178
movslq (%rax), %rax
decq %rax
cmpq %rax, %r12
jge 0x3448
movq (%r15,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm1
ucomisd 0xf2b(%rip), %xmm1      # 0x41a0
jne 0x328f
jp 0x328f
movabsq $0x3f1a36e2eb1c432d, %rcx # imm = 0x3F1A36E2EB1C432D
movq %rcx, (%rax,%r12,8)
movsd 0xee9(%rip), %xmm1      # 0x4178
movq -0x48(%rbp), %rax
movq (%rax,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm0
divsd %xmm1, %xmm0
movsd 0xed7(%rip), %xmm1      # 0x4180
ucomisd %xmm0, %xmm1
jb 0x330c
ucomisd 0xed1(%rip), %xmm0      # 0x4188
jbe 0x330c
movq (%r13,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm0
ucomisd -0x8(%rax,%r12,8), %xmm0
jbe 0x3440
ucomisd 0x8(%rax,%r12,8), %xmm0
jbe 0x3440
pushq $0x8
popq %rdi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3820
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3680
jmp 0x3432
movsd 0xe7c(%rip), %xmm1      # 0x4190
ucomisd %xmm0, %xmm1
jb 0x3381
ucomisd 0xe5e(%rip), %xmm0      # 0x4180
jbe 0x3381
movq -0x8(%r13,%rbx,8), %rax
movq (%r13,%rbx,8), %rcx
movsd (%rcx,%r12,8), %xmm0
ucomisd -0x8(%rax,%r12,8), %xmm0
jbe 0x3440
movq 0x8(%r13,%rbx,8), %rax
ucomisd 0x8(%rax,%r12,8), %xmm0
jbe 0x3440
pushq $0x8
popq %rdi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3820
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3680
jmp 0x3432
movsd 0xdff(%rip), %xmm1      # 0x4188
ucomisd %xmm0, %xmm1
movq (%r13,%rbx,8), %rax
movsd (%rax,%r12,8), %xmm1
jb 0x33ef
ucomisd 0xdf6(%rip), %xmm0      # 0x4198
jbe 0x33ef
movq 0x8(%r13,%rbx,8), %rax
ucomisd -0x8(%rax,%r12,8), %xmm1
jbe 0x3440
movq -0x8(%r13,%rbx,8), %rax
ucomisd 0x8(%rax,%r12,8), %xmm1
jbe 0x3440
pushq $0x8
popq %rdi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3820
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3680
jmp 0x3432
movq -0x8(%r13,%rbx,8), %rax
ucomisd (%rax,%r12,8), %xmm1
jbe 0x3440
movq 0x8(%r13,%rbx,8), %rax
ucomisd (%rax,%r12,8), %xmm1
jbe 0x3440
pushq $0x8
popq %rdi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x3820
movq %r14, -0x30(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3680
movq -0x40(%rbp), %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x390a
incq %r12
jmp 0x324d
incq %rbx
jmp 0x3233
movq -0x38(%rbp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x346f
jmp 0x346f
jmp 0x3481
jmp 0x3481
jmp 0x346f
jmp 0x3481
movq %rax, %rbx
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x2180
jmp 0x3484
jmp 0x3481
movq %rax, %rbx
movq -0x38(%rbp), %rdi
callq 0x2e24
movq %rbx, %rdi
callq 0x2250