// File: /workspace/github_cpp_makefile_star2_O3/sorazy[P]canny/canny.cpp
// Function: recursiveDT(double**, double**, HashMap*, HashMap*, int, int, int)
void recursiveDT(double **mag, double **final, HashMap *h, HashMap *peaks, int a, int b, int flag)
{
	// If the pixel value is < lo, out-of-bounds, or at a point we've visited before,
	// then exit the funciton.
	if (mag[a][b] < lo || a < 0 || b < 0 || a >= height || b >= width)
		return;
	if (h->contains(a, b))
		return;

	// Insert the current pixel so we know we've been here before.
	h->insert(a, b);

	// If flag = 0, that means that this is the first pixel of the "series" that
	// we're looking at. We're going to look for a pixel in "final" that's set to
	// ON. If we found one, assert the flag and break out of the loops.
	if (!flag)
	{
		for (int p = -1; p <= 1; p++)
		{
			for (int q = -1; q <= 1; q++)
			{
				if (final[a+p][b+q] == 255)
				{
					final[a][b] = 255;
					flag = 1;
					break;
				}
			}

			if (flag)
				break;
		}
	}
	
	// If flag is asserted, that means we found a pixel that's in final, all what
	// we have to do now is just search for pixels that are in the mid range.
	// Also, make sure that it's in the peaks to begin with.
	if (flag)
	{
		for (int p = -1; p <= 1; p++)
		{
			for (int q = -1; q <= 1; q++)
			{
				if (mag[a+p][b+q] >= lo && peaks->contains(a+p, b+q))
				{
					recursiveDT(mag, final, h, peaks, a+p, b+q, 1);
					final[a][b] = 255;
				}
			}
		}
	}

	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
movq %rsi, -0x40(%rbp)
movl %r9d, %eax
orl %r8d, %eax
js 0x3abc
movl %r9d, %r14d
movl %r8d, %r13d
movq %rdi, %r12
movslq %r8d, %rax
movq %rax, -0x38(%rbp)
movq (%rdi,%rax,8), %rax
leaq 0x3881(%rip), %rcx      # 0x718c
cvtsi2sdl (%rcx), %xmm0
movslq %r9d, %rcx
movq %rcx, -0x30(%rbp)
ucomisd (%rax,%rcx,8), %xmm0
ja 0x3abc
leaq 0x3854(%rip), %rax      # 0x717c
cmpl %r13d, (%rax)
jle 0x3abc
leaq 0x3848(%rip), %rax      # 0x7180
cmpl %r14d, (%rax)
jle 0x3abc
movq -0x48(%rbp), %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x3cf0
testl %eax, %eax
jne 0x3abc
movl 0x10(%rbp), %ebx
movq -0x48(%rbp), %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x3d5e
testl %ebx, %ebx
leaq 0x3819(%rip), %rbx      # 0x718c
jne 0x39ec
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx,8), %rax
movq $-0x1, %rcx
movq -0x30(%rbp), %rdx
leaq (,%rdx,8), %rdx
movsd 0x17d4(%rip), %xmm0     # 0x5170
movq (%rax,%rcx,8), %rsi
addq %rdx, %rsi
movq $-0x1, %rdi
movsd (%rsi,%rdi,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x39b7
jnp 0x39ce
incq %rdi
cmpq $0x2, %rdi
jne 0x39aa
incq %rcx
cmpq $0x2, %rcx
jne 0x399c
jmp 0x3abc
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x30(%rbp), %rcx
movabsq $0x406fe00000000000, %rdx # imm = 0x406FE00000000000
movq %rdx, (%rax,%rcx,8)
movl %r14d, %eax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0x68(%rbp)
movq $-0x1, %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x58(%rbp)
leaq (%rcx,%rax), %r13
movq $-0x1, %r15
movq (%r12,%r13,8), %rax
addq -0x68(%rbp), %rax
movsd (%rax,%r15,8), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%rbx), %xmm1
ucomisd %xmm1, %xmm0
jb 0x3a9e
movq -0x60(%rbp), %rax
leaq (%rax,%r15), %r14
movq -0x50(%rbp), %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x3cf0
testl %eax, %eax
je 0x3a9e
movl $0x1, (%rsp)
movq %r12, %rdi
movq %r12, %rbx
movq -0x40(%rbp), %r12
movq %r12, %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movl %r13d, %r8d
movl %r14d, %r9d
callq 0x38c7
movq -0x38(%rbp), %rax
movq (%r12,%rax,8), %rax
movq %rbx, %r12
leaq 0x3700(%rip), %rbx      # 0x718c
movq -0x30(%rbp), %rcx
movabsq $0x406fe00000000000, %rdx # imm = 0x406FE00000000000
movq %rdx, (%rax,%rcx,8)
incq %r15
cmpq $0x2, %r15
jne 0x3a1d
movq -0x58(%rbp), %rcx
incq %rcx
cmpq $0x2, %rcx
jne 0x3a0a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop