// File: /workspace/github_c_makefile_star2_O1/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), %r14
testl %esi, %esi
setne %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
movq %r9, (%rsp)
jne 0xbce3
movq %rdx, %r15
testq %rdi, %rdi
je 0xbc27
movq 0x50(%rdi), %r12
xorl %eax, %eax
cmpq %rdi, 0x638(%r14)
setne %al
movw %ax, (%r15)
xorl %eax, %eax
callq 0x17d59
cmpl $0x7, (%rax)
jl 0xbc27
movq %r14, 0x8(%rsp)
movq %rbp, %rax
movl $0x2, %ebp
subl 0x74(%rax), %ebp
movq 0x8(%rax), %rbx
movq %r15, %rdi
callq 0x1a4f0
movq %rax, %r14
movq 0x450(%r12), %r13
testq %r13, %r13
jne 0xbbd6
movq 0x460(%r12), %r13
testq %r13, %r13
jne 0xbbd6
movq 0x458(%r12), %r13
xorl %eax, %eax
callq 0x19a24
movq %rax, %r10
movq (%rsp), %rax
subq 0x80(%rax), %r10
leaq 0x16db6(%rip), %rsi     # 0x229a8
leaq 0x174ef(%rip), %rdx     # 0x230e8
leaq 0x17108(%rip), %r8      # 0x22d08
movl $0x7, %edi
movl $0x280, %ecx            # imm = 0x280
movl %ebp, %r9d
movq %rax, %rbp
xorl %eax, %eax
pushq %r10
pushq %r13
pushq %r14
pushq %rbx
callq 0x17d92
addq $0x20, %rsp
movq 0x8(%rsp), %r14
cmpq $0x0, 0x68(%rbp)
jne 0xbc5e
movq %r14, %rbx
movslq 0x74(%rbp), %r14
shlq $0x3, %r14
movq %r14, %rdi
callq 0x34b0
movq %rax, 0x68(%rbp)
testq %rax, %rax
je 0xbd8b
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x31e0
movq %rbx, %r14
movq 0x68(%rbp), %rax
movslq 0x70(%rbp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x70(%rbp)
movq %r15, (%rax,%rcx,8)
cmpq $0x0, 0x18(%rbp)
je 0xbdd0
movq %r14, %rdi
movq %r15, %rsi
callq 0xc152
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0xbdd0
testb $0x24, %al
je 0xbdd0
andl $0x12, %eax
je 0xbdd0
cmpw $0x0, (%r15)
jne 0xbdd0
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 %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq *0x18(%rbp)
movq %rbx, 0x18(%rbp)
jmp 0xbdd0
movl $0x1, 0x78(%rbp)
testq %rdi, %rdi
je 0xbdd0
movq 0x50(%rdi), %r15
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xbdd0
movq %r14, %r12
movq %rbp, %rax
movl $0x2, %ebp
subl 0x74(%rax), %ebp
movq 0x8(%rax), %rbx
movq 0x450(%r15), %r14
testq %r14, %r14
jne 0xbd38
movq 0x460(%r15), %r14
testq %r14, %r14
jne 0xbd38
movq 0x458(%r15), %r14
xorl %eax, %eax
callq 0x19a24
movq %rax, %r10
movq (%rsp), %rax
subq 0x80(%rax), %r10
subq $0x8, %rsp
leaq 0x16c50(%rip), %rsi     # 0x229a8
leaq 0x17389(%rip), %rdx     # 0x230e8
leaq 0x16fca(%rip), %r8      # 0x22d30
movl $0x3, %edi
movl $0x2a5, %ecx            # imm = 0x2A5
movl %ebp, %r9d
movq %rax, %rbp
xorl %eax, %eax
pushq %r10
pushq %r14
pushq %rbx
callq 0x17d92
addq $0x20, %rsp
movq %r12, %r14
jmp 0xbdd0
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
movq %rbx, %r14
jl 0xbdc0
leaq 0x16c07(%rip), %rsi     # 0x229a8
leaq 0x17340(%rip), %rdx     # 0x230e8
leaq 0x17af4(%rip), %r8      # 0x238a3
movl $0x3, %edi
movl $0x286, %ecx            # imm = 0x286
xorl %eax, %eax
callq 0x17d92
movq %r15, %rdi
callq 0x1a1dd
movq %r15, %rdi
callq 0x3450
decl 0x74(%rbp)
jne 0xc12c
movq 0x28(%rbp), %rax
movq 0x30(%rbp), %rcx
movq %rax, (%rcx)
movq 0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
leaq 0x68(%r14), %rdi
leaq 0x38(%rbp), %rsi
callq 0x3946
decl 0x78(%r14)
cmpq $0x0, 0x18(%rbp)
je 0xbe78
movl 0x70(%rbp), %eax
testl %eax, %eax
movq %r14, 0x8(%rsp)
je 0xbe89
cmpl $0x1, %eax
je 0xbe80
movq 0x60(%rbp), %r14
cmpq $0x0, 0x20(%r14)
je 0xbe80
testl %eax, %eax
jle 0xbe8e
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x68(%rbp), %rax
movq (%rax,%rbx,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xc152
movzwl (%r12), %ecx
testw %cx, %cx
cmovneq %r12, %r13
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0xbe6a
testw %cx, %cx
jne 0xbe63
movl %eax, %edx
andl $0x12, %edx
je 0xbe63
andl $0x24, %eax
jne 0xbe96
testw %cx, %cx
cmovneq %r12, %r15
incq %rbx
movslq 0x70(%rbp), %rax
cmpq %rax, %rbx
jl 0xbe2c
jmp 0xbea0
xorl %r15d, %r15d
jmp 0xc0fa
movq 0x68(%rbp), %rax
movq (%rax), %r15
jmp 0xbeb1
xorl %r15d, %r15d
jmp 0xbeb1
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0xbea0
movl $0x0, 0x78(%rbp)
movq %r12, %r15
testq %r15, %r15
jne 0xbeb1
movq %r13, %r15
testq %r13, %r13
je 0xc13d
xorl %eax, %eax
callq 0x17d59
cmpl $0x8, (%rax)
jl 0xc0d3
movq 0x60(%rbp), %rbx
xorl %eax, %eax
callq 0x17d59
cmpl $0x7, (%rax)
jl 0xbf20
movq (%rsp), %rax
movl 0x70(%rax), %ebp
movq (%rsp), %rax
leaq 0x8(%rax), %rdi
callq 0x1a29d
movq %rax, %r10
subq $0x8, %rsp
leaq 0x16ab5(%rip), %rsi     # 0x229a8
leaq 0x16e59(%rip), %rdx     # 0x22d53
leaq 0x16e64(%rip), %r8      # 0x22d65
movl $0x7, %edi
movl $0x1f0, %ecx            # imm = 0x1F0
movl %ebp, %r9d
movq 0x8(%rsp), %rbp
xorl %eax, %eax
pushq %r10
callq 0x17d92
addq $0x10, %rsp
cmpl $0x0, 0x70(%rbp)
jle 0xc0d3
xorl %r12d, %r12d
movq %r15, 0x20(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x68(%rbp), %rax
movq (%rax,%r12,8), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0xc152
movl %eax, %r14d
xorl %eax, %eax
callq 0x17d59
cmpl $0x7, (%rax)
jl 0xc0af
cmpq %r15, %r13
leaq 0x17e8b(%rip), %rcx     # 0x23df2
movq %rcx, %rdx
leaq 0x16e2c(%rip), %rax     # 0x22d9d
cmoveq %rax, %rdx
movq %rdx, 0x50(%rsp)
testb $0x2, %r14b
leaq 0x16e1e(%rip), %rax     # 0x22da3
cmoveq %rcx, %rax
movq %rax, 0x48(%rsp)
testb $0x4, %r14b
leaq 0x16e11(%rip), %rax     # 0x22daa
cmoveq %rcx, %rax
movq %rax, 0x40(%rsp)
testb $0x8, %r14b
leaq 0x16e08(%rip), %rax     # 0x22db5
cmoveq %rcx, %rax
movq %rax, 0x38(%rsp)
testb $0x10, %r14b
leaq 0x16dff(%rip), %rax     # 0x22dc0
cmoveq %rcx, %rax
movq %rax, 0x30(%rsp)
testb $0x20, %r14b
leaq 0x16df5(%rip), %rax     # 0x22dca
cmoveq %rcx, %rax
movq %rax, 0x28(%rsp)
testb $0x40, %r14b
leaq 0x16def(%rip), %rbp     # 0x22dd8
cmoveq %rcx, %rbp
btl $0x9, %r14d
leaq 0x16ded(%rip), %rbx     # 0x22de6
cmovaeq %rcx, %rbx
btl $0xa, %r14d
movq %r13, 0x10(%rsp)
leaq 0x16de1(%rip), %r13     # 0x22def
cmovaeq %rcx, %r13
btl $0xb, %r14d
leaq 0x16dde(%rip), %r15     # 0x22dfc
cmovaeq %rcx, %r15
cmpl $0x1000, %r14d          # imm = 0x1000
leaq 0x16dd9(%rip), %r14     # 0x22e09
cmovbq %rcx, %r14
movq 0x10(%rsp), %rdi
callq 0x1a4f0
movq %rax, %r10
leal 0x1(%r12), %r9d
movl $0x7, %edi
leaq 0x16956(%rip), %rsi     # 0x229a8
leaq 0x16cfa(%rip), %rdx     # 0x22d53
movl $0x201, %ecx            # imm = 0x201
leaq 0x16d16(%rip), %r8      # 0x22d7b
xorl %eax, %eax
pushq %r10
pushq %r14
pushq %r15
movq 0x38(%rsp), %r15
pushq %r13
movq 0x30(%rsp), %r13
pushq %rbx
movq 0x40(%rsp), %rbx
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 0x17d92
addq $0x60, %rsp
xorl %eax, %eax
callq 0x17d59
cmpl $0x8, (%rax)
jl 0xc0c3
movq %r13, %rdi
callq 0x1c653
incq %r12
movslq 0x70(%rbp), %rax
cmpq %rax, %r12
jl 0xbf37
cmpq $0x1, %r15
movl $0x0, %esi
sbbl %esi, %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 0xc124
movslq 0x70(%rbp), %rax
testq %rax, %rax
jle 0xc124
xorl %ecx, %ecx
movq 0x68(%rbp), %rdx
cmpq %r15, (%rdx,%rcx,8)
jne 0xc11c
movq $0x0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0xc10a
movq %rbp, %rdi
callq 0xb481
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x68(%rbp), %rax
movslq 0x70(%rbp), %rcx
leaq (%rax,%rcx,8), %rax
addq $-0x8, %rax
jmp 0xbe84