// File: /workspace/github_cpp_makefile_star2_O1/davidgfnet[P]dns-db/dns_block.cc
// Function: DNS_DB::DnsBlock::makeRoomMove(char const*)
void DNS_DB::DnsBlock::makeRoomMove(const char * domain) {
	// Assume we do not have an empty spot for ourselves. Therefore
	// look for the place we should be and move all the nodes down one
	// position
	int p = 0;

	int res = lookupEmptyDomainSpot(domain, &p);
	assert(res == NO_EMPTY_SPOT || res == ALREADY_EXISTS);

	for (p; p < numBlocks; p++) {
		DNS_DB::DnsBlock::InternalBlock * ptr = &blockptr[p];
		// Stop after we find our spot
		if ((ptr->header & flagUsed) && (ptr->header & DNS_DB::DnsBlock::flagDomain)) {
			if ( !less(ptr->data.domain.domain, domain) ) {
				// If the domain exists move to the last block of it
				if (memcmp(ptr->data.domain.domain, domain, MAX_DNS_SIZE) == 0) {
					do {
						p++;
						ptr = &blockptr[p];
					} while (ptr != endptr && (ptr->header & DNS_DB::DnsBlock::flagUsed) && !(ptr->header & DNS_DB::DnsBlock::flagDomain));
				}
				break;
			}
		}
	}

	// We should not have space after us, otherwise why are we getting called?
	assert((p == numBlocks) || (blockptr[p].header & DNS_DB::DnsBlock::flagDomain));

	if (p == numBlocks)
		return;

	#ifdef EXTRA_CHECK
	checkBM();
	#endif

	// Look for the first empty slot, and move the N slots to make room
	int tomove = 1;
	InternalBlock * ptrl = &blockptr[p+1];
	while (ptrl != endptr) {
		if (!(ptrl->header & flagUsed)) {
			// Move N consec elements down, to make room at ptr
			memmove(&blockptr[p+1], &blockptr[p], tomove*sizeof(InternalBlock));
			memset (&blockptr[p], 0, sizeof(InternalBlock));
			break;
		}
		else
			tomove++;
			
		ptrl++;
	}
	
	if (ptrl == endptr)
		return;

	// Update the bitmask
	bitmap->setBit(p+tomove, true);
	bitmap->setBit(p, false);

	#ifdef EXTRA_CHECK
	checkBM();
	#endif

	// It might happen that we do not have room :(
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
leaq 0x4(%rsp), %rdx
movl $0x0, (%rdx)
movq %rdi, 0x8(%rsp)
callq 0x634e
cmpl $-0x2, %eax
jb 0x6922
movl 0x8b33(%rip), %ebp      # 0xf280
movl 0x4(%rsp), %ebx
cmpl %ebp, %ebx
jae 0x6811
movslq %ebx, %rax
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movb 0x8b0d(%rip), %r12b     # 0xf278
movb 0x8b07(%rip), %r13b     # 0xf279
shlq $0x6, %rax
movq %rcx, 0x10(%rsp)
leaq (%rax,%rcx), %r15
incq %r15
movb -0x1(%r15), %al
testb %al, %r12b
sete %cl
testb %al, %r13b
sete %al
orb %cl, %al
jne 0x67aa
movl $0x23, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x3110
testl %eax, %eax
jns 0x67ba
incl %ebx
movl %ebx, 0x4(%rsp)
addq $0x40, %r15
cmpl %ebx, %ebp
ja 0x6782
jmp 0x6811
movl $0x23, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x3260
testl %eax, %eax
jne 0x6811
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x4(%rsp), %rcx
leal 0x1(%rcx), %esi
shlq $0x6, %rcx
movq 0x10(%rsp), %rdx
addq %rdx, %rcx
addq $0x40, %rcx
movl %esi, %edx
cmpq %rax, %rcx
je 0x680d
movb (%rcx), %dil
testb %r12b, %dil
je 0x680d
andb %r13b, %dil
leal 0x1(%rdx), %esi
addq $0x40, %rcx
testb %dil, %dil
je 0x67ef
movl %edx, 0x4(%rsp)
movslq 0x4(%rsp), %rax
cmpl %ebp, %eax
je 0x6913
movq 0x8(%rsp), %rcx
movq (%rcx), %rdx
movq %rax, %rcx
shlq $0x6, %rcx
movb 0x8a45(%rip), %sil      # 0xf279
testb %sil, (%rdx,%rcx)
je 0x6941
cmpl %ebp, %eax
je 0x6913
movq 0x8(%rsp), %rax
movq (%rax), %r15
movq 0x8(%rax), %rax
leaq (%r15,%rcx), %rdx
addq $0x40, %rdx
cmpq %rax, %rdx
je 0x6890
addq %rcx, %r15
movl $0x1, %r14d
movl $0x40, %r12d
movb 0x8a04(%rip), %cl       # 0xf278
testb %cl, (%r15,%r12)
je 0x6898
incl %r14d
leaq (%r15,%r12), %rdx
addq $0x40, %rdx
addq $0x40, %r12
cmpq %rax, %rdx
jne 0x6874
jmp 0x68ce
movl $0x1, %r14d
jmp 0x68d4
leaq 0x40(%r15), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x33b0
movq 0x8(%rsp), %rax
movq (%rax), %rax
movslq 0x4(%rsp), %rcx
shlq $0x6, %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax,%rcx)
movups %xmm0, 0x20(%rax,%rcx)
movups %xmm0, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
addq %r12, %r15
movq %r15, %rdx
movq 0x8(%rsp), %rax
cmpq 0x8(%rax), %rdx
je 0x6913
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
addl 0x4(%rsp), %r14d
movl $0x1, %edx
movl %r14d, %ecx
shll %cl, %edx
movq (%rax), %rax
shrl $0x5, %r14d
orl %edx, (%rax,%r14,4)
movl 0x4(%rsp), %ecx
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
roll %cl, %edx
shrl $0x5, %ecx
andl %edx, (%rax,%rcx,4)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3c69(%rip), %rdi      # 0xa592
leaq 0x39c9(%rip), %rsi      # 0xa2f9
leaq 0x3c89(%rip), %rcx      # 0xa5c0
movl $0x162, %edx            # imm = 0x162
callq 0x3180
leaq 0x3caa(%rip), %rdi      # 0xa5f2
leaq 0x39aa(%rip), %rsi      # 0xa2f9
leaq 0x3c6a(%rip), %rcx      # 0xa5c0
movl $0x176, %edx            # imm = 0x176
callq 0x3180