// File: /workspace/github_c_makefile_star2_O1/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, %ebp
testq %rsi, %rsi
setne %al
testq %rdx, %rdx
setne %cl
andb %al, %cl
testl %ebp, %ebp
setne %al
testb %al, %cl
je 0x11a9e
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
addq $0x58, %r15
movq %r15, %rdi
callq 0x390c
testq %rax, %rax
je 0x11adf
movq %rax, %r12
movq %r14, %rdi
movl %ebp, %esi
callq 0x11c63
testq %rax, %rax
je 0x11b4c
movq -0x8(%r12), %rcx
movq %rcx, 0x18(%rax)
movq %rax, -0x8(%r12)
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x17d59
cmpl $0x8, (%rax)
jl 0x11c1b
movl %ebp, %edi
movq %r14, %rsi
callq 0x184bf
movq %rax, (%rsp)
leaq 0x11c88(%rip), %rsi     # 0x23706
leaq 0x11c95(%rip), %rdx     # 0x2371a
leaq 0x11cb0(%rip), %r8      # 0x2373c
xorl %r15d, %r15d
movl $0x8, %edi
movl $0x111, %ecx            # imm = 0x111
jmp 0x11c11
xorl %eax, %eax
callq 0x17d59
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x11c1b
leaq 0x11c4b(%rip), %rsi     # 0x23706
leaq 0x11c58(%rip), %rdx     # 0x2371a
leaq 0x10b71(%rip), %r8      # 0x2263a
movl $0x3, %edi
movl $0xf6, %ecx
xorl %eax, %eax
callq 0x17d92
jmp 0x11c1b
movl $0x38, %edi
callq 0x34b0
testq %rax, %rax
je 0x11b86
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x30(%rax)
movq %rbx, %rdi
callq 0x3610
movq %rax, %r13
movq %rax, (%r12)
movq %rax, 0x10(%r12)
movq %r14, %rdi
movl %ebp, %esi
callq 0x11c63
movq %rax, 0x8(%r12)
testq %rax, %rax
jne 0x11bbe
movq %r13, %rdi
callq 0x3450
movq %r12, %rdi
callq 0x3450
xorl %r12d, %r12d
jmp 0x11bbe
xorl %eax, %eax
callq 0x17d59
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x11c1b
leaq 0x11b9d(%rip), %rsi     # 0x23706
leaq 0x11baa(%rip), %rdx     # 0x2371a
leaq 0x11bdb(%rip), %r8      # 0x23752
movl $0x3, %edi
movl $0x10a, %ecx            # imm = 0x10A
jmp 0x11ad3
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x11bbe
leaq 0x11b6a(%rip), %rsi     # 0x23706
leaq 0x11bd0(%rip), %rdx     # 0x23773
leaq 0x11cf9(%rip), %r8      # 0x238a3
xorl %r12d, %r12d
movl $0x3, %edi
movl $0x4a, %ecx
xorl %eax, %eax
callq 0x17d92
testq %r12, %r12
je 0x11c2d
addq $0x10, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x379c
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x17d59
cmpl $0x8, (%rax)
jl 0x11c1b
movl %ebp, %edi
movq %r14, %rsi
callq 0x184bf
movq %rax, (%rsp)
leaq 0x11b10(%rip), %rsi     # 0x23706
leaq 0x11b1d(%rip), %rdx     # 0x2371a
leaq 0x11b38(%rip), %r8      # 0x2373c
xorl %r15d, %r15d
movl $0x8, %edi
movl $0x103, %ecx            # imm = 0x103
movq %rbx, %r9
xorl %eax, %eax
callq 0x17d92
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
callq 0x17d59
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x11c1b
leaq 0x11ac0(%rip), %rsi     # 0x23706
leaq 0x11acd(%rip), %rdx     # 0x2371a
leaq 0x11ad0(%rip), %r8      # 0x23724
movl $0x3, %edi
movl $0xfe, %ecx
jmp 0x11ad3