// File: /workspace/github_c_makefile_star2_O2/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 0x31f0
andw $0x0, 0xe(%rsp)
cmpw $0x0, 0x4(%r12)
je 0xdda2
movq 0x10(%r12), %rax
movzwl 0x8(%rax), %ecx
cmpl $0x1, %ecx
je 0xddd9
cmpl $0x1c, %ecx
jne 0xde81
leaq 0x18(%rsp), %rbp
pushq $0xa
jmp 0xdde0
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xdef9
leaq 0x133f7(%rip), %rsi     # 0x211b0
leaq 0x12f23(%rip), %rdx     # 0x20ce3
leaq 0x1340c(%rip), %r8      # 0x211d3
pushq $0x3
popq %rdi
pushq $0x27
popq %rcx
xorl %eax, %eax
callq 0x1662e
jmp 0xdef9
leaq 0x14(%rsp), %rbp
pushq $0x2
popq %r14
movq (%rax), %rsi
leaq 0x1340b(%rip), %rdx     # 0x211f7
leaq 0x10(%rsp), %rdi
movl %r14d, %ecx
callq 0x16f67
testl %eax, %eax
jne 0xdef9
movw $0x121, 0xe(%rsp)       # imm = 0x121
pushq $0x20
popq %rdi
callq 0x34c0
testq %rax, %rax
je 0xdece
movzwl (%r12), %esi
movq 0x10(%r12), %rcx
leaq 0xe(%rsp), %rdx
movq %rax, %r12
movq %rax, %rdi
movq %rbp, %r8
movl %r14d, %r9d
callq 0x7db0
testl %eax, %eax
je 0xdf24
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xde6f
leaq 0x1335c(%rip), %rsi     # 0x211b0
leaq 0x12e88(%rip), %rdx     # 0x20ce3
leaq 0x1339b(%rip), %r8      # 0x211fd
pushq $0x3
popq %rdi
pushq $0x49
popq %rcx
xorl %eax, %eax
callq 0x1662e
movq %r12, %rdi
callq 0x188ce
movq %r12, %rdi
callq 0x3460
jmp 0xdef9
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xdef9
movq 0x10(%r12), %rax
movzwl 0x8(%rax), %edi
callq 0x18a25
movq 0x10(%r12), %rcx
movq (%rcx), %rcx
movq %rcx, (%rsp)
leaq 0x13302(%rip), %rsi     # 0x211b0
leaq 0x12e2e(%rip), %rdx     # 0x20ce3
leaq 0x13324(%rip), %r8      # 0x211e0
pushq $0x3
popq %rdi
pushq $0x35
popq %rcx
movq %rax, %r9
xorl %eax, %eax
callq 0x1662e
jmp 0xdef9
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xdef9
leaq 0x132cf(%rip), %rsi     # 0x211b0
leaq 0x12dfb(%rip), %rdx     # 0x20ce3
leaq 0x139c4(%rip), %r8      # 0x218b3
pushq $0x3
popq %rdi
pushq $0x44
jmp 0xddcc
testq %rbx, %rbx
je 0xdf10
pushq $-0x1
popq %rsi
movq %r15, %rdi
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 0xdf10
pushq $0x1
popq %r8
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
jmp 0xdf0b