// File: /workspace/github_c_makefile_star2_O3/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 0x11526
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r12
addq $0x58, %r12
movq %r12, %rdi
callq 0x39f8
testq %rax, %rax
je 0x11566
movq %rax, %r13
movq %r14, %rdi
movl %r15d, %esi
callq 0x116cf
testq %rax, %rax
je 0x1160c
movq -0x8(%r13), %rcx
movq %rcx, 0x18(%rax)
movq %rax, -0x8(%r13)
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x176e5
cmpl $0x8, (%rax)
jl 0x116be
movl %r15d, %edi
movq %r14, %rsi
callq 0x17e5b
movq %rax, (%rsp)
leaq 0x1220f(%rip), %rsi     # 0x23716
leaq 0x1221c(%rip), %rdx     # 0x2372a
leaq 0x12237(%rip), %r8      # 0x2374c
xorl %ebp, %ebp
movl $0x8, %edi
movl $0x111, %ecx            # imm = 0x111
jmp 0x115fd
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x116be
leaq 0x121d4(%rip), %rsi     # 0x23716
leaq 0x121e1(%rip), %rdx     # 0x2372a
leaq 0x110ca(%rip), %r8      # 0x2261a
movl $0x3, %edi
movl $0xf6, %ecx
xorl %eax, %eax
callq 0x1771e
jmp 0x116be
movl $0x1, %edi
movl $0x38, %esi
callq 0x3240
testq %rax, %rax
je 0x11645
movq %rax, %r13
movq %rbx, %rdi
callq 0x3610
movq %rax, %rbp
movq %rax, (%r13)
movq %rax, 0x10(%r13)
movq %r14, %rdi
movl %r15d, %esi
callq 0x116cf
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x11679
addq $0x10, %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x379c
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x176e5
cmpl $0x8, (%rax)
jl 0x116be
movl %r15d, %edi
movq %r14, %rsi
callq 0x17e5b
movq %rax, (%rsp)
leaq 0x12133(%rip), %rsi     # 0x23716
leaq 0x12140(%rip), %rdx     # 0x2372a
leaq 0x1215b(%rip), %r8      # 0x2374c
xorl %ebp, %ebp
movl $0x8, %edi
movl $0x103, %ecx            # imm = 0x103
movq %rbx, %r9
xorl %eax, %eax
callq 0x1771e
jmp 0x116be
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x116be
leaq 0x120ee(%rip), %rsi     # 0x23716
leaq 0x120fb(%rip), %rdx     # 0x2372a
leaq 0x1212c(%rip), %r8      # 0x23762
movl $0x3, %edi
movl $0x10a, %ecx            # imm = 0x10A
jmp 0x1155a
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x11689
leaq 0x120be(%rip), %rsi     # 0x23716
leaq 0x12124(%rip), %rdx     # 0x23783
leaq 0x1224d(%rip), %r8      # 0x238b3
movl $0x3, %edi
movl $0x4a, %ecx
xorl %eax, %eax
callq 0x1771e
jmp 0x11689
movq %rbp, %rdi
callq 0x3450
movq %r13, %rdi
callq 0x3450
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x116be
leaq 0x12075(%rip), %rsi     # 0x23716
leaq 0x12082(%rip), %rdx     # 0x2372a
leaq 0x12085(%rip), %r8      # 0x23734
movl $0x3, %edi
movl $0xfe, %ecx
jmp 0x1155a
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq