// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1a583
cmpq $0x0, -0x20(%rbp)
je 0x1a583
cmpl $0x0, -0x24(%rbp)
jne 0x1a5c5
jmp 0x1a585
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1a5b7
movl $0x3, %edi
leaq 0x1c75d(%rip), %rsi     # 0x36cfa
leaq 0x1c76a(%rip), %rdx     # 0x36d0e
movl $0xf6, %ecx
leaq 0x1b660(%rip), %r8      # 0x35c10
movb $0x0, %al
callq 0x243b0
jmp 0x1a5b9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1a78b
movq -0x30(%rbp), %rdi
addq $0x58, %rdi
movq -0x18(%rbp), %rsi
callq 0x3b10
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x1a6ac
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x1a7a0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x1a642
jmp 0x1a602
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1a634
movl $0x3, %edi
leaq 0x1c6e0(%rip), %rsi     # 0x36cfa
leaq 0x1c6ed(%rip), %rdx     # 0x36d0e
movl $0xfe, %ecx
leaq 0x1c6eb(%rip), %r8      # 0x36d18
movb $0x0, %al
callq 0x243b0
jmp 0x1a636
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1a78b
movq -0x30(%rbp), %rdi
addq $0x58, %rdi
movq -0x38(%rbp), %rsi
addq $0x10, %rsi
callq 0x3790
movb $0x0, %al
callq 0x242d0
cmpl $0x8, (%rax)
jl 0x1a6a5
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x24(%rbp), %edi
movq -0x20(%rbp), %rsi
callq 0x24fe0
movq -0x50(%rbp), %r9
movl $0x8, %edi
leaq 0x1c673(%rip), %rsi     # 0x36cfa
leaq 0x1c680(%rip), %rdx     # 0x36d0e
movl $0x103, %ecx            # imm = 0x103
leaq 0x1c696(%rip), %r8      # 0x36d30
movq %rax, (%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0x1a6a7
jmp 0x1a784
xorl %eax, %eax
movq %rax, %rcx
addq $0x10, %rcx
subq %rcx, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1a8a0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x1a716
jmp 0x1a6d9
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1a70b
movl $0x3, %edi
leaq 0x1c609(%rip), %rsi     # 0x36cfa
leaq 0x1c616(%rip), %rdx     # 0x36d0e
movl $0x10a, %ecx            # imm = 0x10A
leaq 0x1c642(%rip), %r8      # 0x36d46
movb $0x0, %al
callq 0x243b0
jmp 0x1a70d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1a78b
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movb $0x0, %al
callq 0x242d0
cmpl $0x8, (%rax)
jl 0x1a780
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x24(%rbp), %edi
movq -0x20(%rbp), %rsi
callq 0x24fe0
movq -0x58(%rbp), %r9
movl $0x8, %edi
leaq 0x1c598(%rip), %rsi     # 0x36cfa
leaq 0x1c5a5(%rip), %rdx     # 0x36d0e
movl $0x111, %ecx            # imm = 0x111
leaq 0x1c5bb(%rip), %r8      # 0x36d30
movq %rax, (%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0x1a782
jmp 0x1a784
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)