// File: /workspace/github_c_makefile_star2_O3/GangZhuo[P]dohclient/src/channel.c
// Function: channel_build_msg
int channel_build_msg(
	ns_msg_t *msg,
	const uint16_t id,
	const ns_flags_t *flags,
	const ns_qr_t* qr,
	void *ip, int family)
{
	if (init_ns_msg(msg)) {
		loge("init_ns_msg() error\n");
		return -1;
	}

	msg->id = id;
	ns_set_flags(msg, flags);

	if (qr) {
		msg->qrs = ns_qr_clone(qr, 1);
		if (!msg->qrs) {
			loge("ns_qr_clone() error\n");
			return -1;
		}
		msg->qdcount = 1;
	}

	if (qr && ip) {
		msg->rrs = (ns_rr_t*)malloc(sizeof(ns_rr_t));
		if (!msg->rrs) {
			loge("alloc \n");
			ns_msg_free(msg);
			return -1;
		}
		msg->ancount = 1;
		msg->rrs->name = strdup(qr->qname);
		msg->rrs->type = qr->qtype;
		msg->rrs->cls = qr->qclass;
		msg->rrs->ttl = 600;
		msg->rrs->rdlength = family == AF_INET ? 4 : 16;
		msg->rrs->rdata = (char*)malloc(msg->rrs->rdlength);
		if (!msg->rrs->rdata) {
			loge("alloc \n");
			ns_msg_free(msg);
			return -1;
		}

		memcpy(msg->rrs->rdata, ip, msg->rrs->rdlength);
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %r15d
movq %r8, %r14
movq %rcx, %r12
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %rbx
callq 0x19496
testl %eax, %eax
je 0x816a
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x82d8
leaq 0x1a446(%rip), %rsi     # 0x2258c
leaq 0x1a44d(%rip), %rdx     # 0x2259a
leaq 0x1a458(%rip), %r8      # 0x225ac
movl $0x3, %edi
movl $0x66, %ecx
xorl %eax, %eax
callq 0x1771e
jmp 0x82d8
movw %bp, (%rbx)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x19445
xorl %ebp, %ebp
testq %r12, %r12
je 0x82d8
movq %r12, %rdi
movl $0x1, %esi
callq 0x194ee
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x8233
movw $0x1, 0x4(%rbx)
testq %r14, %r14
je 0x82d8
movl $0x20, %edi
callq 0x34b0
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x826c
movq %rax, %r13
movw $0x1, 0x6(%rbx)
movq (%r12), %rdi
callq 0x3610
movq %rax, (%r13)
movl 0x8(%r12), %eax
movl %eax, 0x8(%r13)
movl $0x258, 0xc(%r13)       # imm = 0x258
cmpl $0x2, %r15d
movl $0x4, %eax
movl $0x10, %ecx
cmovel %eax, %ecx
movw %cx, 0x10(%r13)
movl $0x4, %eax
movl $0x10, %r15d
cmoveq %rax, %r15
movq %r15, %rdi
callq 0x34b0
movq %rax, 0x18(%r13)
testq %rax, %rax
je 0x8299
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x32b0
jmp 0x82d8
xorl %eax, %eax
callq 0x176e5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x3, (%rax)
jl 0x82d8
leaq 0x1a33d(%rip), %rsi     # 0x2258c
leaq 0x1a344(%rip), %rdx     # 0x2259a
leaq 0x1a364(%rip), %r8      # 0x225c1
movl $0x3, %edi
movl $0x70, %ecx
jmp 0x815e
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x82cb
leaq 0x1a30d(%rip), %rsi     # 0x2258c
leaq 0x1a314(%rip), %rdx     # 0x2259a
leaq 0x1a349(%rip), %r8      # 0x225d6
movl $0x3, %edi
movl $0x79, %ecx
jmp 0x82c4
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x82cb
leaq 0x1a2e0(%rip), %rsi     # 0x2258c
leaq 0x1a2e7(%rip), %rdx     # 0x2259a
leaq 0x1a31c(%rip), %r8      # 0x225d6
movl $0x3, %edi
movl $0x85, %ecx
xorl %eax, %eax
callq 0x1771e
movq %rbx, %rdi
callq 0x19ae0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)