// File: /workspace/github_c_makefile_star2_O0/pwelke[P]GraphMiningTools/wilsonsAlgorithm.c
// Function: loopErasedRandomWalk
char loopErasedRandomWalk(struct Graph* g, struct IntegerArrayStack* remaining, struct VertexList** previous, char* used, struct ShallowGraph* tree, struct ListPool* lp) {

	int index0 = -1;
	int index1 = -1;

	// Pick a location that’s not yet in the maze (if any).
	for (index0 = ias_pop(remaining); (index0 != -1) && (used[index0]); index0 = ias_pop(remaining));

	if (index0 == -1) {
		return 1;
	}

	// Perform a random walk starting at this location,
	previous[index0] = ROOT; // must be different from NULL, however, must not be a valid pointer.
	while (1) {
		struct VertexList* e;
		int neighborIndex = rand() % degree(g->vertices[index0]);
		int i = 0;

		for (e=g->vertices[index0]->neighborhood; e!=NULL; e=e->next) {
			if (i == neighborIndex) {
				index1 = e->endPoint->number;
				break;
			} else {
				++i;
			}
		}
		// e is set to the edge selected

		// If this new cell was visited previously during this walk,
		// erase the loop, rewinding the path to its earlier state.
		// Otherwise, just add it to the walk.
		if ((previous[index1] != NULL)) {
			eraseWalk(index0, index1, previous);
		} else {
			previous[index1] = e;
		}
		index0 = index1;

		// If this cell is part of the maze, we’re done walking.
		if (used[index1]) {
			// Add the random walk to the maze by backtracking to the starting cell.
			// Also erase this walk’s history to not interfere with subsequent walks.
			for (index0=previous[index1]->startPoint->number; index0!=index1; index0=previous[index1]->startPoint->number) {
				used[index0] = 1;
				appendEdge(tree, shallowCopyEdge(previous[index1], lp));
				previous[index1] = NULL;
				index1 = index0;
				if (previous[index1] == ROOT) {
					break;
				}
			}
			previous[index1] = NULL;
			return 0;
		}
	}
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %r9, 0x30(%rsp)
movl $0xffffffff, 0x2c(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
movq 0x50(%rsp), %rdi
callq 0x32ce0
movl %eax, 0x2c(%rsp)
xorl %eax, %eax
cmpl $-0x1, 0x2c(%rsp)
movb %al, 0x17(%rsp)
je 0x33165
movq 0x40(%rsp), %rax
movslq 0x2c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x3316f
jmp 0x33181
jmp 0x33171
movq 0x50(%rsp), %rdi
callq 0x32ce0
movl %eax, 0x2c(%rsp)
jmp 0x33140
cmpl $-0x1, 0x2c(%rsp)
jne 0x33192
movb $0x1, 0x67(%rsp)
jmp 0x33361
movq 0xafbf(%rip), %rdx      # 0x3e158
movq 0x48(%rsp), %rax
movslq 0x2c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
callq 0x1220
movl %eax, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x2c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xa440
movl %eax, %ecx
movl 0x10(%rsp), %eax
cltd
idivl %ecx
movl %edx, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movq 0x58(%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 0x33238
movl 0x18(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jne 0x3321b
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %eax
movl %eax, 0x28(%rsp)
jmp 0x33238
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x33228
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x331f7
movq 0x48(%rsp), %rax
movslq 0x28(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x3325d
movl 0x2c(%rsp), %edi
movl 0x28(%rsp), %esi
movq 0x48(%rsp), %rdx
callq 0x33080
jmp 0x33270
movq 0x20(%rsp), %rdx
movq 0x48(%rsp), %rax
movslq 0x28(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x28(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x40(%rsp), %rax
movslq 0x28(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3335c
movq 0x48(%rsp), %rax
movslq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rax
movl 0x18(%rax), %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x28(%rsp), %eax
je 0x33343
movq 0x40(%rsp), %rax
movslq 0x2c(%rsp), %rcx
movb $0x1, (%rax,%rcx)
movq 0x38(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rax
movslq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x30(%rsp), %rsi
callq 0xa310
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0xbf70
movq 0x48(%rsp), %rax
movslq 0x28(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movl 0x2c(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x48(%rsp), %rax
movslq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
cmpq 0xae39(%rip), %rax      # 0x3e158
jne 0x33323
jmp 0x33343
jmp 0x33325
movq 0x48(%rsp), %rax
movslq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rax
movl 0x18(%rax), %eax
movl %eax, 0x2c(%rsp)
jmp 0x332a5
movq 0x48(%rsp), %rax
movslq 0x28(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movb $0x0, 0x67(%rsp)
jmp 0x33361
jmp 0x331a7
movb 0x67(%rsp), %al
addq $0x68, %rsp
retq
nopw (%rax,%rax)