// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/channel_cache.c
// Function: cache_edit
int cache_edit(channel_t *ctx, const char *key, const ns_msg_t *msg)
{
	cache_t *c = (cache_t*)ctx;
	cache_item_t *item;
	struct rbnode_t *rbn;
	int ttl;
	ns_msg_t *newmsg;

	if (!key || !msg) {
		loge("invalid arguments\n");
		return -1;
	}

	if (!msg->qrs || !msg->rrs ||
		msg->qdcount < 1 || ns_rrcount(msg) < 1) {
		loge("invalid msg (qdcount=%d,ancount=%d,nscount=%d,arcount=%d) - %s\n",
			(int)msg->qdcount,
			(int)msg->ancount,
			(int)msg->nscount,
			(int)msg->arcount,
			key);
		return -1;
	}

	ttl = (int)ns_get_ttl(msg);

	/* no ttl */
	if (ttl < 1) {
		loge("no ttl\n");
		return -1;
	}

	rbn = rbtree_lookup(&c->dic, key);
	if (!rbn) {
		loge("item not exists - %s\n", key);
		return -1;
	}

	item = rbtree_container_of(rbn, cache_item_t, node);
	newmsg = ns_msg_clone(msg);
	if (!newmsg) {
		loge("ns_msg_clone() error\n");
		return -1;
	}
	ns_msg_free(item->msg);
	free(item->msg);
	item->msg = newmsg;
	update_expire(c, item, ttl);
	dllist_remove(&item->entry);
	cache_item_add(c, item);
	logi("cache updated: %s - %s\n", key, msg_answers(msg));
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x78, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xc26b
cmpq $0x0, -0x28(%rbp)
jne 0xc2ad
jmp 0xc26d
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0xc29f
movl $0x3, %edi
leaq 0x2996d(%rip), %rsi     # 0x35bf2
leaq 0x299cd(%rip), %rdx     # 0x35c59
movl $0xf8, %ecx
leaq 0x29978(%rip), %r8      # 0x35c10
movb $0x0, %al
callq 0x243b0
jmp 0xc2a1
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xc53e
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0xc2f1
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xc2f1
movq -0x28(%rbp), %rax
movzwl 0x4(%rax), %eax
cmpl $0x1, %eax
jl 0xc2f1
movq -0x28(%rbp), %rax
movzwl 0x6(%rax), %eax
movq -0x28(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
addl %ecx, %eax
cmpl $0x1, %eax
jge 0xc36c
jmp 0xc2f3
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0xc35e
movq -0x28(%rbp), %rax
movzwl 0x4(%rax), %r9d
movq -0x28(%rbp), %rax
movzwl 0x6(%rax), %ebx
movq -0x28(%rbp), %rax
movzwl 0x8(%rax), %r11d
movq -0x28(%rbp), %rax
movzwl 0xa(%rax), %r10d
movq -0x20(%rbp), %rax
movl $0x3, %edi
leaq 0x298c0(%rip), %rsi     # 0x35bf2
leaq 0x29920(%rip), %rdx     # 0x35c59
movl $0x103, %ecx            # imm = 0x103
leaq 0x2991f(%rip), %r8      # 0x35c64
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0xc360
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xc53e
movq -0x28(%rbp), %rdi
callq 0x27120
movl %eax, -0x44(%rbp)
cmpl $0x1, -0x44(%rbp)
jge 0xc3c0
jmp 0xc380
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0xc3b2
movl $0x3, %edi
leaq 0x2985a(%rip), %rsi     # 0x35bf2
leaq 0x298ba(%rip), %rdx     # 0x35c59
movl $0x10b, %ecx            # imm = 0x10B
leaq 0x298f9(%rip), %r8      # 0x35ca4
movb $0x0, %al
callq 0x243b0
jmp 0xc3b4
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xc53e
movq -0x30(%rbp), %rdi
addq $0x68, %rdi
movq -0x20(%rbp), %rsi
callq 0x3b10
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0xc422
jmp 0xc3de
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0xc414
movq -0x20(%rbp), %r9
movl $0x3, %edi
leaq 0x297f8(%rip), %rsi     # 0x35bf2
leaq 0x29858(%rip), %rdx     # 0x35c59
movl $0x111, %ecx            # imm = 0x111
leaq 0x29816(%rip), %r8      # 0x35c23
movb $0x0, %al
callq 0x243b0
jmp 0xc416
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xc53e
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
callq 0x27660
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0xc480
jmp 0xc440
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0xc472
movl $0x3, %edi
leaq 0x2979a(%rip), %rsi     # 0x35bf2
leaq 0x297fa(%rip), %rdx     # 0x35c59
movl $0x118, %ecx            # imm = 0x118
leaq 0x29841(%rip), %r8      # 0x35cac
movb $0x0, %al
callq 0x243b0
jmp 0xc474
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0xc53e
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x27870
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x3460
movq -0x50(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x44(%rbp), %edx
callq 0xc550
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xc5d0
movb $0x0, %al
callq 0x242d0
cmpl $0x6, (%rax)
jl 0xc535
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rdi
callq 0x27de0
movq -0x58(%rbp), %r9
movl $0x6, %edi
leaq 0x296db(%rip), %rsi     # 0x35bf2
leaq 0x2973b(%rip), %rdx     # 0x35c59
movl $0x121, %ecx            # imm = 0x121
leaq 0x29798(%rip), %r8      # 0x35cc2
movq %rax, (%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0xc537
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x78, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax,%rax)