// File: davidgfnet[P]dns-db/dns_index.cc
// Function: DNS_DB::DnsIndex::addIp4Record(char const*, IPv4_Record const&)
void DNS_DB::DnsIndex::addIp4Record(const char * domain, const IPv4_Record & record) {
	char domint[MAX_DNS_SIZE];
	if (!domain2idom(domain, domint)) {
		fprintf(stderr, "Domain too long!\n");
		return;
	}

	int n = lookupNode(domint);
	DNS_DB::DnsBlockPtr blk = database->getBlock(nodes[n].dnsblock_id);

	if (!blk->addDomainIpv4(domint, record)) {
		// Ops, just split the Block in two, must be full
		unsigned int nwblk_id = this->current_id++;
		DnsBlockPtr newblk = database->getBlock(nwblk_id);
		blk->splitBlock(domint, newblk);

		char nodemax[MAX_DNS_SIZE];
		char dommax [MAX_DNS_SIZE];
		getBlkMax(n, nodemax);
		newblk->getMinDomain(dommax);

		// Set new block boundaries
		addBlock(nwblk_id, dommax, nodemax);

		// Just recalculate the max for the other block
		setBlkMinMax(n, 0, dommax);

		// Redo
		n = lookupNode(domint);
		blk = database->getBlock(nodes[n].dnsblock_id);

		bool r = blk->addDomainIpv4(domint, record);
		assert(r);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xd720
testb $0x1, %al
jne 0x7b80
movq 0x14466(%rip), %rax     # 0x1bfd0
movq (%rax), %rdi
leaq 0xb621(%rip), %rsi      # 0x13195
movb $0x0, %al
callq 0x43f0
jmp 0x7db7
movq -0xf0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movq %rsi, -0x100(%rbp)
callq 0x7420
movq -0xf0(%rbp), %rdi
movl %eax, -0x44(%rbp)
movq 0x18(%rdi), %rax
movq %rax, -0x110(%rbp)
movslq -0x44(%rbp), %rsi
callq 0x8610
movq -0x110(%rbp), %rsi
movl 0x46(%rax), %edx
leaq -0x58(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x8650
movq -0x108(%rbp), %rdi
callq 0x8680
movq -0x100(%rbp), %rsi
movq %rax, %rdi
movq -0x18(%rbp), %rdx
callq 0xb800
movb %al, -0xf1(%rbp)
jmp 0x7bf6
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0x7dae
jmp 0x7c06
movq -0xf0(%rbp), %rax
movl 0x20(%rax), %ecx
movl %ecx, %edx
incl %edx
movl %edx, 0x20(%rax)
movl %ecx, -0x68(%rbp)
movq 0x18(%rax), %rsi
movl -0x68(%rbp), %edx
leaq -0x78(%rbp), %rdi
callq 0x8650
jmp 0x7c2c
leaq -0x58(%rbp), %rdi
callq 0x8680
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0xba70
jmp 0x7c47
movq -0xf0(%rbp), %rdi
movl -0x44(%rbp), %esi
leaq -0xa0(%rbp), %rdx
callq 0x7de0
jmp 0x7c5f
leaq -0x78(%rbp), %rdi
callq 0x8680
movq %rax, %rdi
leaq -0xd0(%rbp), %rsi
callq 0xbcd0
jmp 0x7c79
movq -0xf0(%rbp), %rdi
movl -0x68(%rbp), %esi
leaq -0xd0(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
callq 0x7e30
jmp 0x7c98
movq -0xf0(%rbp), %rdi
movl -0x44(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
leaq -0xd0(%rbp), %rcx
callq 0x7f60
jmp 0x7cb4
movq -0xf0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x7420
movq -0xf0(%rbp), %rdi
movl %eax, -0x44(%rbp)
movq 0x18(%rdi), %rax
movq %rax, -0x118(%rbp)
movslq -0x44(%rbp), %rsi
callq 0x8610
movq -0x118(%rbp), %rsi
movl 0x46(%rax), %edx
leaq -0xe0(%rbp), %rdi
callq 0x8650
jmp 0x7cfa
leaq -0x58(%rbp), %rdi
movq %rdi, -0x128(%rbp)
leaq -0xe0(%rbp), %rsi
movq %rsi, -0x130(%rbp)
callq 0x8760
movq -0x130(%rbp), %rdi
callq 0x5f20
movq -0x128(%rbp), %rdi
callq 0x8680
movq %rax, %rdi
movq -0x18(%rbp), %rdx
leaq -0x40(%rbp), %rsi
callq 0xb800
movb %al, -0x119(%rbp)
jmp 0x7d48
movb -0x119(%rbp), %al
andb $0x1, %al
movb %al, -0xe1(%rbp)
testb $0x1, -0xe1(%rbp)
je 0x7d61
jmp 0x7da5
leaq 0xbb88(%rip), %rdi      # 0x138f0
leaq 0xb3ab(%rip), %rsi      # 0x1311a
movl $0x9f, %edx
leaq 0xb42c(%rip), %rcx      # 0x131a7
callq 0x41e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x7dc0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5f20
jmp 0x7dc0
leaq -0x78(%rbp), %rdi
callq 0x5f20
leaq -0x58(%rbp), %rdi
callq 0x5f20
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x5f20
movq -0x60(%rbp), %rdi
callq 0x44f0
nopw %cs:(%rax,%rax)