// File: /workspace/github_cpp_makefile_star2_O1/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 0x3af7
movl %r9d, %r15d
movl %r8d, %r13d
movq %rdi, %r12
movslq %r8d, %rax
movq %rax, -0x38(%rbp)
movq (%rdi,%rax,8), %rax
leaq 0x385f(%rip), %r14      # 0x7194
cvtsi2sdl (%r14), %xmm0
movslq %r9d, %rcx
movq %rcx, -0x30(%rbp)
ucomisd (%rax,%rcx,8), %xmm0
ja 0x3af7
leaq 0x3831(%rip), %rax      # 0x7184
cmpl %r13d, (%rax)
jle 0x3af7
leaq 0x3825(%rip), %rax      # 0x7188
cmpl %r15d, (%rax)
jle 0x3af7
movq -0x48(%rbp), %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x3d20
testl %eax, %eax
jne 0x3af7
movl 0x10(%rbp), %ebx
movq -0x48(%rbp), %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x3d90
testl %ebx, %ebx
jne 0x3a2a
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx,8), %rax
movq $-0x1, %rsi
xorl %ecx, %ecx
movq -0x30(%rbp), %rdx
leaq (,%rdx,8), %rdx
movsd 0x164a(%rip), %xmm0     # 0x5010
movq (%rax,%rsi,8), %rdi
addq %rdx, %rdi
movq $-0x1, %r8
movsd (%rdi,%r8,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x39e2
jnp 0x3a03
incq %r8
cmpq $0x2, %r8
jne 0x39d4
testq %rsi, %rsi
leaq 0x1(%rsi), %rdi
setg %cl
movq %rdi, %rsi
cmpq $0x2, %rdi
jne 0x39c6
jmp 0x3af7
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq -0x30(%rbp), %rdx
movabsq $0x406fe00000000000, %rsi # imm = 0x406FE00000000000
movq %rsi, (%rax,%rdx,8)
testb $0x1, %cl
jne 0x3af7
movl %r15d, %r15d
movq -0x30(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0x68(%rbp)
movq $-0x1, %rcx
movq %r15, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq %rcx, -0x58(%rbp)
leaq (%rcx,%rax), %r13
movq $-0x1, %rbx
movq (%r12,%r13,8), %rax
addq -0x68(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%r14), %xmm1
ucomisd %xmm1, %xmm0
jb 0x3ad9
leal (%r15,%rbx), %edx
movq -0x50(%rbp), %rdi
movl %r13d, %esi
callq 0x3d20
testl %eax, %eax
je 0x3ad9
leal (%r15,%rbx), %r9d
movl $0x1, (%rsp)
movq %r12, %rdi
movq %r14, %r15
movq %r12, %r14
movq -0x40(%rbp), %r12
movq %r12, %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movl %r13d, %r8d
callq 0x38f1
movq -0x38(%rbp), %rax
movq (%r12,%rax,8), %rax
movq %r14, %r12
movq %r15, %r14
movq -0x60(%rbp), %r15
movq -0x30(%rbp), %rcx
movabsq $0x406fe00000000000, %rdx # imm = 0x406FE00000000000
movq %rdx, (%rax,%rcx,8)
incq %rbx
cmpq $0x2, %rbx
jne 0x3a5b
movq -0x58(%rbp), %rcx
incq %rcx
cmpq $0x2, %rcx
jne 0x3a48
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq