// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %rbx
subq $0xc8, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x109ee
cmpq $0x0, -0x20(%rbp)
je 0x109ee
cmpq $0x0, -0x10(%rbp)
je 0x108ac
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdx
movq -0x40(%rbp), %rax
movq 0x638(%rax), %rsi
movl $0x1, %eax
xorl %ecx, %ecx
cmpq %rsi, %rdx
cmovel %ecx, %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, (%rax)
movb $0x0, %al
callq 0x242d0
cmpl $0x7, (%rax)
jl 0x108a8
movq -0x38(%rbp), %rcx
movl $0x2, %eax
subl 0x74(%rcx), %eax
movl %eax, -0x64(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rdi
callq 0x27de0
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x450(%rax)
je 0x1080f
movq -0x48(%rbp), %rax
movq 0x450(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x10845
movq -0x48(%rbp), %rax
cmpq $0x0, 0x460(%rax)
je 0x1082e
movq -0x48(%rbp), %rax
movq 0x460(%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0x1083d
movq -0x48(%rbp), %rax
movq 0x458(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rbx
movq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movb $0x0, %al
callq 0x26e40
movl -0x64(%rbp), %r9d
movq -0x58(%rbp), %r11
movq -0x80(%rbp), %r10
movq -0x38(%rbp), %rcx
subq 0x80(%rcx), %rax
movl $0x7, %edi
leaq 0x25703(%rip), %rsi     # 0x35f7e
leaq 0x25e68(%rip), %rdx     # 0x366ea
movl $0x280, %ecx            # imm = 0x280
leaq 0x25a7c(%rip), %r8      # 0x3630a
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0x108aa
jmp 0x108ac
movq -0x38(%rbp), %rax
cmpq $0x0, 0x68(%rax)
jne 0x10952
movq -0x38(%rbp), %rax
movslq 0x74(%rax), %rdi
shlq $0x3, %rdi
callq 0x34d0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x68(%rax)
jne 0x10937
jmp 0x108e4
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x10916
movl $0x3, %edi
leaq 0x25682(%rip), %rsi     # 0x35f7e
leaq 0x25de7(%rip), %rdx     # 0x366ea
movl $0x286, %ecx            # imm = 0x286
leaq 0x26588(%rip), %r8      # 0x36e97
movb $0x0, %al
callq 0x243b0
jmp 0x10918
movq -0x20(%rbp), %rdi
callq 0x27870
movq -0x20(%rbp), %rdi
callq 0x3460
movq $0x0, -0x20(%rbp)
jmp 0x10b16
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x38(%rbp), %rax
movslq 0x74(%rax), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3200
movq -0x20(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x38(%rbp), %rsi
movl 0x70(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x70(%rsi)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x109e9
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x10e80
cmpl $0x0, %eax
je 0x109e9
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x38(%rbp), %rcx
movl 0x70(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq $0x0, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movl $0x0, 0x78(%rax)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq 0x20(%rcx), %r9
xorl %ecx, %ecx
movl $0x1, %r8d
movl %ecx, %esi
callq *%rax
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
jmp 0x10b14
movq -0x38(%rbp), %rax
movl $0x1, 0x78(%rax)
cmpq $0x0, -0x10(%rbp)
je 0x10b12
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x50(%rbp)
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x10b0e
movq -0x38(%rbp), %rcx
movl $0x2, %eax
subl 0x74(%rcx), %eax
movl %eax, -0x8c(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rax
cmpq $0x0, 0x450(%rax)
je 0x10a63
movq -0x50(%rbp), %rax
movq 0x450(%rax), %rax
movq %rax, -0x98(%rbp)
jmp 0x10aa5
movq -0x50(%rbp), %rax
cmpq $0x0, 0x460(%rax)
je 0x10a85
movq -0x50(%rbp), %rax
movq 0x460(%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0x10a97
movq -0x50(%rbp), %rax
movq 0x458(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movb $0x0, %al
callq 0x26e40
movl -0x8c(%rbp), %r9d
movq -0x88(%rbp), %r11
movq -0xa8(%rbp), %r10
movq -0x38(%rbp), %rcx
subq 0x80(%rcx), %rax
movl $0x3, %edi
leaq 0x25498(%rip), %rsi     # 0x35f7e
leaq 0x25bfd(%rip), %rdx     # 0x366ea
movl $0x2a5, %ecx            # imm = 0x2A5
leaq 0x25839(%rip), %r8      # 0x36332
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0x10b10
jmp 0x10b12
jmp 0x10b14
jmp 0x10b16
movq -0x38(%rbp), %rax
movl 0x74(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x74(%rax)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x74(%rax)
jne 0x10bfe
jmp 0x10b33
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rdi
addq $0x68, %rdi
movq -0x38(%rbp), %rsi
addq $0x38, %rsi
callq 0x3b90
movq -0x40(%rbp), %rax
movl 0x78(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x78(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x10bd9
movq -0x38(%rbp), %rdi
callq 0x10f10
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %esi
movq -0x20(%rbp), %rdx
movq -0x38(%rbp), %rcx
cmpl $0x0, 0x78(%rcx)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %r8d
movq -0x38(%rbp), %rcx
movq 0x20(%rcx), %r9
xorl %ecx, %ecx
callq *%rax
jmp 0x10be1
movq $0x0, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x10bf5
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x110c0
movq -0x38(%rbp), %rdi
callq 0x10410
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %rbp
retq
nopw (%rax,%rax)