// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x58(%rsp), %rcx
movl 0x1c(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rdi
callq 0xa440
movl %eax, 0x44(%rsp)
movq 0x58(%rsp), %rdi
movl 0x44(%rsp), %esi
callq 0x2e0e0
movq %rax, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movl $0x0, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x2e4f7
movq 0x38(%rsp), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x2e4e5
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x2e4e3
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x2e4ce
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq 0x18(%rsp), %rax
movq (%rax), %rsi
callq 0x2dcf0
cmpl $0x0, %eax
jne 0x2e4ce
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rsi
callq 0x2dcf0
cmpl $0x0, %eax
jne 0x2e4ce
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movl %ecx, 0x1c(%rax)
movq 0x20(%rsp), %rax
movl $0x1, 0x24(%rax)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movl $0x1, 0x1c(%rax)
movl 0x34(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x2e4e3
jmp 0x2e4d0
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x2e42f
jmp 0x2e4e5
jmp 0x2e4e7
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x2e3d7
cmpl $0x0, 0x34(%rsp)
jle 0x2e512
movq 0x38(%rsp), %rdi
callq 0x1030
movb $0x0, 0x67(%rsp)
jmp 0x2e5af
cmpl $0x0, 0x30(%rsp)
jne 0x2e52d
movq 0x38(%rsp), %rdi
callq 0x1030
movb $0x1, 0x67(%rsp)
jmp 0x2e5af
movb $0x1, 0x17(%rsp)
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x2e59d
movq 0x38(%rsp), %rax
movslq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpl $0x0, 0x24(%rax)
je 0x2e585
movq 0x8(%rsp), %rax
movl $0x0, 0x24(%rax)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x50(%rsp), %rsi
callq 0x2e370
movb %al, 0x17(%rsp)
cmpb $0x0, 0x17(%rsp)
jne 0x2e58e
jmp 0x2e59d
jmp 0x2e590
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x2e53a
movq 0x38(%rsp), %rdi
callq 0x1030
movb 0x17(%rsp), %al
movb %al, 0x67(%rsp)
movb 0x67(%rsp), %al
addq $0x68, %rsp
retq
nopl (%rax,%rax)