// File: /workspace/github_c_makefile_star2_O3/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)
movq $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x19496
movq %r15, %rdi
callq 0x19496
movzwl (%r14), %eax
movw %ax, (%r15)
movzwl 0x4(%r14), %eax
movw %ax, 0x2(%r15)
movw $0x1, 0x4(%r15)
addq $0x8, %r14
movq %r14, %rdi
movl $0x1, %esi
callq 0x194ee
movq %rax, 0x10(%r15)
testq %rbx, %rbx
je 0xd93b
leaq 0x18(%rsp), %rdi
movl $0x29, %esi
callq 0x1ad6f
testq %rax, %rax
jne 0xd8e6
leaq 0x18(%rsp), %rdi
callq 0x1ae8f
testq %rax, %rax
je 0xda59
movw $0x400, 0xa(%rax)       # imm = 0x400
movl 0x90(%rbx), %edx
addq $0x10, %rbx
movq %rax, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x1b504
testl %eax, %eax
je 0xd93b
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xda8b
leaq 0x156eb(%rip), %rsi     # 0x23009
leaq 0x15596(%rip), %rdx     # 0x22ebb
leaq 0x1552b(%rip), %r8      # 0x22e57
movl $0x3, %edi
movl $0x24b, %ecx            # imm = 0x24B
jmp 0xda84
movq %rsp, %rdi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x1b58c
testl %eax, %eax
jle 0xd9de
leaq 0x18(%rsp), %rdi
callq 0x19ae0
movq 0x120(%r12), %rdx
movq 0x128(%r12), %rsi
movl 0x130(%r12), %ecx
leaq 0x14447(%rip), %rdi     # 0x21dc2
callq 0x13e60
testq %rax, %rax
je 0xda1a
movq %rax, %rbx
leaq 0x1555c(%rip), %rsi     # 0x22eef
leaq 0x15562(%rip), %rdx     # 0x22efc
movq %rax, %rdi
callq 0x13fd7
testl %eax, %eax
je 0xda9a
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xdb7b
leaq 0x15648(%rip), %rsi     # 0x23009
leaq 0x154f3(%rip), %rdx     # 0x22ebb
leaq 0x15545(%rip), %r8      # 0x22f14
movl $0x3, %edi
movl $0x263, %ecx            # imm = 0x263
jmp 0xdb74
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xda10
leaq 0x15618(%rip), %rsi     # 0x23009
leaq 0x154c3(%rip), %rdx     # 0x22ebb
leaq 0x14d6d(%rip), %r8      # 0x2276c
movl $0x3, %edi
movl $0x252, %ecx            # imm = 0x252
xorl %eax, %eax
callq 0x1771e
movq %rsp, %rdi
callq 0x1cdc9
jmp 0xda8b
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xda4c
leaq 0x155dc(%rip), %rsi     # 0x23009
leaq 0x15487(%rip), %rdx     # 0x22ebb
leaq 0x15497(%rip), %r8      # 0x22ed2
movl $0x3, %edi
movl $0x25c, %ecx            # imm = 0x25C
xorl %eax, %eax
callq 0x1771e
movq %rsp, %rdi
callq 0x1cdc9
jmp 0xdb8b
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xda8b
leaq 0x1559d(%rip), %rsi     # 0x23009
leaq 0x15448(%rip), %rdx     # 0x22ebb
leaq 0x153b8(%rip), %r8      # 0x22e32
movl $0x3, %edi
movl $0x242, %ecx            # imm = 0x242
xorl %eax, %eax
callq 0x1771e
leaq 0x18(%rsp), %rdi
callq 0x19ae0
jmp 0xdb8b
leaq 0x1569f(%rip), %rsi     # 0x23140
leaq 0x1569f(%rip), %rdx     # 0x23147
movq %rbx, %rdi
callq 0x13fd7
testl %eax, %eax
je 0xdae8
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xdb7b
leaq 0x1553e(%rip), %rsi     # 0x23009
leaq 0x153e9(%rip), %rdx     # 0x22ebb
leaq 0x1543b(%rip), %r8      # 0x22f14
movl $0x3, %edi
movl $0x26b, %ecx            # imm = 0x26B
jmp 0xdb74
leaq 0x15661(%rip), %rsi     # 0x23150
leaq 0x15651(%rip), %rdx     # 0x23147
movq %rbx, %rdi
callq 0x13fd7
testl %eax, %eax
je 0xdb2f
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xdb7b
leaq 0x154f4(%rip), %rsi     # 0x23009
leaq 0x1539f(%rip), %rdx     # 0x22ebb
leaq 0x153f1(%rip), %r8      # 0x22f14
movl $0x3, %edi
movl $0x273, %ecx            # imm = 0x273
jmp 0xdb74
leaq 0x153ff(%rip), %rsi     # 0x22f35
leaq 0x153ff(%rip), %rdx     # 0x22f3c
movq %rbx, %rdi
callq 0x13fd7
testl %eax, %eax
je 0xdb9c
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0xdb7b
leaq 0x154ad(%rip), %rsi     # 0x23009
leaq 0x15358(%rip), %rdx     # 0x22ebb
leaq 0x153aa(%rip), %r8      # 0x22f14
movl $0x3, %edi
movl $0x27b, %ecx            # imm = 0x27B
xorl %eax, %eax
callq 0x1771e
movq %rsp, %rdi
callq 0x1cdc9
movq %rbx, %rdi
callq 0x13ee7
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 0x1418d
movq (%r14), %rsi
movq %rbx, %rdi
callq 0x140fe
jmp 0xdb8d