// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/ns_msg.c
// Function: ns_msg_clone
ns_msg_t* ns_msg_clone(const ns_msg_t *msg)
{
	ns_msg_t* copy;
	copy = (ns_msg_t*)malloc(sizeof(ns_msg_t));
	if (!copy) {
		loge("alloc \n");
		return NULL;
	}

	memset(copy, 0, sizeof(ns_msg_t));
	
	copy->id = msg->id;
	copy->flags = msg->flags;
	if (msg->qrs) {
		copy->qrs = ns_qr_clone(msg->qrs, msg->qdcount);
		if (!copy->qrs) {
			loge("ns_qr_clone() error\n");
			free(copy);
			return NULL;
		}
	}
	copy->qdcount = msg->qdcount;

	if (msg->rrs) {
		copy->rrs = ns_rr_clone(msg->rrs, ns_rrcount(msg));
		if (!copy->rrs) {
			loge("ns_rr_clone() error\n");
			ns_msg_free(copy);
			return NULL;
		}
	}

	copy->ancount = msg->ancount;
	copy->nscount = msg->nscount;
	copy->arcount = msg->arcount;

	return copy;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl $0x20, %edi
callq 0x34d0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x276c4
jmp 0x27683
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x276b5
movl $0x3, %edi
leaq 0x10d79(%rip), %rsi     # 0x38414
leaq 0x10d97(%rip), %rdx     # 0x38439
movl $0x11f, %ecx            # imm = 0x11F
leaq 0xe51e(%rip), %r8       # 0x35bcc
movb $0x0, %al
callq 0x243b0
jmp 0x276b7
movq $0x0, -0x8(%rbp)
jmp 0x27857
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x3200
movq -0x10(%rbp), %rax
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw 0x2(%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x27776
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movzwl 0x4(%rax), %esi
callq 0x271c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x27774
jmp 0x2772a
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x2775c
movl $0x3, %edi
leaq 0x10cd2(%rip), %rsi     # 0x38414
leaq 0x10cf0(%rip), %rdx     # 0x38439
movl $0x12a, %ecx            # imm = 0x12A
leaq 0xe462(%rip), %r8       # 0x35bb7
movb $0x0, %al
callq 0x243b0
jmp 0x2775e
movq -0x18(%rbp), %rdi
callq 0x3460
movq $0x0, -0x8(%rbp)
jmp 0x27857
jmp 0x27776
movq -0x10(%rbp), %rax
movw 0x4(%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x2781f
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movzwl 0x6(%rax), %esi
movq -0x10(%rbp), %rax
movzwl 0x8(%rax), %eax
addl %eax, %esi
movq -0x10(%rbp), %rax
movzwl 0xa(%rax), %eax
addl %eax, %esi
callq 0x27300
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x2781d
jmp 0x277d6
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x27808
movl $0x3, %edi
leaq 0x10c26(%rip), %rsi     # 0x38414
leaq 0x10c44(%rip), %rdx     # 0x38439
movl $0x134, %ecx            # imm = 0x134
leaq 0x10c45(%rip), %r8      # 0x38446
movb $0x0, %al
callq 0x243b0
jmp 0x2780a
movq -0x18(%rbp), %rdi
callq 0x27870
movq $0x0, -0x8(%rbp)
jmp 0x27857
jmp 0x2781f
movq -0x10(%rbp), %rax
movw 0x6(%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x6(%rax)
movq -0x10(%rbp), %rax
movw 0x8(%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x8(%rax)
movq -0x10(%rbp), %rax
movw 0xa(%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0xa(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)