// File: /workspace/github_c_makefile_star2_O3/pwelke[P]GraphMiningTools/subtreeIsomorphismSampling.c
// Function: recursiveSubtreeIsomorphismSampler
static char recursiveSubtreeIsomorphismSampler(struct Vertex* parent, struct Graph* g) {

	struct Vertex* currentImage = g->vertices[parent->visited - 1];

	int nNeighbors = degree(parent);
	struct VertexList** shuffledNeighbors = shuffleNeighbors(parent, nNeighbors);

	// TODO need to shuffle the neighbors of the image, as well
	int unassignedNeighborsOfRoot = 0;
	int processedNeighborsOfRoot = 0;

	for (int i=0; i<nNeighbors; ++i) {
		struct VertexList* child = shuffledNeighbors[i];
		if (child->endPoint->visited == 0) {
			++unassignedNeighborsOfRoot;
			++processedNeighborsOfRoot;
			for (struct VertexList* embeddingEdge=currentImage->neighborhood; embeddingEdge!=NULL; embeddingEdge=embeddingEdge->next) {
				if ((embeddingEdge->endPoint->visited == 0)
						&& (labelCmp(child->label, embeddingEdge->label) == 0)
						&& (labelCmp(child->endPoint->label, embeddingEdge->endPoint->label) == 0)) {

					// if the child vertex and edge labels fit, map the vertices to each other, mark it as a novel assignment
					child->endPoint->visited = embeddingEdge->endPoint->number + 1;
					child->flag = 1;
					embeddingEdge->endPoint->visited = 1;

					// and remember that the child vertex was assigned
					--unassignedNeighborsOfRoot;
					break; //...looping over the neighbors of the image of parent in g
				}
			}
		}
	}

	// check, if we could assign all neighbors of the currentRoot to some neighbors of its image.
	if (unassignedNeighborsOfRoot > 0) {
		free(shuffledNeighbors);
		return 0;
	}

	// if none of the neighbors needs to be newly asigned, we have embedded this branch.
	if (processedNeighborsOfRoot == 0) {
		free(shuffledNeighbors);
		return 1;
	}

	// if new neighbors were assigned, recurse to the newly assigned neighbors
	char embeddingWorked = 1;
	for (int i=0; i<nNeighbors; ++i) {
		struct VertexList* child = shuffledNeighbors[i];
		if (child->flag) {
			child->flag = 0;
			embeddingWorked = recursiveSubtreeIsomorphismSampler(child->endPoint, g);
		}
		if (!embeddingWorked) {
			break;
		}
	}
	free(shuffledNeighbors);
	return embeddingWorked;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x10(%rsi), %rax
movslq 0x1c(%rdi), %rcx
movq -0x8(%rax,%rcx,8), %rax
movq %rax, 0x20(%rsp)
callq 0x7c4e
movl %eax, %ebp
movq %r14, %rdi
movl %eax, %esi
callq 0x1bd78
movq %rax, %r13
testl %ebp, %ebp
jle 0x1c040
movq %rbx, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
movl %ebp, %r15d
xorl %ebp, %ebp
xorl %ecx, %ecx
xorl %r14d, %r14d
movq %r15, (%rsp)
movq (%r13,%rbp,8), %r12
movq 0x18(%r12), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x1bfbc
movq %r13, %r15
movq %rcx, 0x18(%rsp)
leal 0x1(%rcx), %r13d
incl %r14d
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rbx
testq %rbx, %rbx
je 0x1bfb2
movq 0x18(%rbx), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x1bfac
movq (%r12), %rdi
movq (%rbx), %rsi
callq 0x1bb34
testl %eax, %eax
jne 0x1bfac
movq 0x18(%r12), %rax
movq (%rax), %rdi
movq 0x18(%rbx), %rax
movq (%rax), %rsi
callq 0x1bb34
testl %eax, %eax
je 0x1bfc6
movq 0x8(%rbx), %rbx
jmp 0x1bf75
movl %r13d, %ecx
movq %r15, %r13
movq (%rsp), %r15
incq %rbp
cmpq %r15, %rbp
jne 0x1bf4d
jmp 0x1bff2
movq 0x18(%rbx), %rax
movl 0x18(%rax), %ecx
incl %ecx
movq 0x18(%r12), %rdx
movl %ecx, 0x1c(%rdx)
movl $0x1, %ecx
movl %ecx, 0x24(%r12)
movl %ecx, 0x1c(%rax)
movq %r15, %r13
movq (%rsp), %r15
movq 0x18(%rsp), %rcx
jmp 0x1bfbc
cmpl $0x0, 0xc(%rsp)
setle %al
testl %ecx, %ecx
setle %bpl
setg %cl
testl %r14d, %r14d
sete %dl
orb %cl, %dl
orb %al, %dl
jne 0x1c043
xorl %ebx, %ebx
movq 0x10(%rsp), %r12
movq (%r13,%rbx,8), %rax
cmpl $0x0, 0x24(%rax)
je 0x1c038
movl $0x0, 0x24(%rax)
movq 0x18(%rax), %rdi
movq %r12, %rsi
callq 0x1bef4
testb %al, %al
je 0x1c05c
incq %rbx
cmpq %rbx, %r15
jne 0x1c016
movb $0x1, %bpl
movq %r13, %rdi
callq 0x1030
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0x1c043