// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, (%rsp)
movq %rsi, %rbx
movq %rdi, %r15
callq 0x5a99
testb %al, %al
je 0x19ac0
movq 0x8(%r15), %rax
movq 0x18(%rax), %rcx
movb $0x1, %al
cmpl $0x0, 0x1c(%rcx)
jne 0x19d22
movq %rbx, 0x8(%rsp)
movq 0x10(%rbx), %rax
movslq 0x1c(%r15), %rcx
movq -0x8(%rax,%rcx,8), %r13
movq %r15, %rdi
callq 0x5a8a
movl %eax, %ebx
movq %r15, %rdi
movl %eax, %esi
callq 0x19544
movq %rax, %r12
movq %r13, %rdi
callq 0x5a8a
movl %eax, %ebp
movq %r13, %rdi
movl %eax, %esi
callq 0x19544
movq %rax, %r13
leal (%rbx,%rbp), %edi
movq (%rsp), %rsi
callq 0x630e
movq %rax, %r15
xorl %eax, %eax
testl %ebx, %ebx
movl $0x0, %ecx
cmovgl %ebx, %ecx
xorl %r14d, %r14d
cmpq %rax, %rcx
je 0x19b4d
movq (%r12,%rax,8), %rdx
movq 0x18(%rdx), %rsi
cmpl $0x0, 0x1c(%rsi)
jne 0x19b48
movl 0x18(%rsi), %esi
movq 0x10(%r15), %rdi
movslq %r14d, %r14
movq (%rdi,%r14,8), %rdi
movl %esi, 0x20(%rdi)
movq %rdx, (%rdi)
incl %r14d
incq %rax
jmp 0x19b1e
movl %ebx, %eax
decl %eax
cmpl %eax, %r14d
jne 0x19b7c
movl %r14d, 0x8(%r15)
movslq (%r15), %rax
leaq -0x1(%rax), %rcx
movl %ecx, (%r15)
movq (%rsp), %rcx
movq 0x10(%rcx), %rdi
movq 0x10(%r15), %rcx
movq -0x8(%rcx,%rax,8), %rsi
callq 0x11512
jmp 0x19b83
movl %ebx, 0x8(%r15)
movl %ebx, %r14d
movslq %r14d, %rcx
xorl %eax, %eax
testl %ebp, %ebp
cmovlel %eax, %ebp
movq %rcx, 0x10(%rsp)
leaq (,%rcx,8), %rcx
cmpq %rax, %rbp
je 0x19bc1
movq (%r13,%rax,8), %rdx
movq 0x18(%rdx), %rsi
movl 0x18(%rsi), %esi
movq 0x10(%r15), %rdi
addq %rcx, %rdi
movq (%rdi,%rax,8), %rdi
movl %esi, 0x20(%rdi)
movq %rdx, (%rdi)
incq %rax
jmp 0x19b9a
movq %r12, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
xorl %r12d, %r12d
testl %r14d, %r14d
cmovlel %r12d, %r14d
cmpq %r14, %r12
je 0x19c5b
movq 0x10(%r15), %rax
movq (%rax,%r12,8), %rax
movq (%rax), %r13
movq 0x10(%rsp), %rbp
movslq (%r15), %rax
cmpq %rax, %rbp
jge 0x19c56
movq 0x10(%r15), %rax
movq (%rax,%rbp,8), %rax
movq (%rax), %rbx
movq 0x18(%rbx), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x19c51
movq (%r13), %rdi
movq (%rbx), %rsi
callq 0x19340
testl %eax, %eax
jne 0x19c51
movq 0x18(%r13), %rax
movq (%rax), %rdi
movq 0x18(%rbx), %rax
movq (%rax), %rsi
callq 0x19340
testl %eax, %eax
jne 0x19c51
movq 0x10(%r15), %rax
movq (%rax,%r12,8), %rdi
movq (%rax,%rbp,8), %rsi
movq (%rsp), %rax
movq 0x18(%rax), %rdx
callq 0x17e4
incl 0x4(%r15)
incq %rbp
jmp 0x19bf0
incq %r12
jmp 0x19bdb
movq %r15, %rdi
callq 0x1aac
cmpl 0x8(%r15), %eax
jne 0x19d04
movl %eax, %r12d
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
movq 0x8(%rsp), %r14
cmpq %r12, %rax
je 0x19cc6
movq 0x10(%r15), %rcx
movq (%rcx,%rax,8), %rcx
movq %rcx, %rdx
movq 0x8(%rdx), %rdx
testq %rdx, %rdx
je 0x19cc1
cmpl $0x1, 0x24(%rdx)
jne 0x19c8e
movq 0x18(%rdx), %rdx
movslq 0x20(%rdx), %rdx
leal 0x1(%rdx), %esi
movq (%rcx), %rcx
movq 0x18(%rcx), %rcx
movl %esi, 0x1c(%rcx)
movq 0x10(%r14), %rcx
movq (%rcx,%rdx,8), %rcx
movl $0x1, 0x1c(%rcx)
incq %rax
jmp 0x19c7e
xorl %ebx, %ebx
cmpq %r12, %rbx
je 0x19d14
movq 0x10(%r15), %rax
movq (%rax,%rbx,8), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x19cff
cmpl $0x1, 0x24(%rax)
jne 0x19cd5
movq 0x10(%rax), %rax
movq (%rax), %rax
movq 0x18(%rax), %rdi
movq %r14, %rsi
movq (%rsp), %rdx
callq 0x19a8b
testb %al, %al
je 0x19d04
incq %rbx
jmp 0x19cc8
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x1166e
xorl %eax, %eax
jmp 0x19d22
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x1166e
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq