// File: /workspace/github_cpp_makefile_star2_O2/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
andl $0x0, (%rdx)
movq %rsi, 0x10(%rsp)
callq 0x5a60
cmpl $-0x2, %eax
jb 0x5f49
movl 0x94b1(%rip), %r15d     # 0xf290
movslq 0x4(%rsp), %r12
movq %rbx, 0x8(%rsp)
movq (%rbx), %r14
movb 0x9495(%rip), %bpl      # 0xf288
movb 0x9490(%rip), %bl       # 0xf289
cmpl %r12d, %r15d
jbe 0x5e94
movq %r12, %r13
shlq $0x6, %r13
movb (%r14,%r13), %al
testb %al, %bpl
sete %cl
testb %al, %bl
sete %al
orb %cl, %al
jne 0x5e36
addq %r14, %r13
incq %r13
movq %r13, %rdi
movq 0x10(%rsp), %rsi
pushq $0x23
popq %rdx
callq 0x3120
testl %eax, %eax
jns 0x5e40
incq %r12
movl %r12d, 0x4(%rsp)
jmp 0x5df9
pushq $0x23
popq %rdx
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0x3270
testl %eax, %eax
jne 0x5e94
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movslq %r12d, %rcx
shlq $0x6, %rcx
addq %r14, %rcx
addq $0x40, %rcx
pushq $-0x1
popq %rsi
movl %esi, %edx
cmpq %rax, %rcx
je 0x5e8c
movb (%rcx), %dil
testb %bpl, %dil
je 0x5e8c
andb %bl, %dil
leal -0x1(%rdx), %esi
addq $0x40, %rcx
testb %dil, %dil
je 0x5e6e
subl %edx, %r12d
movl %r12d, 0x4(%rsp)
cmpl %r15d, %r12d
je 0x5f3a
movslq %r12d, %rax
shlq $0x6, %rax
testb %bl, (%r14,%rax)
je 0x5f68
pushq $-0x1
popq %rbx
addq %rax, %r14
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
pushq $0x40
popq %rdx
leaq (%r14,%rdx), %r15
cmpq %rax, %r15
je 0x5f3a
testb %bpl, (%r15)
je 0x5ed6
decl %ebx
addq $0x40, %rdx
jmp 0x5ec0
leaq 0x40(%r14), %rdi
movq %r14, %rsi
callq 0x33c0
movq 0x8(%rsp), %rsi
movq (%rsi), %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)
cmpq 0x8(%rsi), %r15
je 0x5f3a
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
subl %ebx, %ecx
pushq $0x1
popq %rdx
shll %cl, %edx
movq (%rax), %rax
shrl $0x5, %ecx
orl %edx, (%rax,%rcx,4)
movl 0x4(%rsp), %ecx
pushq $-0x2
popq %rdx
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 0x3612(%rip), %rdi      # 0x9562
leaq 0x3372(%rip), %rsi      # 0x92c9
leaq 0x3632(%rip), %rcx      # 0x9590
movl $0x162, %edx            # imm = 0x162
callq 0x31a0
leaq 0x3653(%rip), %rdi      # 0x95c2
leaq 0x3353(%rip), %rsi      # 0x92c9
leaq 0x3613(%rip), %rcx      # 0x9590
movl $0x176, %edx            # imm = 0x176
callq 0x31a0
nop