// File: /workspace/github_c_makefile_star2_O1/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 $0xa8, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r15
leaq 0x20(%rsp), %rdi
movl $0x88, %edx
xorl %esi, %esi
callq 0x31e0
movw $0x0, 0x16(%rsp)
cmpw $0x0, 0x4(%r13)
je 0xe8d0
movq 0x10(%r13), %rax
movzwl 0x8(%rax), %ecx
cmpl $0x1, %ecx
je 0xe911
cmpl $0x1c, %ecx
jne 0xe950
movq %r15, 0x18(%rsp)
movq %r14, %r15
leaq 0x28(%rsp), %rbp
movl $0xa, %r14d
jmp 0xe924
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xe9a3
leaq 0x148be(%rip), %rsi     # 0x231a8
leaq 0x143ea(%rip), %rdx     # 0x22cdb
leaq 0x148d3(%rip), %r8      # 0x231cb
xorl %r12d, %r12d
movl $0x3, %edi
movl $0x27, %ecx
xorl %eax, %eax
callq 0x17d92
jmp 0xe9a3
movq %r15, 0x18(%rsp)
movq %r14, %r15
leaq 0x24(%rsp), %rbp
movl $0x2, %r14d
movq (%rax), %rsi
leaq 0x148c1(%rip), %rdx     # 0x231ef
leaq 0x20(%rsp), %rdi
movl %r14d, %ecx
callq 0x186dc
testl %eax, %eax
je 0xe9e5
xorl %r12d, %r12d
movq %r15, %r14
movq 0x18(%rsp), %r15
jmp 0xe9a3
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xe9a3
movq 0x10(%r13), %rax
movzwl 0x8(%rax), %edi
callq 0x1a346
movq 0x10(%r13), %rcx
movq (%rcx), %rcx
movq %rcx, (%rsp)
leaq 0x1482a(%rip), %rsi     # 0x231a8
leaq 0x14356(%rip), %rdx     # 0x22cdb
leaq 0x1484c(%rip), %r8      # 0x231d8
xorl %r12d, %r12d
movl $0x3, %edi
movl $0x35, %ecx
movq %rax, %r9
xorl %eax, %eax
callq 0x17d92
testq %r12, %r12
je 0xe9b8
movq %r12, %rdi
callq 0x1a1dd
movq %r12, %rdi
callq 0x3450
testq %rbx, %rbx
je 0xe9d1
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r14, %r9
callq *%rbx
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
orw $0x121, 0x16(%rsp)      # imm = 0x121
movl $0x20, %edi
callq 0x34b0
testq %rax, %rax
je 0xea5c
movq %rax, %r12
movzwl (%r13), %esi
movq 0x10(%r13), %rcx
leaq 0x16(%rsp), %rdx
movq %rax, %rdi
movq %rbp, %r8
movl %r14d, %r9d
callq 0x83fd
testl %eax, %eax
je 0xea9d
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
movq %r15, %r14
jl 0xe949
leaq 0x14770(%rip), %rsi     # 0x231a8
leaq 0x1429c(%rip), %rdx     # 0x22cdb
leaq 0x147af(%rip), %r8      # 0x231f5
movl $0x3, %edi
movl $0x49, %ecx
xorl %eax, %eax
callq 0x17d92
jmp 0xe949
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xe946
leaq 0x14732(%rip), %rsi     # 0x231a8
leaq 0x1425e(%rip), %rdx     # 0x22cdb
leaq 0x14e1f(%rip), %r8      # 0x238a3
xorl %r12d, %r12d
movl $0x3, %edi
movl $0x44, %ecx
xorl %eax, %eax
callq 0x17d92
jmp 0xe946
testq %rbx, %rbx
movq 0x18(%rsp), %rdi
je 0xe9d1
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
movq %r15, %r9
jmp 0xe9cf