// File: /workspace/github_c_makefile_star2_O2/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 %rdi, %r14
movq %rsi, 0x10(%rsp)
movq 0x10(%rsi), %rax
movslq 0x1c(%rdi), %rcx
movq -0x8(%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
callq 0x5a8a
movl %eax, %r15d
movq %r14, %rdi
movl %eax, %esi
callq 0x19544
xorl %r13d, %r13d
testl %r15d, %r15d
cmovlel %r13d, %r15d
movq %rax, %rbp
xorl %r14d, %r14d
xorl %ecx, %ecx
movq %r15, 0x8(%rsp)
cmpq %r15, %r13
je 0x19785
movq (%rbp,%r13,8), %r12
movq 0x18(%r12), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x1977d
movq %rbp, %r15
movq %rcx, 0x20(%rsp)
leal 0x1(%rcx), %ebp
incl %r14d
movq 0x18(%rsp), %rbx
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
je 0x19773
movq 0x18(%rbx), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x1970d
movq (%r12), %rdi
movq (%rbx), %rsi
callq 0x19340
testl %eax, %eax
jne 0x1970d
movq 0x18(%r12), %rax
movq (%rax), %rdi
movq 0x18(%rbx), %rax
movq (%rax), %rsi
callq 0x19340
testl %eax, %eax
jne 0x1970d
movq 0x18(%rbx), %rax
movl 0x18(%rax), %ecx
incl %ecx
movq 0x18(%r12), %rdx
movl %ecx, 0x1c(%rdx)
pushq $0x1
popq %rcx
movl %ecx, 0x24(%r12)
movl %ecx, 0x1c(%rax)
movq %r15, %rbp
movq 0x8(%rsp), %r15
movq 0x20(%rsp), %rcx
jmp 0x1977d
movl %ebp, %ecx
movq %r15, %rbp
movq 0x8(%rsp), %r15
incq %r13
jmp 0x196dd
testl %ecx, %ecx
jle 0x197a6
xorl %r12d, %r12d
movq %rbp, %rdi
callq 0x1030
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %r12b
testl %r14d, %r14d
je 0x1978c
xorl %ebx, %ebx
movq 0x10(%rsp), %r13
cmpq %rbx, %r15
je 0x1978c
movq (%rbp,%rbx,8), %rax
cmpl $0x0, 0x24(%rax)
je 0x197d9
andl $0x0, 0x24(%rax)
movq 0x18(%rax), %rdi
movq %r13, %rsi
callq 0x1968c
testb %al, %al
je 0x19789
incq %rbx
jmp 0x197b5