// File: davidgfnet[P]dns-db/dns_block.cc
// Function: DNS_DB::DnsBlock::replaceDomainIpv4(char const*, IPv4_Record const&, IPv4_Record const&)
bool DNS_DB::DnsBlock::replaceDomainIpv4(const char * domint, const IPv4_Record & oldrec, const IPv4_Record & newrec) {
	DNS_DB::DnsBlock::InternalBlock * ptr = lookupDomain(domint);
	if (ptr == 0)
		return false;

	do {
		if (ptr->header & DNS_DB::DnsBlock::flagDomain) {
			for (int i = 0; i < 2; i++)
				if (ptr->data.domain.records[i] == oldrec) {
					ptr->data.domain.records[i] = newrec;
					return true;
				}
		}
		else {
			for (int i = 0; i < 5; i++)
				if (ptr->data.records.records[i] == oldrec) {
					ptr->data.records.records[i] = newrec;
					return true;
				}
		}

		ptr++;
	} while ( ptr != endptr && (ptr->header & DNS_DB::DnsBlock::flagUsed) && !(ptr->header & DNS_DB::DnsBlock::flagDomain));

	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x40(%rbp)
movq -0x18(%rbp), %rsi
callq 0xacd0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xb63d
movb $0x0, -0x1(%rbp)
jmp 0xb798
jmp 0xb63f
movq -0x30(%rbp), %rax
movzbl (%rax), %eax
movzbl 0x10cbc(%rip), %ecx     # 0x1c309
andl %ecx, %eax
cmpl $0x0, %eax
je 0xb6c6
movl $0x0, -0x34(%rbp)
cmpl $0x2, -0x34(%rbp)
jge 0xb6c4
movq -0x30(%rbp), %rdi
addq $0x1, %rdi
addq $0x23, %rdi
movslq -0x34(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0xb7b0
testb $0x1, %al
jne 0xb687
jmp 0xb6b7
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
addq $0x1, %rax
addq $0x23, %rax
movslq -0x34(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movb $0x1, -0x1(%rbp)
jmp 0xb798
jmp 0xb6b9
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xb65b
jmp 0xb735
movl $0x0, -0x38(%rbp)
cmpl $0x5, -0x38(%rbp)
jge 0xb733
movq -0x30(%rbp), %rdi
addq $0x1, %rdi
addq $0x3, %rdi
movslq -0x38(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0xb7b0
testb $0x1, %al
jne 0xb6f9
jmp 0xb726
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
addq $0x1, %rax
addq $0x3, %rax
movslq -0x38(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
movb $0x1, -0x1(%rbp)
jmp 0xb798
jmp 0xb728
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xb6cd
jmp 0xb735
movq -0x30(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rdx
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq 0x8(%rdx), %rcx
movb %al, -0x41(%rbp)
je 0xb789
movq -0x30(%rbp), %rax
movzbl (%rax), %ecx
movzbl 0x10ba6(%rip), %eax     # 0x1c308
andl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x41(%rbp)
je 0xb789
movq -0x30(%rbp), %rax
movzbl (%rax), %eax
movzbl 0x10b8d(%rip), %ecx     # 0x1c309
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0xb63f
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)