// File: /workspace/github_c_makefile_star2_O3/GangZhuo[P]dohclient/src/channel_os.c
// Function: query
static int query(channel_t* ctx,
	const ns_msg_t* msg,
	channel_query_cb callback, void* state)
{
	sockaddr_t addr = { 0 };
	void* ip = (struct sockaddr_in*)&addr.addr;
	int family, r;
	ns_msg_t* result = NULL;
	ns_flags_t flg = { 0 };

	if (msg->qdcount <= 0) {
		loge("no question\n");
		goto error;
	}
	else if (msg->qrs->qtype == NS_QTYPE_A) {
		family = AF_INET;
		ip = &((struct sockaddr_in*)(&addr.addr))->sin_addr;
	}
	else if (msg->qrs->qtype == NS_QTYPE_AAAA) {
		family = AF_INET6;
		ip = &((struct sockaddr_in6*)(&addr.addr))->sin6_addr;
	}
	else {
		loge("invalid qtype %s - %s\n",
			ns_typename(msg->qrs->qtype),
			msg->qrs->qname);
		goto error;
	}

	r = host2addr(&addr, msg->qrs->qname, "55555", family);
	if (r) {
		goto error;
	}

	flg.qr = 1;
	flg.aa = 1;
	flg.ra = 1;

	result = (ns_msg_t*)malloc(sizeof(ns_msg_t));
	if (!result) {
		loge("alloc\n");
		goto error;
	}

	if (channel_build_msg(result, msg->id, &flg, msg->qrs, ip, family)) {
		loge("channel_build_msg() error\n");
		goto error;
	}

	if (callback)
		callback(ctx, 0, result, FALSE, TRUE, state);

	return 0;

error:
	if (result) {
		ns_msg_free(result);
		free(result);
	}
	if (callback)
		callback(ctx, -1, NULL, FALSE, FALSE, state);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %r13
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
leaq 0x10(%rsp), %rdi
movl $0x88, %edx
xorl %esi, %esi
callq 0x31e0
movw $0x0, 0xe(%rsp)
cmpw $0x0, 0x4(%r12)
je 0xe4a1
movq 0x10(%r12), %rax
movzwl 0x8(%rax), %ecx
cmpl $0x1, %ecx
je 0xe4dc
cmpl $0x1c, %ecx
jne 0xe58f
leaq 0x18(%rsp), %rbp
movl $0xa, %r14d
jmp 0xe4e7
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xe610
leaq 0x14cf8(%rip), %rsi     # 0x231b0
leaq 0x14824(%rip), %rdx     # 0x22ce3
leaq 0x14d0d(%rip), %r8      # 0x231d3
movl $0x3, %edi
movl $0x27, %ecx
xorl %eax, %eax
callq 0x1771e
jmp 0xe610
leaq 0x14(%rsp), %rbp
movl $0x2, %r14d
movq (%rax), %rsi
leaq 0x14d06(%rip), %rdx     # 0x231f7
leaq 0x10(%rsp), %rdi
movl %r14d, %ecx
callq 0x18078
testl %eax, %eax
jne 0xe610
movw $0x121, 0xe(%rsp)       # imm = 0x121
movl $0x20, %edi
callq 0x34b0
testq %rax, %rax
je 0xe5e0
movzwl (%r12), %esi
movq 0x10(%r12), %rcx
leaq 0xe(%rsp), %rdx
movq %rax, %r12
movq %rax, %rdi
movq %rbp, %r8
movl %r14d, %r9d
callq 0x8105
testl %eax, %eax
je 0xe63d
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xe57a
leaq 0x14c55(%rip), %rsi     # 0x231b0
leaq 0x14781(%rip), %rdx     # 0x22ce3
leaq 0x14c94(%rip), %r8      # 0x231fd
movl $0x3, %edi
movl $0x49, %ecx
xorl %eax, %eax
callq 0x1771e
movq %r12, %rdi
callq 0x19ae0
movq %r12, %rdi
callq 0x3450
jmp 0xe610
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xe610
movq 0x10(%r12), %rax
movzwl 0x8(%rax), %edi
callq 0x19c4d
movq 0x10(%r12), %rcx
movq (%rcx), %rcx
movq %rcx, (%rsp)
leaq 0x14bf4(%rip), %rsi     # 0x231b0
leaq 0x14720(%rip), %rdx     # 0x22ce3
leaq 0x14c16(%rip), %r8      # 0x231e0
movl $0x3, %edi
movl $0x35, %ecx
movq %rax, %r9
xorl %eax, %eax
callq 0x1771e
jmp 0xe610
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xe610
leaq 0x14bbd(%rip), %rsi     # 0x231b0
leaq 0x146e9(%rip), %rdx     # 0x22ce3
leaq 0x152b2(%rip), %r8      # 0x238b3
movl $0x3, %edi
movl $0x44, %ecx
jmp 0xe4d0
testq %rbx, %rbx
je 0xe629
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r13, %r9
callq *%rbx
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rbx, %rbx
je 0xe629
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
jmp 0xe624