// File: /workspace/github_cpp_makefile_star2_O3/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 %rdi, %rbx
leaq 0x4(%rsp), %rdx
movl $0x0, (%rdx)
movq %rsi, 0x10(%rsp)
callq 0x62c6
cmpl $-0x2, %eax
jb 0x682b
movl 0x8bf1(%rip), %ebp      # 0xf280
movl 0x4(%rsp), %r12d
cmpl %ebp, %r12d
movq %rbx, 0x8(%rsp)
jae 0x6752
movslq %r12d, %r12
movq (%rbx), %r14
movb 0x8bc9(%rip), %r13b     # 0xf278
movb 0x8bc4(%rip), %bl       # 0xf279
movq %r12, %r15
shlq $0x6, %r15
movb (%r14,%r15), %al
testb %al, %r13b
sete %cl
testb %al, %bl
sete %al
orb %cl, %al
jne 0x66eb
addq %r14, %r15
incq %r15
movl $0x23, %edx
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0x3110
testl %eax, %eax
jns 0x66fa
incq %r12
movl %r12d, 0x4(%rsp)
cmpl %r12d, %ebp
ja 0x66b5
jmp 0x6752
movl $0x23, %edx
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0x3260
testl %eax, %eax
jne 0x6752
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movslq %r12d, %rcx
shlq $0x6, %rcx
addq %r14, %rcx
addq $0x40, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %esi, %edx
cmpq %rax, %rcx
je 0x674a
movb (%rcx), %dil
testb %r13b, %dil
je 0x674a
andb %bl, %dil
leal -0x1(%rdx), %esi
addq $0x40, %rcx
testb %dil, %dil
je 0x672c
subl %edx, %r12d
movl %r12d, 0x4(%rsp)
cmpl %ebp, %r12d
movq 0x8(%rsp), %r13
je 0x681c
movq (%r13), %r14
movslq %r12d, %rax
shlq $0x6, %rax
movb 0x8b08(%rip), %cl       # 0xf279
testb %cl, (%r14,%rax)
je 0x684a
addq %rax, %r14
movq 0x8(%r13), %rax
leaq 0x40(%r14), %rdi
cmpq %rax, %rdi
je 0x681c
movl $0x40, %r15d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movb 0x8ad8(%rip), %cl       # 0xf278
testb %cl, (%r14,%r15)
je 0x67bb
leaq (%r14,%r15), %rdx
addq $0x40, %rdx
addq $0x40, %r15
decl %ebx
cmpq %rax, %rdx
jne 0x67a0
jmp 0x681c
movq %r14, %rsi
movq %r15, %rdx
callq 0x33b0
movq (%r13), %rax
movslq 0x4(%rsp), %rcx
movq %rcx, %rdx
shlq $0x6, %rdx
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax,%rdx)
movups %xmm0, 0x20(%rax,%rdx)
movups %xmm0, 0x10(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
addq %r15, %r14
cmpq 0x8(%r13), %r14
je 0x681c
movq 0x18(%r13), %rax
subl %ebx, %ecx
movl $0x1, %edx
shll %cl, %edx
movq (%rax), %rax
shrl $0x5, %ecx
orl %edx, (%rax,%rcx,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 0x3d60(%rip), %rdi      # 0xa592
leaq 0x3ac0(%rip), %rsi      # 0xa2f9
leaq 0x3d80(%rip), %rcx      # 0xa5c0
movl $0x162, %edx            # imm = 0x162
callq 0x3180
leaq 0x3da1(%rip), %rdi      # 0xa5f2
leaq 0x3aa1(%rip), %rsi      # 0xa2f9
leaq 0x3d61(%rip), %rcx      # 0xa5c0
movl $0x176, %edx            # imm = 0x176
callq 0x3180
nop