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

	// base case: if parent is a leaf and its only neighbor is already assigned to a vertex in g, we are done
	if (isLeaf(parent) && parent->neighborhood->endPoint->visited) { return 1; }

	struct Vertex* parentImage = g->vertices[parent->visited - 1];
	struct Graph* B = makeBipartiteInstanceFromVertices(parent, parentImage, gp);
	int sizeOfMatching = bipartiteMatchingEvenMoreDirty(B);
	int nNeighbors = B->number;

	// is there a matching here covering all unmatched neighbors of parent?
	// if not, there is no subgraph iso here
	if (sizeOfMatching != nNeighbors) {
		dumpGraph(gp, B);
		return 0;
	}

	// mark all matched neighbors of currentImage as ->visited
	for (int i=0; i<nNeighbors; ++i) {
		// find match
		for (struct VertexList* e=B->vertices[i]->neighborhood; e!=NULL; e=e->next) {
			if (e->flag == 1) {
				// mark embedding vertex as mapped to current vertex
				((struct VertexList*)B->vertices[i]->label)->endPoint->visited = e->endPoint->lowPoint + 1;
				g->vertices[e->endPoint->lowPoint]->visited = 1;
				break;
			}
		}
	}

	// recurse to the matched vertices
	for (int i=0; i<nNeighbors; ++i) {
		for (struct VertexList* e=B->vertices[i]->neighborhood; e!=NULL; e=e->next) {
			if (e->flag == 1) {
				struct Vertex* newChild = ((struct VertexList*)e->startPoint->label)->endPoint;
				char embeddingWorked = recursiveSubtreeIsomorphismSamplerWithMatching(newChild, g, gp);
				if (embeddingWorked) {
					// we are done with this neighbor of parent
					break;
				} else {
					// there is no subtree iso here
					dumpGraph(gp, B);
					return 0;
				}
			}
		}
	}

	dumpGraph(gp, B);
	// so far, we have been successful
	return 1;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq 0x58(%rsp), %rdi
callq 0xa490
movsbl %al, %eax
cmpl $0x0, %eax
je 0x2ead2
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
cmpl $0x0, 0x1c(%rax)
je 0x2ead2
movb $0x1, 0x67(%rsp)
jmp 0x2ecc6
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, 0x40(%rsp)
movq 0x58(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0x2f040
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
callq 0x21d0
movl %eax, 0x34(%rsp)
movq 0x38(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x30(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x30(%rsp), %eax
je 0x2eb48
movq 0x48(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1fb30
movb $0x0, 0x67(%rsp)
jmp 0x2ecc6
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x30(%rsp), %eax
jge 0x2ebfe
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x2ebec
movq 0x20(%rsp), %rax
cmpl $0x1, 0x24(%rax)
jne 0x2ebda
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl %ecx, 0x1c(%rax)
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, 0x1c(%rax)
jmp 0x2ebec
jmp 0x2ebdc
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x2eb79
jmp 0x2ebee
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x2eb50
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x30(%rsp), %eax
jge 0x2ecb2
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x2eca0
movq 0x10(%rsp), %rax
cmpl $0x1, 0x24(%rax)
jne 0x2ec8e
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0x2ea90
movb %al, 0x7(%rsp)
cmpb $0x0, 0x7(%rsp)
je 0x2ec78
jmp 0x2eca0
movq 0x48(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1fb30
movb $0x0, 0x67(%rsp)
jmp 0x2ecc6
jmp 0x2ec90
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x2ec2f
jmp 0x2eca2
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x2ec06
movq 0x48(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1fb30
movb $0x1, 0x67(%rsp)
movb 0x67(%rsp), %al
addq $0x68, %rsp
retq
nop