// File: /workspace/github_c_makefile_star2_O2/GangZhuo[P]dohclient/src/channel_doh.c
// Function: doh_build_post_request
static http_request_t* doh_build_post_request(channel_req_t* rq, subnet_t* subnet)
{
	channel_doh_t* c = rq->ctx;
	http_request_t* req = NULL;
	ns_msg_t msg;
	int r, len;
	stream_t s = STREAM_INIT();

	init_ns_msg(&msg);

	r = build_request_nsmsg(&msg, rq);
	if (r) {
		loge("build_request_nsmsg() error\n");
		return NULL;
	}

	if (subnet) {
		ns_rr_t* rr;
		rr = ns_find_opt_rr(&msg);
		if (rr == NULL) {
			rr = ns_add_optrr(&msg);
			if (rr == NULL) {
				loge("Can't add option record to ns_msg_t\n");
				ns_msg_free(&msg);
				return NULL;
			}
		}

		rr->cls = NS_PAYLOAD_SIZE; /* reset edns payload size */

		if (ns_optrr_set_ecs(rr, (struct sockaddr*)&subnet->addr, subnet->mask, 0) != 0) {
			loge("Can't add ecs option\n");
			ns_msg_free(&msg);
			return NULL;
		}
	}

	if ((len = ns_serialize(&s, &msg, 0)) <= 0) {
		loge("ns_serialize() error\n");
		stream_free(&s);
		ns_msg_free(&msg);
		return NULL;
	}

	ns_msg_free(&msg);

	req = http_request_create("POST", c->path, c->host, c->keep_alive);
	if (!req) {
		loge("http_request_create() error\n");
		stream_free(&s);
		return NULL;
	}

	r = http_request_set_header(req, "Content-Type", "application/dns-message");
	if (r) {
		loge("http_request_set_header() error\n");
		stream_free(&s);
		http_request_destroy(req);
		return NULL;
	}

	r = http_request_set_header(req, "Pragma", "no-cache");
	if (r) {
		loge("http_request_set_header() error\n");
		stream_free(&s);
		http_request_destroy(req);
		return NULL;
	}

	r = http_request_set_header(req, "Cache-Control", "no-cache");
	if (r) {
		loge("http_request_set_header() error\n");
		stream_free(&s);
		http_request_destroy(req);
		return NULL;
	}

	r = http_request_set_header(req, "Accept", "*/*");
	if (r) {
		loge("http_request_set_header() error\n");
		stream_free(&s);
		http_request_destroy(req);
		return NULL;
	}

	http_request_set_data(req, s.array, s.size);

	http_request_set_tag(req, rq->qr.qname);

	return req;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x60(%rdi), %r12
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x18296
movq %r15, %rdi
movq %r14, %rsi
callq 0xda4f
testq %rbx, %rbx
je 0xd265
leaq 0x18(%rsp), %rdi
pushq $0x29
popq %rsi
callq 0x19ad8
testq %rax, %rax
jne 0xd212
leaq 0x18(%rsp), %rdi
callq 0x19bdc
testq %rax, %rax
je 0xd37d
movw $0x400, 0xa(%rax)       # imm = 0x400
movl 0x90(%rbx), %edx
addq $0x10, %rbx
movq %rax, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x1a257
testl %eax, %eax
je 0xd265
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd3ad
leaq 0x13dbf(%rip), %rsi     # 0x21009
leaq 0x13c6a(%rip), %rdx     # 0x20ebb
leaq 0x13bff(%rip), %r8      # 0x20e57
pushq $0x3
popq %rdi
movl $0x24b, %ecx            # imm = 0x24B
jmp 0xd3a6
movq %rsp, %rdi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x1a2cd
testl %eax, %eax
jle 0xd306
leaq 0x18(%rsp), %rdi
callq 0x188ce
movq 0x120(%r12), %rdx
movq 0x128(%r12), %rsi
movl 0x130(%r12), %ecx
leaq 0x12b1d(%rip), %rdi     # 0x1fdc2
callq 0x13234
testq %rax, %rax
je 0xd340
movq %rax, %rbx
leaq 0x13c32(%rip), %rsi     # 0x20eef
leaq 0x13c38(%rip), %rdx     # 0x20efc
movq %rax, %rdi
callq 0x1336f
testl %eax, %eax
je 0xd3bc
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd497
leaq 0x13d1e(%rip), %rsi     # 0x21009
leaq 0x13bc9(%rip), %rdx     # 0x20ebb
leaq 0x13c1b(%rip), %r8      # 0x20f14
pushq $0x3
popq %rdi
movl $0x263, %ecx            # imm = 0x263
jmp 0xd490
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd336
leaq 0x13cf0(%rip), %rsi     # 0x21009
leaq 0x13b9b(%rip), %rdx     # 0x20ebb
leaq 0x13445(%rip), %r8      # 0x2076c
pushq $0x3
popq %rdi
movl $0x252, %ecx            # imm = 0x252
xorl %eax, %eax
callq 0x1662e
movq %rsp, %rdi
callq 0x1b8a6
jmp 0xd3ad
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd370
leaq 0x13cb6(%rip), %rsi     # 0x21009
leaq 0x13b61(%rip), %rdx     # 0x20ebb
leaq 0x13b71(%rip), %r8      # 0x20ed2
pushq $0x3
popq %rdi
movl $0x25c, %ecx            # imm = 0x25C
xorl %eax, %eax
callq 0x1662e
movq %rsp, %rdi
callq 0x1b8a6
jmp 0xd4a7
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd3ad
leaq 0x13c79(%rip), %rsi     # 0x21009
leaq 0x13b24(%rip), %rdx     # 0x20ebb
leaq 0x13a94(%rip), %r8      # 0x20e32
pushq $0x3
popq %rdi
movl $0x242, %ecx            # imm = 0x242
xorl %eax, %eax
callq 0x1662e
leaq 0x18(%rsp), %rdi
callq 0x188ce
jmp 0xd4a7
leaq 0x13d7d(%rip), %rsi     # 0x21140
leaq 0x13d7d(%rip), %rdx     # 0x21147
movq %rbx, %rdi
callq 0x1336f
testl %eax, %eax
je 0xd408
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd497
leaq 0x13c1c(%rip), %rsi     # 0x21009
leaq 0x13ac7(%rip), %rdx     # 0x20ebb
leaq 0x13b19(%rip), %r8      # 0x20f14
pushq $0x3
popq %rdi
movl $0x26b, %ecx            # imm = 0x26B
jmp 0xd490
leaq 0x13d41(%rip), %rsi     # 0x21150
leaq 0x13d31(%rip), %rdx     # 0x21147
movq %rbx, %rdi
callq 0x1336f
testl %eax, %eax
je 0xd44d
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd497
leaq 0x13bd4(%rip), %rsi     # 0x21009
leaq 0x13a7f(%rip), %rdx     # 0x20ebb
leaq 0x13ad1(%rip), %r8      # 0x20f14
pushq $0x3
popq %rdi
movl $0x273, %ecx            # imm = 0x273
jmp 0xd490
leaq 0x13ae1(%rip), %rsi     # 0x20f35
leaq 0x13ae1(%rip), %rdx     # 0x20f3c
movq %rbx, %rdi
callq 0x1336f
testl %eax, %eax
je 0xd4b8
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0xd497
leaq 0x13b8f(%rip), %rsi     # 0x21009
leaq 0x13a3a(%rip), %rdx     # 0x20ebb
leaq 0x13a8c(%rip), %r8      # 0x20f14
pushq $0x3
popq %rdi
movl $0x27b, %ecx            # imm = 0x27B
xorl %eax, %eax
callq 0x1662e
movq %rsp, %rdi
callq 0x1b8a6
movq %rbx, %rdi
callq 0x132b5
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq (%rsp), %rsi
movl 0x8(%rsp), %edx
movq %rbx, %rdi
callq 0x134d7
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x13474
jmp 0xd4a9