// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movw %si, %ax
movq %rdi, -0x10(%rbp)
movw %ax, -0x12(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq -0x10(%rbp), %rdi
callq 0x270f0
cmpl $0x0, %eax
je 0xbcb3
jmp 0xbc73
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0xbca5
movl $0x3, %edi
leaq 0x29ef7(%rip), %rsi     # 0x35b82
leaq 0x29efe(%rip), %rdx     # 0x35b90
movl $0x66, %ecx
leaq 0x29f04(%rip), %r8      # 0x35ba2
movb $0x0, %al
callq 0x243b0
jmp 0xbca7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xbee3
movw -0x12(%rbp), %cx
movq -0x10(%rbp), %rax
movw %cx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x26fd0
cmpq $0x0, -0x28(%rbp)
je 0xbd42
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x271c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0xbd38
jmp 0xbcf8
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0xbd2a
movl $0x3, %edi
leaq 0x29e72(%rip), %rsi     # 0x35b82
leaq 0x29e79(%rip), %rdx     # 0x35b90
movl $0x70, %ecx
leaq 0x29e94(%rip), %r8      # 0x35bb7
movb $0x0, %al
callq 0x243b0
jmp 0xbd2c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xbee3
movq -0x10(%rbp), %rax
movw $0x1, 0x4(%rax)
cmpq $0x0, -0x28(%rbp)
je 0xbedc
cmpq $0x0, -0x30(%rbp)
je 0xbedc
movl $0x20, %edi
callq 0x34d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xbdc3
jmp 0xbd7a
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0xbdac
movl $0x3, %edi
leaq 0x29df0(%rip), %rsi     # 0x35b82
leaq 0x29df7(%rip), %rdx     # 0x35b90
movl $0x79, %ecx
leaq 0x29e27(%rip), %r8      # 0x35bcc
movb $0x0, %al
callq 0x243b0
jmp 0xbdae
movq -0x10(%rbp), %rdi
callq 0x27870
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xbee3
movq -0x10(%rbp), %rax
movw $0x1, 0x6(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
callq 0x3620
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movw 0x8(%rax), %cx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movw %cx, 0x8(%rax)
movq -0x28(%rbp), %rax
movw 0xa(%rax), %cx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movw %cx, 0xa(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl $0x258, 0xc(%rax)       # imm = 0x258
movl -0x34(%rbp), %edx
movl $0x10, %eax
movl $0x4, %ecx
cmpl $0x2, %edx
cmovel %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movw %cx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movzwl 0x10(%rax), %eax
movl %eax, %edi
callq 0x34d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x18(%rax)
jne 0xbeb9
jmp 0xbe73
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0xbea5
movl $0x3, %edi
leaq 0x29cf7(%rip), %rsi     # 0x35b82
leaq 0x29cfe(%rip), %rdx     # 0x35b90
movl $0x85, %ecx
leaq 0x29d2e(%rip), %r8      # 0x35bcc
movb $0x0, %al
callq 0x243b0
jmp 0xbea7
movq -0x10(%rbp), %rdi
callq 0x27870
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xbee3
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movzwl 0x10(%rax), %eax
movl %eax, %edx
callq 0x32d0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)