// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
cmpl $0x0, -0x4(%rbp)
jne 0x147b9
movq -0x18(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x1f440
movl %eax, -0x48(%rbp)
cmpl $0xc8, %eax
jne 0x147b9
movl $0x20, %edi
callq 0x34d0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x1461a
jmp 0x145e1
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x14613
movl $0x3, %edi
leaq 0x2200a(%rip), %rsi     # 0x36603
leaq 0x21f83(%rip), %rdx     # 0x36583
movl $0x1e6, %ecx            # imm = 0x1E6
leaq 0x2288b(%rip), %r8      # 0x36e97
movb $0x0, %al
callq 0x243b0
jmp 0x14615
jmp 0x14839
movq -0x38(%rbp), %rdi
callq 0x270f0
cmpl $0x0, %eax
je 0x14674
jmp 0x1462a
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1465c
movl $0x3, %edi
leaq 0x21fc1(%rip), %rsi     # 0x36603
leaq 0x21f3a(%rip), %rdx     # 0x36583
movl $0x1eb, %ecx            # imm = 0x1EB
leaq 0x2154d(%rip), %r8      # 0x35ba2
movb $0x0, %al
callq 0x243b0
jmp 0x1465e
movq -0x38(%rbp), %rdi
callq 0x3460
movq $0x0, -0x38(%rbp)
jmp 0x14839
movq -0x18(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x1f500
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x44(%rbp), %edx
callq 0x284b0
cmpl $0x0, %eax
je 0x146ef
jmp 0x1469c
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x146ce
movl $0x3, %edi
leaq 0x21f4f(%rip), %rsi     # 0x36603
leaq 0x21ec8(%rip), %rdx     # 0x36583
movl $0x1f3, %ecx            # imm = 0x1F3
leaq 0x21ec4(%rip), %r8      # 0x3658b
movb $0x0, %al
callq 0x243b0
jmp 0x146d0
movq -0x38(%rbp), %rdi
callq 0x27870
movq -0x38(%rbp), %rdi
callq 0x3460
movq $0x0, -0x38(%rbp)
jmp 0x14839
movq -0x28(%rbp), %rax
cmpq $0x0, 0x68(%rax)
jne 0x14795
movq -0x28(%rbp), %rax
movslq 0x74(%rax), %rdi
shlq $0x3, %rdi
callq 0x34d0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x68(%rax)
jne 0x1477a
jmp 0x14727
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x14759
movl $0x3, %edi
leaq 0x21ec4(%rip), %rsi     # 0x36603
leaq 0x21e3d(%rip), %rdx     # 0x36583
movl $0x1fd, %ecx            # imm = 0x1FD
leaq 0x22745(%rip), %r8      # 0x36e97
movb $0x0, %al
callq 0x243b0
jmp 0x1475b
movq -0x38(%rbp), %rdi
callq 0x27870
movq -0x38(%rbp), %rdi
callq 0x3460
movq $0x0, -0x38(%rbp)
jmp 0x14839
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x28(%rbp), %rax
movslq 0x74(%rax), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3200
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x28(%rbp), %rsi
movl 0x70(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x70(%rsi)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x14837
jmp 0x147bb
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1482a
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1e9a0
movq -0x68(%rbp), %r9
movl -0x5c(%rbp), %r11d
movq -0x58(%rbp), %r10
movl $0x3, %edi
leaq 0x21e01(%rip), %rsi     # 0x36603
leaq 0x21d7a(%rip), %rdx     # 0x36583
movl $0x20c, %ecx            # imm = 0x20C
leaq 0x21f43(%rip), %r8      # 0x36758
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0x1482c
movq -0x28(%rbp), %rax
movl $0x1, 0x78(%rax)
jmp 0x14839
movq -0x10(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x1ea10
movq %rax, %rdi
callq 0x3460
movq -0x10(%rbp), %rdi
callq 0x1e4b0
movq -0x18(%rbp), %rdi
callq 0x1f090
movq -0x28(%rbp), %rax
movl 0x74(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x74(%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x74(%rax)
jne 0x14941
jmp 0x1487d
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rdi
addq $0x68, %rdi
movq -0x28(%rbp), %rsi
addq $0x38, %rsi
callq 0x3b90
movq -0x30(%rbp), %rax
movl 0x78(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x78(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x14923
movq -0x28(%rbp), %rdi
callq 0x149c0
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %esi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rcx
cmpl $0x0, 0x78(%rcx)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %r8d
movq -0x28(%rbp), %rcx
movq 0x20(%rcx), %r9
xorl %ecx, %ecx
callq *%rax
jmp 0x1492b
movq $0x0, -0x38(%rbp)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x14b30
movq -0x28(%rbp), %rdi
callq 0x13910
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)