// File: /workspace/github_c_makefile_star2_O2/GangZhuo[P]dohclient/src/channel_doh.c
// Function: http_cb
static void http_cb(
	int status,
	http_request_t* request,
	http_response_t* response,
	void* state)
{
	channel_req_t* rq = (channel_req_t*)state;
	channel_doh_t* c = rq->ctx;
	ns_msg_t* result = NULL;
	char* data;
	int datalen;
	int http_status = 0;
	const char* status_text = NULL;

	if (status == HTTP_OK &&
		(http_status = http_response_get_status_code(response, &status_text)) == 200) {
		result = (ns_msg_t*)malloc(sizeof(ns_msg_t));
		if (!result) {
			loge("alloc\n");
			goto exit;
		}
		
		if (init_ns_msg(result)) {
			loge("init_ns_msg() error\n");
			free(result);
			result = NULL;
			goto exit;
		}

		data = http_response_get_data(response, &datalen);
		if (ns_parse(result, (const uint8_t*)data, datalen)) {
			loge("ns_parse() error\n");
			ns_msg_free(result);
			free(result);
			result = NULL;
			goto exit;
		}

		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;
	}
	else {
		loge("query %s failed: HTTP %d %s - %s\n",
			rq->qr.qname,
			http_status,
			status_text,
			http_request_get_host(request));
		rq->untrust = TRUE;
	}

exit:
	free(http_request_get_data(request, &datalen));
	http_request_destroy(request);
	http_response_destroy(response);

	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;
		}

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %rbp
movq %rdx, %r15
movq 0x60(%rcx), %rbx
andq $0x0, 0x18(%rsp)
movq %rsi, %r12
xorl %r14d, %r14d
testl %edi, %edi
jne 0xd572
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x13ae2
movl %eax, %r14d
cmpl $0xc8, %eax
jne 0xd572
pushq $0x20
popq %rdi
callq 0x34c0
testq %rax, %rax
je 0xd6be
movq %rax, %r13
movq %rax, %rdi
callq 0x18296
testl %eax, %eax
je 0xd6f7
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd751
leaq 0x13ab9(%rip), %rsi     # 0x21009
leaq 0x13a32(%rip), %rdx     # 0x20f89
leaq 0x1304e(%rip), %r8      # 0x205ac
pushq $0x3
popq %rdi
movl $0x1eb, %ecx            # imm = 0x1EB
xorl %eax, %eax
callq 0x1662e
jmp 0xd751
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd5d6
movq 0x8(%rbp), %r13
movq %r15, 0x8(%rsp)
movq %rbx, %r15
movq 0x18(%rsp), %rbx
movq %r12, %rdi
callq 0x134a4
movq %rax, %r10
subq $0x8, %rsp
leaq 0x13a64(%rip), %rsi     # 0x21009
leaq 0x139dd(%rip), %rdx     # 0x20f89
leaq 0x13bab(%rip), %r8      # 0x2115e
pushq $0x3
popq %rdi
movl $0x20c, %ecx            # imm = 0x20C
movq %r13, %r9
xorl %eax, %eax
pushq %r10
pushq %rbx
movq %r15, %rbx
movq 0x20(%rsp), %r15
pushq %r14
callq 0x1662e
addq $0x20, %rsp
movl $0x1, 0x78(%rbp)
leaq 0x14(%rsp), %rsi
movq %r12, %rdi
callq 0x134c8
movq %rax, %rdi
callq 0x3460
movq %r12, %rdi
callq 0x132b5
movq %r15, %rdi
callq 0x13901
decl 0x74(%rbp)
jne 0xd9f9
movq 0x28(%rbp), %rax
movq 0x30(%rbp), %rcx
movq %rax, (%rcx)
movq %rcx, 0x8(%rax)
leaq 0x68(%rbx), %rdi
leaq 0x38(%rbp), %rsi
callq 0x392c
decl 0x78(%rbx)
xorl %r13d, %r13d
cmpq $0x0, 0x18(%rbp)
je 0xd6a2
movl 0x70(%rbp), %eax
testl %eax, %eax
movq %rbx, 0x20(%rsp)
je 0xd6b6
cmpl $0x1, %eax
je 0xd6aa
movq 0x60(%rbp), %r14
cmpq $0x0, 0x20(%r14)
je 0xd6aa
xorl %ebx, %ebx
xorl %r15d, %r15d
cltq
cmpq %rax, %rbx
jge 0xd79a
movq 0x68(%rbp), %rax
movq (%rax,%rbx,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xda90
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0xd69a
btl $0xa, %eax
jae 0xd692
movl %eax, %ecx
andl $0x12, %ecx
je 0xd692
movl %eax, %ecx
andl $0x24, %ecx
jne 0xd797
testw $0x400, %ax             # imm = 0x400
cmoveq %r12, %r15
incq %rbx
movl 0x70(%rbp), %eax
jmp 0xd655
xorl %r15d, %r15d
jmp 0xd9cf
movq 0x68(%rbp), %rax
movq (%rax), %r15
jmp 0xd7a3
xorl %r15d, %r15d
jmp 0xd7a3
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd5dd
leaq 0x13934(%rip), %rsi     # 0x21009
leaq 0x138ad(%rip), %rdx     # 0x20f89
leaq 0x141d0(%rip), %r8      # 0x218b3
pushq $0x3
popq %rdi
movl $0x1e6, %ecx            # imm = 0x1E6
xorl %eax, %eax
callq 0x1662e
jmp 0xd5dd
leaq 0x14(%rsp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x13b36
movl (%r14), %edx
movq %r13, %rdi
movq %rax, %rsi
callq 0x18e8f
testl %eax, %eax
je 0xd75e
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd749
leaq 0x138dd(%rip), %rsi     # 0x21009
leaq 0x13856(%rip), %rdx     # 0x20f89
leaq 0x13857(%rip), %r8      # 0x20f91
pushq $0x3
popq %rdi
movl $0x1f3, %ecx            # imm = 0x1F3
xorl %eax, %eax
callq 0x1662e
movq %r13, %rdi
callq 0x188ce
movq %r13, %rdi
callq 0x3460
jmp 0xd5dd
movq 0x68(%rbp), %rax
testq %rax, %rax
jne 0xd784
movslq 0x74(%rbp), %rsi
shlq $0x3, %rsi
pushq $0x1
popq %rdi
callq 0x3250
movq %rax, 0x68(%rbp)
testq %rax, %rax
je 0xda1d
movslq 0x70(%rbp), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x70(%rbp)
movq %r13, (%rax,%rcx,8)
jmp 0xd5dd
movq %r12, %r15
testq %r15, %r15
je 0xda08
xorl %eax, %eax
callq 0x165f5
cmpl $0x8, (%rax)
jl 0xd9a8
movq 0x60(%rbp), %r14
xorl %eax, %eax
callq 0x165f5
cmpl $0x7, (%rax)
jl 0xd7f3
leaq 0x8(%rbp), %rdi
callq 0x1897e
leaq 0x13836(%rip), %rsi     # 0x21009
leaq 0x13581(%rip), %rdx     # 0x20d5b
leaq 0x1399f(%rip), %r8      # 0x21180
pushq $0x7
popq %rdi
movl $0x17d, %ecx            # imm = 0x17D
movq %rax, %r9
xorl %eax, %eax
callq 0x1662e
xorl %ebx, %ebx
movq %rbp, 0x60(%rsp)
movq %r15, 0x30(%rsp)
movq %r14, 0x28(%rsp)
movslq 0x70(%rbp), %rax
cmpq %rax, %rbx
jge 0xd9a8
movq 0x68(%rbp), %rax
movq (%rax,%rbx,8), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xda90
movl %eax, %ebp
xorl %eax, %eax
callq 0x165f5
cmpl $0x7, (%rax)
jl 0xd993
cmpq %r15, %r12
leaq 0x145be(%rip), %rcx     # 0x21dfe
movq %rcx, %rdx
leaq 0x1355b(%rip), %rax     # 0x20da5
cmoveq %rax, %rdx
movq %rdx, 0x58(%rsp)
testb $0x2, %bpl
leaq 0x1354d(%rip), %rax     # 0x20dab
cmoveq %rcx, %rax
movq %rax, 0x50(%rsp)
movd %ebp, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa %xmm0, %xmm1
pand 0x13114(%rip), %xmm1    # 0x20990
pand 0x1311c(%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 0x1350d(%rip), %rdx     # 0x20db2
cmovneq %rcx, %rdx
movq %rdx, 0x48(%rsp)
testb $0x40, %al
leaq 0x13506(%rip), %rdx     # 0x20dbd
cmovneq %rcx, %rdx
movq %rdx, 0x40(%rsp)
testb $0x20, %al
leaq 0x134ff(%rip), %rdx     # 0x20dc8
cmovneq %rcx, %rdx
movq %rdx, 0x38(%rsp)
testb $0x10, %al
leaq 0x134f7(%rip), %r11     # 0x20dd2
cmovneq %rcx, %r11
testb $0x8, %al
leaq 0x134f8(%rip), %r15     # 0x20de0
cmovneq %rcx, %r15
testb $0x4, %al
leaq 0x134f9(%rip), %r14     # 0x20dee
cmovneq %rcx, %r14
testb $0x2, %al
movq %r12, 0x8(%rsp)
leaq 0x134f0(%rip), %r12     # 0x20df7
cmovneq %rcx, %r12
testb $0x1, %al
leaq 0x134f0(%rip), %r10     # 0x20e04
cmovneq %rcx, %r10
cmpl $0x1000, %ebp           # imm = 0x1000
leaq 0x134ec(%rip), %rbp     # 0x20e11
cmovbq %rcx, %rbp
leal 0x1(%rbx), %r9d
subq $0x8, %rsp
pushq $0x7
popq %rdi
leaq 0x136ce(%rip), %rsi     # 0x21009
leaq 0x13419(%rip), %rdx     # 0x20d5b
movl $0x18d, %ecx            # imm = 0x18D
leaq 0x13845(%rip), %r8      # 0x21193
xorl %eax, %eax
pushq %rbp
pushq %r10
pushq %r12
movq 0x28(%rsp), %r12
pushq %r14
movq 0x50(%rsp), %r14
pushq %r15
movq 0x60(%rsp), %r15
pushq %r11
pushq 0x70(%rsp)
pushq 0x80(%rsp)
pushq 0x90(%rsp)
pushq 0xa0(%rsp)
pushq 0xb0(%rsp)
callq 0x1662e
addq $0x60, %rsp
movq %r12, %rdi
callq 0x1aa39
incq %rbx
movq 0x60(%rsp), %rbp
jmp 0xd804
cmpq $0x1, %r15
movl $0x0, %esi
sbbl %esi, %esi
xorl %r8d, %r8d
cmpl $0x0, 0x78(%rbp)
sete %r8b
movq 0x20(%rbp), %r9
movq 0x20(%rsp), %rdi
movq %r15, %rdx
xorl %ecx, %ecx
callq *0x18(%rbp)
movl 0x70(%rbp), %eax
testl %eax, %eax
cmovlel %r13d, %eax
cmpq %r13, %rax
je 0xd9f1
movq 0x68(%rbp), %rcx
cmpq %r15, (%rcx,%r13,8)
jne 0xd9ec
andq $0x0, (%rcx,%r13,8)
incq %r13
jmp 0xd9d8
movq %rbp, %rdi
callq 0xccb6
addq $0x68, %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 0xd6ae
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd749
leaq 0x135d5(%rip), %rsi     # 0x21009
leaq 0x1354e(%rip), %rdx     # 0x20f89
leaq 0x13e71(%rip), %r8      # 0x218b3
pushq $0x3
popq %rdi
movl $0x1fd, %ecx            # imm = 0x1FD
jmp 0xd742