// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
movl $0x88, %edx
callq 0x3200
leaq -0xb0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq $0x0, -0xc8(%rbp)
leaq -0xca(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x3200
movq -0x18(%rbp), %rax
movzwl 0x4(%rax), %eax
cmpl $0x0, %eax
jg 0x15362
jmp 0x15329
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1535b
movl $0x3, %edi
leaq 0x21469(%rip), %rsi     # 0x367aa
leaq 0x20f69(%rip), %rdx     # 0x362b1
movl $0x27, %ecx
leaq 0x21479(%rip), %r8      # 0x367cd
movb $0x0, %al
callq 0x243b0
jmp 0x1535d
jmp 0x15594
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzwl 0x8(%rax), %eax
cmpl $0x1, %eax
jne 0x15394
movl $0x2, -0xbc(%rbp)
leaq -0xb0(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xb8(%rbp)
jmp 0x15423
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzwl 0x8(%rax), %eax
cmpl $0x1c, %eax
jne 0x153c3
movl $0xa, -0xbc(%rbp)
leaq -0xb0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xb8(%rbp)
jmp 0x15421
jmp 0x153c5
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1541a
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzwl 0x8(%rax), %edi
callq 0x27a50
movq %rax, %r9
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movl $0x3, %edi
leaq 0x213ae(%rip), %rsi     # 0x367aa
leaq 0x20eae(%rip), %rdx     # 0x362b1
movl $0x35, %ecx
leaq 0x213cb(%rip), %r8      # 0x367da
movq %rax, (%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0x1541c
jmp 0x15594
jmp 0x15423
jmp 0x15425
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rsi
movl -0xbc(%rbp), %ecx
leaq -0xb0(%rbp), %rdi
leaq 0x213ad(%rip), %rdx     # 0x367f1
callq 0x253d0
movl %eax, -0xc0(%rbp)
cmpl $0x0, -0xc0(%rbp)
je 0x1545d
jmp 0x15594
movw -0xca(%rbp), %ax
andw $-0x2, %ax
orw $0x1, %ax
movw %ax, -0xca(%rbp)
movw -0xca(%rbp), %ax
andw $-0x21, %ax
orw $0x20, %ax
movw %ax, -0xca(%rbp)
movw -0xca(%rbp), %ax
andw $0xfeff, %ax            # imm = 0xFEFF
orw $0x100, %ax             # imm = 0x100
movw %ax, -0xca(%rbp)
movl $0x20, %edi
callq 0x34d0
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
jne 0x154f5
jmp 0x154bc
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x154ee
movl $0x3, %edi
leaq 0x212d6(%rip), %rsi     # 0x367aa
leaq 0x20dd6(%rip), %rdx     # 0x362b1
movl $0x44, %ecx
leaq 0x219b0(%rip), %r8      # 0x36e97
movb $0x0, %al
callq 0x243b0
jmp 0x154f0
jmp 0x15594
movq -0xc8(%rbp), %rdi
movq -0x18(%rbp), %rax
movw (%rax), %ax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0xb8(%rbp), %r8
movl -0xbc(%rbp), %r9d
leaq -0xca(%rbp), %rdx
movzwl %ax, %esi
callq 0xbc40
cmpl $0x0, %eax
je 0x15565
jmp 0x1552f
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x15561
movl $0x3, %edi
leaq 0x21263(%rip), %rsi     # 0x367aa
leaq 0x20d63(%rip), %rdx     # 0x362b1
movl $0x49, %ecx
leaq 0x2129d(%rip), %r8      # 0x367f7
movb $0x0, %al
callq 0x243b0
jmp 0x15563
jmp 0x15594
cmpq $0x0, -0x20(%rbp)
je 0x1558b
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rdx
movq -0x28(%rbp), %r9
xorl %ecx, %ecx
movl $0x1, %r8d
movl %ecx, %esi
callq *%rax
movl $0x0, -0x4(%rbp)
jmp 0x155e1
cmpq $0x0, -0xc8(%rbp)
je 0x155b6
movq -0xc8(%rbp), %rdi
callq 0x27870
movq -0xc8(%rbp), %rdi
callq 0x3460
cmpq $0x0, -0x20(%rbp)
je 0x155da
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %r9
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl %ecx, %edx
xorl %r8d, %r8d
movl %r8d, %ecx
callq *%rax
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax)