// File: /workspace/github_c_makefile_star2_O3/GangZhuo[P]dohclient/src/channel_chndoh.c
// Function: query_cb
static int query_cb(channel_t* ctx,
	int status,
	ns_msg_t* result,
	int fromcache,
	int trust,
	void* state)
{
	channel_req_t* rq = (channel_req_t*)state;
	channel_chndoh_t* c = rq->ctx;

	if (status == 0 && result) {

		if (ctx != NULL) {
			doh_server_t* doh = (doh_server_t*)ctx->data;

			result->id = ctx == c->chndoh.chctx ? 0 : 1;

			logd("%d. query %s success: %s - %s (%lu ms)\n",
				2 - rq->wait_num,
				rq->qr.qname,
				msg_answers(result),
				doh->name ? doh->name : (doh->host ? doh->host : doh->addrstr),
				OS_GetTickCount() - rq->start_time);
		}

		if (!rq->results) {
			rq->results = (ns_msg_t**)malloc(sizeof(ns_msg_t*) * rq->wait_num);
			if (!rq->results) {
				loge("alloc\n");
				ns_msg_free(result);
				free(result);
				result = NULL;
				goto exit;
			}
			memset(rq->results, 0, sizeof(ns_msg_t*) * rq->wait_num);
		}

		rq->results[rq->result_num++] = result;

		if (rq->callback && is_best(c, result)) {
			/* Detach the result, so can keep the result in memory,
			after myreq_destroy() called. */
			rq->results[rq->result_num - 1] = NULL;
			rq->untrust = FALSE;

			/* callback */
			rq->callback((channel_t*)c, 0, result, FALSE, TRUE, rq->cb_state);
			rq->callback = NULL;
		}
	}
	else {
		rq->untrust = TRUE;
		if (ctx != NULL) {
			doh_server_t* doh = (doh_server_t*)ctx->data;

			loge("%d. query %s failed - %s (%lu ms)\n",
				2 - rq->wait_num,
				rq->qr.qname,
				doh->name ? doh->name : (doh->host ? doh->host : doh->addrstr),
				OS_GetTickCount() - rq->start_time);
		}
	}

exit:
	rq->wait_num--;

	if (rq->wait_num == 0) {

		dllist_remove(&rq->entry);
		rbtree_remove(&c->reqdic, &rq->rbn);
		c->req_count--;

		if (rq->callback) {
			result = choose_best_nsmsg(rq);
			rq->callback((channel_t*)c, result ? 0 : -1, result, FALSE, !rq->untrust, rq->cb_state);
		}
		else {
			result = NULL;
		}

		if (result) {
			/* Detach the result, so can keep the result in memory,
			after myreq_destroy() called. */
			detach_result(rq, result);
		}

		myreq_destroy(rq);
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbp
movq 0x60(%r9), %r12
testl %esi, %esi
setne %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
movq %r9, (%rsp)
jne 0xb8f7
movq %rdx, %r15
testq %rdi, %rdi
je 0xb84e
movq 0x50(%rdi), %r14
xorl %eax, %eax
cmpq %rdi, 0x638(%r12)
setne %al
movw %ax, (%r15)
xorl %eax, %eax
callq 0x176e5
cmpl $0x7, (%rax)
jl 0xb84e
movq %r12, 0x8(%rsp)
movq %rbp, %rax
movl $0x2, %ebp
subl 0x74(%rax), %ebp
movq 0x8(%rax), %rbx
movq %r15, %rdi
callq 0x19df7
movq %rax, %r12
movq 0x450(%r14), %r13
testq %r13, %r13
jne 0xb7fd
movq 0x460(%r14), %r13
testq %r13, %r13
jne 0xb7fd
movq 0x458(%r14), %r13
xorl %eax, %eax
callq 0x193ab
movq %rax, %r10
movq (%rsp), %rax
subq 0x80(%rax), %r10
leaq 0x17197(%rip), %rsi     # 0x229b0
leaq 0x178d0(%rip), %rdx     # 0x230f0
leaq 0x174e9(%rip), %r8      # 0x22d10
movl $0x7, %edi
movl $0x280, %ecx            # imm = 0x280
movl %ebp, %r9d
movq %rax, %rbp
xorl %eax, %eax
pushq %r10
pushq %r13
pushq %r12
pushq %rbx
callq 0x1771e
addq $0x20, %rsp
movq 0x8(%rsp), %r12
movq 0x68(%rbp), %rax
testq %rax, %rax
jne 0xb876
movslq 0x74(%rbp), %rsi
shlq $0x3, %rsi
movl $0x1, %edi
callq 0x3240
movq %rax, 0x68(%rbp)
testq %rax, %rax
je 0xb999
movslq 0x70(%rbp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x70(%rbp)
movq %r15, (%rax,%rcx,8)
cmpq $0x0, 0x18(%rbp)
je 0xb9db
movq %r12, %rdi
movq %r15, %rsi
callq 0xbd70
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0xb9db
testb $0x24, %al
je 0xb9db
andl $0x12, %eax
je 0xb9db
cmpw $0x0, (%r15)
jne 0xb9db
movq 0x68(%rbp), %rax
movslq 0x70(%rbp), %rcx
xorl %ebx, %ebx
movq %rbx, -0x8(%rax,%rcx,8)
movl $0x0, 0x78(%rbp)
movq 0x20(%rbp), %r9
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq *0x18(%rbp)
movq %rbx, 0x18(%rbp)
jmp 0xb9db
movl $0x1, 0x78(%rbp)
testq %rdi, %rdi
je 0xb9db
movq 0x50(%rdi), %r15
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xb9db
movq %rbp, %rax
movl $0x2, %ebp
subl 0x74(%rax), %ebp
movq 0x8(%rax), %rbx
movq 0x450(%r15), %r14
testq %r14, %r14
jne 0xb949
movq 0x460(%r15), %r14
testq %r14, %r14
jne 0xb949
movq 0x458(%r15), %r14
xorl %eax, %eax
callq 0x193ab
movq %rax, %r10
movq (%rsp), %rax
subq 0x80(%rax), %r10
subq $0x8, %rsp
leaq 0x17047(%rip), %rsi     # 0x229b0
leaq 0x17780(%rip), %rdx     # 0x230f0
leaq 0x173c1(%rip), %r8      # 0x22d38
movl $0x3, %edi
movl $0x2a5, %ecx            # imm = 0x2A5
movl %ebp, %r9d
movq %rax, %rbp
xorl %eax, %eax
pushq %r10
pushq %r14
pushq %rbx
callq 0x1771e
addq $0x20, %rsp
jmp 0xb9db
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xb9cb
leaq 0x17004(%rip), %rsi     # 0x229b0
leaq 0x1773d(%rip), %rdx     # 0x230f0
leaq 0x17ef9(%rip), %r8      # 0x238b3
movl $0x3, %edi
movl $0x286, %ecx            # imm = 0x286
xorl %eax, %eax
callq 0x1771e
movq %r15, %rdi
callq 0x19ae0
movq %r15, %rdi
callq 0x3450
decl 0x74(%rbp)
jne 0xbd50
movq 0x28(%rbp), %rax
movq 0x30(%rbp), %rcx
movq %rax, (%rcx)
movq %rcx, 0x8(%rax)
leaq 0x68(%r12), %rdi
leaq 0x38(%rbp), %rsi
callq 0x3a34
decl 0x78(%r12)
cmpq $0x0, 0x18(%rbp)
je 0xbd48
movslq 0x70(%rbp), %rax
testq %rax, %rax
movq %r12, 0x8(%rsp)
je 0xbaaf
cmpl $0x1, %eax
je 0xbaa6
movq 0x60(%rbp), %r12
cmpq $0x0, 0x20(%r12)
je 0xbaa6
testl %eax, %eax
jle 0xba9b
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebx, %ebx
movq 0x68(%rbp), %rax
movq (%rax,%r14,8), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0xbd70
movzwl (%r13), %ecx
testw %cx, %cx
cmovneq %r13, %rbx
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0xba82
testw %cx, %cx
jne 0xba7b
movl %eax, %edx
andl $0x12, %edx
je 0xba7b
andl $0x24, %eax
jne 0xbd61
testw %cx, %cx
cmovneq %r13, %r15
incq %r14
movslq 0x70(%rbp), %rax
cmpq %rax, %r14
jl 0xba40
testq %r15, %r15
jne 0xbab2
movq %rbx, %r15
testq %rbx, %rbx
jne 0xbab2
movq 0x68(%rbp), %rcx
movq -0x8(%rcx,%rax,8), %r15
jmp 0xbab2
movq 0x68(%rbp), %rax
movq (%rax), %r15
jmp 0xbab2
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x176e5
cmpl $0x8, (%rax)
jl 0xbcf7
movq 0x60(%rbp), %rbx
xorl %eax, %eax
callq 0x176e5
cmpl $0x7, (%rax)
jl 0xbb21
movq (%rsp), %rax
movl 0x70(%rax), %ebp
movq (%rsp), %rax
leaq 0x8(%rax), %rdi
callq 0x19ba4
movq %rax, %r10
subq $0x8, %rsp
leaq 0x16ebc(%rip), %rsi     # 0x229b0
leaq 0x17260(%rip), %rdx     # 0x22d5b
leaq 0x1726b(%rip), %r8      # 0x22d6d
movl $0x7, %edi
movl $0x1f0, %ecx            # imm = 0x1F0
movl %ebp, %r9d
movq 0x8(%rsp), %rbp
xorl %eax, %eax
pushq %r10
callq 0x1771e
addq $0x10, %rsp
cmpl $0x0, 0x70(%rbp)
jle 0xbcf7
xorl %r12d, %r12d
movq %r15, 0x20(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x68(%rbp), %rax
movq (%rax,%r12,8), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbd70
movl %eax, %r13d
xorl %eax, %eax
callq 0x176e5
cmpl $0x7, (%rax)
jl 0xbcd3
cmpq %r15, %r14
leaq 0x18296(%rip), %rcx     # 0x23dfe
movq %rcx, %rdx
leaq 0x17233(%rip), %rax     # 0x22da5
cmoveq %rax, %rdx
movq %rdx, 0x50(%rsp)
testb $0x2, %r13b
leaq 0x17225(%rip), %rax     # 0x22dab
cmoveq %rcx, %rax
movq %rax, 0x48(%rsp)
movd %r13d, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa %xmm0, %xmm1
pand 0x16deb(%rip), %xmm1    # 0x22990
pand 0x16df3(%rip), %xmm0    # 0x229a0
pxor %xmm2, %xmm2
pcmpeqd %xmm2, %xmm0
pcmpeqd %xmm2, %xmm1
packssdw %xmm0, %xmm1
packsswb %xmm1, %xmm1
pmovmskb %xmm1, %eax
testb $-0x80, %al
leaq 0x171e4(%rip), %rdx     # 0x22db2
cmovneq %rcx, %rdx
movq %rdx, 0x40(%rsp)
testb $0x40, %al
leaq 0x171dd(%rip), %rdx     # 0x22dbd
cmovneq %rcx, %rdx
movq %rdx, 0x38(%rsp)
testb $0x20, %al
leaq 0x171d6(%rip), %rdx     # 0x22dc8
cmovneq %rcx, %rdx
movq %rdx, 0x30(%rsp)
testb $0x10, %al
leaq 0x171ce(%rip), %rdx     # 0x22dd2
cmovneq %rcx, %rdx
movq %rdx, 0x28(%rsp)
testb $0x8, %al
leaq 0x171ca(%rip), %rbp     # 0x22de0
cmovneq %rcx, %rbp
testb $0x4, %al
movq %r14, 0x10(%rsp)
leaq 0x171c6(%rip), %r14     # 0x22dee
cmovneq %rcx, %r14
testb $0x2, %al
leaq 0x171c2(%rip), %rbx     # 0x22df7
cmovneq %rcx, %rbx
testb $0x1, %al
leaq 0x171c2(%rip), %r15     # 0x22e04
cmovneq %rcx, %r15
cmpl $0x1000, %r13d          # imm = 0x1000
leaq 0x171bd(%rip), %r13     # 0x22e11
cmovbq %rcx, %r13
movq 0x10(%rsp), %rdi
callq 0x19df7
movq %rax, %r10
leal 0x1(%r12), %r9d
movl $0x7, %edi
leaq 0x16d3a(%rip), %rsi     # 0x229b0
leaq 0x170de(%rip), %rdx     # 0x22d5b
movl $0x201, %ecx            # imm = 0x201
leaq 0x170fa(%rip), %r8      # 0x22d83
xorl %eax, %eax
pushq %r10
pushq %r13
pushq %r15
movq 0x38(%rsp), %r15
pushq %rbx
movq 0x38(%rsp), %rbx
pushq %r14
movq 0x38(%rsp), %r14
pushq %rbp
movq 0x30(%rsp), %rbp
pushq 0x58(%rsp)
pushq 0x68(%rsp)
pushq 0x78(%rsp)
pushq 0x88(%rsp)
pushq 0x98(%rsp)
pushq 0xa8(%rsp)
callq 0x1771e
addq $0x60, %rsp
xorl %eax, %eax
callq 0x176e5
cmpl $0x8, (%rax)
jl 0xbce7
movq %r14, %rdi
callq 0x1bd90
incq %r12
movslq 0x70(%rbp), %rax
cmpq %rax, %r12
jl 0xbb38
xorl %esi, %esi
testq %r15, %r15
sete %sil
negl %esi
xorl %r8d, %r8d
cmpl $0x0, 0x78(%rbp)
sete %r8b
movq 0x20(%rbp), %r9
movq 0x8(%rsp), %rdi
movq %r15, %rdx
xorl %ecx, %ecx
callq *0x18(%rbp)
testq %r15, %r15
je 0xbd48
movslq 0x70(%rbp), %rax
testq %rax, %rax
jle 0xbd48
xorl %ecx, %ecx
movq 0x68(%rbp), %rdx
cmpq %r15, (%rdx,%rcx,8)
jne 0xbd40
movq $0x0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0xbd2e
movq %rbp, %rdi
callq 0xb0a7
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, 0x78(%rbp)
movq %r13, %r15
jmp 0xbab2