// File: /workspace/github_c_makefile_star2_O2/GangZhuo[P]dohclient/src/channel_hosts.c
// Function: hosts_add
int hosts_add(channel_t *ctx, const char *domain, const void *ip, int family)
{
	hosts_t *c = (hosts_t*)ctx;
	hosts_item_t *item;
	struct rbnode_t *rbn;
	ipnode_t *ipnode;

	if (!domain || !ip || !family) {
		loge("invalid arguments\n");
		return -1;
	}

	rbn = rbtree_lookup(&c->dic, domain);
	if (!rbn) {
		item = hosts_item_new(domain, ip, family);
		if (!item) {
			loge("hosts_item_new() error\n");
			return -1;
		}

		rbtree_insert(&c->dic, &item->node);
		logv("hosts added: %s - %s\n", domain, get_ipname(family, ip));
	}
	else {
		item = rbtree_container_of(rbn, hosts_item_t, node);

		ipnode = ipnode_new(ip, family);
		if (!ipnode) {
			loge("ipnode_new() error\n");
			return -1;
		}

		ipnode->next = item->iplist;
		item->iplist = ipnode;

		logv("hosts added: %s - %s\n", domain, get_ipname(family, ip));
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r15d
testq %rsi, %rsi
setne %al
testq %rdx, %rdx
setne %cl
andb %al, %cl
testl %r15d, %r15d
setne %al
testb %al, %cl
je 0x10b74
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r12
addq $0x58, %r12
movq %r12, %rdi
callq 0x38ef
testq %rax, %rax
je 0x10bb0
movq %rax, %r13
movq %r14, %rdi
movl %r15d, %esi
callq 0x10d07
testq %rax, %rax
je 0x10c50
movq -0x8(%r13), %rcx
movq %rcx, 0x18(%rax)
movq %rax, -0x8(%r13)
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x165f5
cmpl $0x8, (%rax)
jl 0x10cf6
movl %r15d, %edi
movq %r14, %rsi
callq 0x16d6a
movq %rax, (%rsp)
leaq 0x10bbf(%rip), %rsi     # 0x21716
leaq 0x10bcc(%rip), %rdx     # 0x2172a
leaq 0x10be7(%rip), %r8      # 0x2174c
xorl %ebp, %ebp
pushq $0x8
popq %rdi
movl $0x111, %ecx            # imm = 0x111
jmp 0x10c41
xorl %eax, %eax
callq 0x165f5
pushq $-0x1
popq %rbp
cmpl $0x3, (%rax)
jl 0x10cf6
leaq 0x10b88(%rip), %rsi     # 0x21716
leaq 0x10b95(%rip), %rdx     # 0x2172a
leaq 0xfa7e(%rip), %r8       # 0x2061a
pushq $0x3
popq %rdi
movl $0xf6, %ecx
xorl %eax, %eax
callq 0x1662e
jmp 0x10cf6
pushq $0x1
popq %rdi
pushq $0x38
popq %rsi
callq 0x3250
testq %rax, %rax
je 0x10c85
movq %rax, %r13
movq %rbx, %rdi
callq 0x3620
movq %rax, %rbp
movq %rax, (%r13)
movq %rax, 0x10(%r13)
movq %r14, %rdi
movl %r15d, %esi
callq 0x10d07
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x10cb5
addq $0x10, %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x378c
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x165f5
cmpl $0x8, (%rax)
jl 0x10cf6
movl %r15d, %edi
movq %r14, %rsi
callq 0x16d6a
movq %rax, (%rsp)
leaq 0x10aed(%rip), %rsi     # 0x21716
leaq 0x10afa(%rip), %rdx     # 0x2172a
leaq 0x10b15(%rip), %r8      # 0x2174c
xorl %ebp, %ebp
pushq $0x8
popq %rdi
movl $0x103, %ecx            # imm = 0x103
movq %rbx, %r9
xorl %eax, %eax
callq 0x1662e
jmp 0x10cf6
xorl %eax, %eax
callq 0x165f5
pushq $-0x1
popq %rbp
cmpl $0x3, (%rax)
jl 0x10cf6
leaq 0x10aac(%rip), %rsi     # 0x21716
leaq 0x10ab9(%rip), %rdx     # 0x2172a
leaq 0x10aea(%rip), %r8      # 0x21762
pushq $0x3
popq %rdi
movl $0x10a, %ecx            # imm = 0x10A
jmp 0x10ba4
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x10cc5
leaq 0x10a7e(%rip), %rsi     # 0x21716
leaq 0x10ae4(%rip), %rdx     # 0x21783
leaq 0x10c0d(%rip), %r8      # 0x218b3
pushq $0x3
popq %rdi
pushq $0x4a
popq %rcx
xorl %eax, %eax
callq 0x1662e
jmp 0x10cc5
movq %rbp, %rdi
callq 0x3460
movq %r13, %rdi
callq 0x3460
xorl %eax, %eax
callq 0x165f5
pushq $-0x1
popq %rbp
cmpl $0x3, (%rax)
jl 0x10cf6
leaq 0x10a3b(%rip), %rsi     # 0x21716
leaq 0x10a48(%rip), %rdx     # 0x2172a
leaq 0x10a4b(%rip), %r8      # 0x21734
pushq $0x3
popq %rdi
movl $0xfe, %ecx
jmp 0x10ba4
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq