// File: /workspace/github_c_makefile_star2_O1/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 0x19b12
movq %r15, %rdi
callq 0x19b12
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 0x19b6a
movq %rax, 0x10(%r15)
testq %rbx, %rbx
je 0xdd73
leaq 0x18(%rsp), %rdi
movl $0x29, %esi
callq 0x1b531
testq %rax, %rax
jne 0xdd1e
leaq 0x18(%rsp), %rdi
callq 0x1b653
testq %rax, %rax
je 0xde91
movw $0x400, 0xa(%rax)       # imm = 0x400
movl 0x90(%rbx), %edx
addq $0x10, %rbx
movq %rax, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x1bd22
testl %eax, %eax
je 0xdd73
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xdec3
leaq 0x152ab(%rip), %rsi     # 0x23001
leaq 0x15156(%rip), %rdx     # 0x22eb3
leaq 0x150eb(%rip), %r8      # 0x22e4f
movl $0x3, %edi
movl $0x24b, %ecx            # imm = 0x24B
jmp 0xdebc
movq %rsp, %rdi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x1bdbb
testl %eax, %eax
jle 0xde16
leaq 0x18(%rsp), %rdi
callq 0x1a1dd
movq 0x120(%r12), %rdx
movq 0x128(%r12), %rsi
movl 0x130(%r12), %ecx
leaq 0x1402f(%rip), %rdi     # 0x21de2
callq 0x14344
testq %rax, %rax
je 0xde52
movq %rax, %rbx
leaq 0x1511c(%rip), %rsi     # 0x22ee7
leaq 0x15122(%rip), %rdx     # 0x22ef4
movq %rax, %rdi
callq 0x144e9
testl %eax, %eax
je 0xded2
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xdfb3
leaq 0x15208(%rip), %rsi     # 0x23001
leaq 0x150b3(%rip), %rdx     # 0x22eb3
leaq 0x15105(%rip), %r8      # 0x22f0c
movl $0x3, %edi
movl $0x263, %ecx            # imm = 0x263
jmp 0xdfac
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xde48
leaq 0x151d8(%rip), %rsi     # 0x23001
leaq 0x15083(%rip), %rdx     # 0x22eb3
leaq 0x14955(%rip), %r8      # 0x2278c
movl $0x3, %edi
movl $0x252, %ecx            # imm = 0x252
xorl %eax, %eax
callq 0x17d92
movq %rsp, %rdi
callq 0x1d5f9
jmp 0xdec3
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xde84
leaq 0x1519c(%rip), %rsi     # 0x23001
leaq 0x15047(%rip), %rdx     # 0x22eb3
leaq 0x15057(%rip), %r8      # 0x22eca
movl $0x3, %edi
movl $0x25c, %ecx            # imm = 0x25C
xorl %eax, %eax
callq 0x17d92
movq %rsp, %rdi
callq 0x1d5f9
jmp 0xdfc3
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xdec3
leaq 0x1515d(%rip), %rsi     # 0x23001
leaq 0x15008(%rip), %rdx     # 0x22eb3
leaq 0x14f78(%rip), %r8      # 0x22e2a
movl $0x3, %edi
movl $0x242, %ecx            # imm = 0x242
xorl %eax, %eax
callq 0x17d92
leaq 0x18(%rsp), %rdi
callq 0x1a1dd
jmp 0xdfc3
leaq 0x1525f(%rip), %rsi     # 0x23138
leaq 0x1525f(%rip), %rdx     # 0x2313f
movq %rbx, %rdi
callq 0x144e9
testl %eax, %eax
je 0xdf20
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xdfb3
leaq 0x150fe(%rip), %rsi     # 0x23001
leaq 0x14fa9(%rip), %rdx     # 0x22eb3
leaq 0x14ffb(%rip), %r8      # 0x22f0c
movl $0x3, %edi
movl $0x26b, %ecx            # imm = 0x26B
jmp 0xdfac
leaq 0x15221(%rip), %rsi     # 0x23148
leaq 0x15211(%rip), %rdx     # 0x2313f
movq %rbx, %rdi
callq 0x144e9
testl %eax, %eax
je 0xdf67
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xdfb3
leaq 0x150b4(%rip), %rsi     # 0x23001
leaq 0x14f5f(%rip), %rdx     # 0x22eb3
leaq 0x14fb1(%rip), %r8      # 0x22f0c
movl $0x3, %edi
movl $0x273, %ecx            # imm = 0x273
jmp 0xdfac
leaq 0x14fbf(%rip), %rsi     # 0x22f2d
leaq 0x14fbf(%rip), %rdx     # 0x22f34
movq %rbx, %rdi
callq 0x144e9
testl %eax, %eax
je 0xdfd4
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0xdfb3
leaq 0x1506d(%rip), %rsi     # 0x23001
leaq 0x14f18(%rip), %rdx     # 0x22eb3
leaq 0x14f6a(%rip), %r8      # 0x22f0c
movl $0x3, %edi
movl $0x27b, %ecx            # imm = 0x27B
xorl %eax, %eax
callq 0x17d92
movq %rsp, %rdi
callq 0x1d5f9
movq %rbx, %rdi
callq 0x143e9
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 0x146c4
movq (%r14), %rsi
movq %rbx, %rdi
callq 0x14628
jmp 0xdfc5