// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq 0x60(%r9), %rbx
testl %esi, %esi
setne %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
pushq $0x2
popq %rbp
movq %r9, 0x8(%rsp)
jne 0xb395
movq %rdx, %r15
testq %rdi, %rdi
je 0xb2f0
movq 0x50(%rdi), %r12
xorl %eax, %eax
cmpq %rdi, 0x638(%rbx)
setne %al
movw %ax, (%r15)
xorl %eax, %eax
callq 0x165f5
cmpl $0x7, (%rax)
jl 0xb2f0
movq %rbx, (%rsp)
subl 0x74(%r13), %ebp
movq 0x8(%r13), %rbx
movq %r15, %rdi
callq 0x18bcb
movq %rax, %r14
movq 0x450(%r12), %r13
testq %r13, %r13
jne 0xb2a1
movq 0x460(%r12), %r13
testq %r13, %r13
jne 0xb2a1
movq 0x458(%r12), %r13
xorl %eax, %eax
callq 0x181bb
movq %rax, %r10
movq 0x8(%rsp), %r11
subq 0x80(%r11), %r10
leaq 0x156f2(%rip), %rsi     # 0x209b0
leaq 0x15e2b(%rip), %rdx     # 0x210f0
leaq 0x15a44(%rip), %r8      # 0x20d10
pushq $0x7
popq %rdi
movl $0x280, %ecx            # imm = 0x280
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq %r13
movq %r11, %r13
pushq %r14
pushq %rbx
callq 0x1662e
addq $0x20, %rsp
movq (%rsp), %rbx
movq 0x68(%r13), %rax
testq %rax, %rax
jne 0xb316
movslq 0x74(%r13), %rsi
shlq $0x3, %rsi
pushq $0x1
popq %rdi
callq 0x3250
movq %rax, 0x68(%r13)
testq %rax, %rax
je 0xb42e
movslq 0x70(%r13), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x70(%r13)
movq %r15, (%rax,%rcx,8)
cmpq $0x0, 0x18(%r13)
je 0xb46e
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb7e5
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0xb46e
testb $0x24, %al
je 0xb46e
andl $0x12, %eax
je 0xb46e
cmpw $0x0, (%r15)
jne 0xb46e
movq 0x68(%r13), %rax
movslq 0x70(%r13), %rcx
andq $0x0, -0x8(%rax,%rcx,8)
andl $0x0, 0x78(%r13)
movq 0x20(%r13), %r9
pushq $0x1
popq %r8
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq *0x18(%r13)
andq $0x0, 0x18(%r13)
jmp 0xb46e
movl $0x1, 0x78(%r13)
testq %rdi, %rdi
je 0xb46e
movq 0x50(%rdi), %r15
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xb46e
movq %rbx, %r12
subl 0x74(%r13), %ebp
movq 0x8(%r13), %rbx
movq 0x450(%r15), %r14
testq %r14, %r14
jne 0xb3e4
movq 0x460(%r15), %r14
testq %r14, %r14
jne 0xb3e4
movq 0x458(%r15), %r14
xorl %eax, %eax
callq 0x181bb
movq %rax, %r10
subq 0x80(%r13), %r10
subq $0x8, %rsp
leaq 0x155b0(%rip), %rsi     # 0x209b0
leaq 0x15ce9(%rip), %rdx     # 0x210f0
leaq 0x1592a(%rip), %r8      # 0x20d38
pushq $0x3
popq %rdi
movl $0x2a5, %ecx            # imm = 0x2A5
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq %r14
pushq %rbx
callq 0x1662e
addq $0x20, %rsp
movq %r12, %rbx
jmp 0xb46e
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xb45e
leaq 0x1556f(%rip), %rsi     # 0x209b0
leaq 0x15ca8(%rip), %rdx     # 0x210f0
leaq 0x16464(%rip), %r8      # 0x218b3
pushq $0x3
popq %rdi
movl $0x286, %ecx            # imm = 0x286
xorl %eax, %eax
callq 0x1662e
movq %r15, %rdi
callq 0x188ce
movq %r15, %rdi
callq 0x3460
decl 0x74(%r13)
jne 0xb7d4
movq 0x28(%r13), %rax
movq 0x30(%r13), %rcx
movq %rax, (%rcx)
movq %rcx, 0x8(%rax)
leaq 0x68(%rbx), %rdi
leaq 0x38(%r13), %rsi
callq 0x392c
decl 0x78(%rbx)
cmpq $0x0, 0x18(%r13)
je 0xb7cc
movl 0x70(%r13), %eax
testl %eax, %eax
movq %rbx, (%rsp)
je 0xb51c
cmpl $0x1, %eax
je 0xb513
movq 0x60(%r13), %r14
cmpq $0x0, 0x20(%r14)
je 0xb513
xorl %r15d, %r15d
xorl %ebx, %ebx
xorl %ebp, %ebp
cltq
cmpq %rax, %r15
jge 0xb520
movq 0x68(%r13), %rax
movq (%rax,%r15,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xb7e5
movzwl (%r12), %ecx
testw %cx, %cx
cmovneq %r12, %rbx
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0xb50a
testw %cx, %cx
jne 0xb503
movl %eax, %edx
andl $0x12, %edx
je 0xb503
andl $0x24, %eax
jne 0xb538
testw %cx, %cx
cmovneq %r12, %rbp
incq %r15
movl 0x70(%r13), %eax
jmp 0xb4c5
movq 0x68(%r13), %rax
movq (%rax), %rbp
jmp 0xb540
xorl %ebp, %ebp
jmp 0xb540
testq %rbp, %rbp
jne 0xb540
movq %rbx, %rbp
testq %rbx, %rbx
jne 0xb540
movq 0x68(%r13), %rcx
movq -0x8(%rcx,%rax,8), %rbp
jmp 0xb540
andl $0x0, 0x78(%r13)
movq %r12, %rbp
xorl %eax, %eax
callq 0x165f5
cmpl $0x8, (%rax)
jl 0xb77b
movq 0x60(%r13), %r15
xorl %eax, %eax
callq 0x165f5
cmpl $0x7, (%rax)
jl 0xb5a5
movq %rbp, %rbx
movl 0x70(%r13), %ebp
leaq 0x8(%r13), %rdi
callq 0x1897e
movq %rax, %r10
subq $0x8, %rsp
leaq 0x15432(%rip), %rsi     # 0x209b0
leaq 0x157d6(%rip), %rdx     # 0x20d5b
leaq 0x157e1(%rip), %r8      # 0x20d6d
pushq $0x7
popq %rdi
movl $0x1f0, %ecx            # imm = 0x1F0
movl %ebp, %r9d
movq %rbx, %rbp
xorl %eax, %eax
pushq %r10
callq 0x1662e
popq %rax
popq %rcx
xorl %ebx, %ebx
movq %rbp, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movslq 0x70(%r13), %rax
cmpq %rax, %rbx
jge 0xb77b
movq 0x68(%r13), %rax
movq (%rax,%rbx,8), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0xb7e5
movl %eax, %r14d
xorl %eax, %eax
callq 0x165f5
cmpl $0x7, (%rax)
jl 0xb75f
cmpq %rbp, %r12
leaq 0x16810(%rip), %rcx     # 0x21dfe
movq %rcx, %rdx
leaq 0x157ad(%rip), %rax     # 0x20da5
cmoveq %rax, %rdx
movq %rdx, 0x50(%rsp)
testb $0x2, %r14b
leaq 0x1579f(%rip), %rax     # 0x20dab
cmoveq %rcx, %rax
movq %rax, 0x48(%rsp)
movd %r14d, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa %xmm0, %xmm1
pand 0x15365(%rip), %xmm1    # 0x20990
pand 0x1536d(%rip), %xmm0    # 0x209a0
pxor %xmm2, %xmm2
pcmpeqd %xmm2, %xmm0
pcmpeqd %xmm2, %xmm1
packssdw %xmm0, %xmm1
packsswb %xmm1, %xmm1
pmovmskb %xmm1, %eax
testb $-0x80, %al
leaq 0x1575e(%rip), %rdx     # 0x20db2
cmovneq %rcx, %rdx
movq %rdx, 0x40(%rsp)
testb $0x40, %al
leaq 0x15757(%rip), %rdx     # 0x20dbd
cmovneq %rcx, %rdx
movq %rdx, 0x38(%rsp)
testb $0x20, %al
leaq 0x15750(%rip), %rdx     # 0x20dc8
cmovneq %rcx, %rdx
movq %rdx, 0x30(%rsp)
testb $0x10, %al
leaq 0x15748(%rip), %r15     # 0x20dd2
cmovneq %rcx, %r15
movq %r15, 0x28(%rsp)
testb $0x8, %al
leaq 0x15744(%rip), %rbp     # 0x20de0
cmovneq %rcx, %rbp
testb $0x4, %al
leaq 0x15745(%rip), %r13     # 0x20dee
cmovneq %rcx, %r13
testb $0x2, %al
movq %rbx, 0x10(%rsp)
leaq 0x1573c(%rip), %rbx     # 0x20df7
cmovneq %rcx, %rbx
testb $0x1, %al
movq %r12, %r15
leaq 0x15739(%rip), %r12     # 0x20e04
cmovneq %rcx, %r12
cmpl $0x1000, %r14d          # imm = 0x1000
leaq 0x15734(%rip), %r14     # 0x20e11
cmovbq %rcx, %r14
movq %r15, %rdi
callq 0x18bcb
movq %rax, %r10
movq 0x10(%rsp), %rax
leal 0x1(%rax), %r9d
pushq $0x7
popq %rdi
leaq 0x152b1(%rip), %rsi     # 0x209b0
leaq 0x15655(%rip), %rdx     # 0x20d5b
movl $0x201, %ecx            # imm = 0x201
leaq 0x15671(%rip), %r8      # 0x20d83
xorl %eax, %eax
pushq %r10
pushq %r14
pushq %r12
movq %r15, %r12
pushq %rbx
movq 0x30(%rsp), %rbx
pushq %r13
movq 0x30(%rsp), %r13
pushq %rbp
movq 0x50(%rsp), %rbp
pushq 0x58(%rsp)
movq 0x50(%rsp), %r15
pushq 0x68(%rsp)
pushq 0x78(%rsp)
pushq 0x88(%rsp)
pushq 0x98(%rsp)
pushq 0xa8(%rsp)
callq 0x1662e
addq $0x60, %rsp
xorl %eax, %eax
callq 0x165f5
cmpl $0x8, (%rax)
jl 0xb773
movq %r12, %rdi
callq 0x1aa39
incq %rbx
jmp 0xb5b1
xorl %esi, %esi
testq %rbp, %rbp
sete %sil
negl %esi
xorl %r8d, %r8d
cmpl $0x0, 0x78(%r13)
sete %r8b
movq 0x20(%r13), %r9
xorl %ebx, %ebx
movq (%rsp), %rdi
movq %rbp, %rdx
xorl %ecx, %ecx
callq *0x18(%r13)
testq %rbp, %rbp
je 0xb7cc
movl 0x70(%r13), %eax
testl %eax, %eax
cmovlel %ebx, %eax
cmpq %rbx, %rax
je 0xb7cc
movq 0x68(%r13), %rcx
cmpq %rbp, (%rcx,%rbx,8)
jne 0xb7c7
andq $0x0, (%rcx,%rbx,8)
incq %rbx
jmp 0xb7b3
movq %r13, %rdi
callq 0xab90
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq