// File: EnderGed[P]fast-random-walk/HelperFunctions.cpp
// Function: boolSort(unsigned int*, unsigned long)
void boolSort(uint * const list, size_t const size)
{
	// Determine maximum list value
	uint const maxVal = maxValue(list, size);

	std::vector<bool> bitSet(maxVal + 1, false);

	// Set the corresponding bit in bitSet for every value in the list
	for(uint const * pos = list; pos < list + size; ++pos)
	{
		// If bit is already set ...
		if(bitSet[*pos])
		{
			// Print warning and call countSort as fallback
			printf("Value occures multiple times. Fallback tack countSort.\n");
			countSort(list, size);
			return;
		}
		else bitSet[*pos] = true;
	}

	// Write the found values back to the list
	register uint val = 0;
	for(register uint * pos = list; pos < list + size; ++pos)
	{
		while(!bitSet[val]) ++val;
		*pos = val++;
	}
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x69c0
movl %eax, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
incl %eax
movq %rax, 0x30(%rsp)
movb $0x0, 0xa7(%rsp)
leaq 0xa6(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x3a80
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rcx
leaq 0xa8(%rsp), %rdi
leaq 0xa7(%rsp), %rdx
callq 0x3a90
jmp 0x6cec
leaq 0xa6(%rsp), %rdi
callq 0x3b10
movq 0xe0(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rax
movq 0xe0(%rsp), %rcx
movq 0xd8(%rsp), %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x6e5e
movq 0x88(%rsp), %rax
movl (%rax), %eax
movl %eax, %esi
leaq 0xa8(%rsp), %rdi
callq 0x3bb0
movq %rdx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
jmp 0x6d56
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x78(%rsp)
movq %rax, 0x80(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x3e60
testb $0x1, %al
jne 0x6d7d
jmp 0x6dfb
leaq 0x53fb(%rip), %rdi      # 0xc17f
xorl %eax, %eax
callq 0x2040
jmp 0x6d8d
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x6b40
movl $0x1, 0x74(%rsp)
jmp 0x6f15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0xa6(%rsp), %rdi
callq 0x3b10
jmp 0x6f2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x3e90
jmp 0x6f2a
movq 0x88(%rsp), %rax
movl (%rax), %eax
movl %eax, %esi
leaq 0xa8(%rsp), %rdi
callq 0x3bb0
movq %rdx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
jmp 0x6e20
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movq %rax, 0x68(%rsp)
leaq 0x60(%rsp), %rdi
movl $0x1, %esi
callq 0x3c10
jmp 0x6e45
movq 0x88(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x88(%rsp)
jmp 0x6d09
movl $0x0, 0x5c(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq 0xe0(%rsp), %rcx
movq 0xd8(%rsp), %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x6f0d
jmp 0x6e96
movl 0x5c(%rsp), %eax
movl %eax, %esi
leaq 0xa8(%rsp), %rdi
callq 0x3bb0
movq %rdx, (%rsp)
movq %rax, 0x8(%rsp)
jmp 0x6eb4
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq %rax, 0x48(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x3e60
xorb $-0x1, %al
testb $0x1, %al
jne 0x6ed9
jmp 0x6ee6
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x6e96
movl 0x5c(%rsp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
movq 0x50(%rsp), %rax
movl %ecx, (%rax)
movq 0x50(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x50(%rsp)
jmp 0x6e73
movl $0x0, 0x74(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x3e90
addq $0xe8, %rsp
retq
movq 0x98(%rsp), %rdi
callq 0x22d0
nopw (%rax,%rax)