// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/channel_doh.c
// Function: doh_build_get_request
static http_request_t* doh_build_get_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();
	char* dns;
	int dns_len;

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

	dns = base64url_encode(s.array, s.size, &dns_len, FALSE, TRUE);
	if (!dns) {
		loge("base64_encode() error\n");
		stream_free(&s);
		return NULL;
	}

	stream_reset(&s);

	if (stream_appendf(&s,
		"%s?dns=%s",
		c->path,
		dns) == -1) {
		loge("stream_appendf()\n");
		stream_free(&s);
		return NULL;
	}

	free(dns);

	req = http_request_create("GET", s.array, 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, "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 %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3200
leaq -0x48(%rbp), %rdi
callq 0x270f0
movq -0x10(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x14950
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x14159
jmp 0x14118
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1414a
movl $0x3, %edi
leaq 0x224d3(%rip), %rsi     # 0x36603
leaq 0x22403(%rip), %rdx     # 0x3653a
movl $0x296, %ecx            # imm = 0x296
leaq 0x221aa(%rip), %r8      # 0x362ed
movb $0x0, %al
callq 0x243b0
jmp 0x1414c
movq $0x0, -0x8(%rbp)
jmp 0x14552
cmpq $0x0, -0x18(%rbp)
je 0x14259
leaq -0x48(%rbp), %rdi
movl $0x29, %esi
callq 0x29010
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x141df
leaq -0x48(%rbp), %rdi
callq 0x29220
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x141dd
jmp 0x14193
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x141c5
movl $0x3, %edi
leaq 0x22458(%rip), %rsi     # 0x36603
leaq 0x22388(%rip), %rdx     # 0x3653a
movl $0x2a0, %ecx            # imm = 0x2A0
leaq 0x2226e(%rip), %r8      # 0x3642c
movb $0x0, %al
callq 0x243b0
jmp 0x141c7
leaq -0x48(%rbp), %rdi
callq 0x27870
movq $0x0, -0x8(%rbp)
jmp 0x14552
jmp 0x141df
movq -0x80(%rbp), %rax
movw $0x400, 0xa(%rax)       # imm = 0x400
movq -0x80(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x10, %rsi
movq -0x18(%rbp), %rax
movl 0x90(%rax), %edx
xorl %ecx, %ecx
callq 0x29e00
cmpl $0x0, %eax
je 0x14257
jmp 0x1420d
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1423f
movl $0x3, %edi
leaq 0x223de(%rip), %rsi     # 0x36603
leaq 0x2230e(%rip), %rdx     # 0x3653a
movl $0x2a9, %ecx            # imm = 0x2A9
leaq 0x22219(%rip), %r8      # 0x36451
movb $0x0, %al
callq 0x243b0
jmp 0x14241
leaq -0x48(%rbp), %rdi
callq 0x27870
movq $0x0, -0x8(%rbp)
jmp 0x14552
jmp 0x14259
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x29ec0
movl %eax, -0x50(%rbp)
cmpl $0x0, %eax
jg 0x142c5
jmp 0x14272
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x142a4
movl $0x3, %edi
leaq 0x22379(%rip), %rsi     # 0x36603
leaq 0x222a9(%rip), %rdx     # 0x3653a
movl $0x2b0, %ecx            # imm = 0x2B0
leaq 0x21ac5(%rip), %r8      # 0x35d62
movb $0x0, %al
callq 0x243b0
jmp 0x142a6
leaq -0x68(%rbp), %rdi
callq 0x2d640
leaq -0x48(%rbp), %rdi
callq 0x27870
movq $0x0, -0x8(%rbp)
jmp 0x14552
leaq -0x48(%rbp), %rdi
callq 0x27870
movq -0x68(%rbp), %rdi
movl -0x60(%rbp), %esi
leaq -0x74(%rbp), %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0xb860
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x1433d
jmp 0x142f3
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x14325
movl $0x3, %edi
leaq 0x222f8(%rip), %rsi     # 0x36603
leaq 0x22228(%rip), %rdx     # 0x3653a
movl $0x2ba, %ecx            # imm = 0x2BA
leaq 0x22232(%rip), %r8      # 0x36550
movb $0x0, %al
callq 0x243b0
jmp 0x14327
leaq -0x68(%rbp), %rdi
callq 0x2d640
movq $0x0, -0x8(%rbp)
jmp 0x14552
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq 0x128(%rax), %rdx
movq -0x70(%rbp), %rcx
leaq -0x68(%rbp), %rdi
leaq 0x22202(%rip), %rsi     # 0x36567
movb $0x0, %al
callq 0x2e2a0
cmpl $-0x1, %eax
jne 0x143bd
jmp 0x14373
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x143a5
movl $0x3, %edi
leaq 0x22278(%rip), %rsi     # 0x36603
leaq 0x221a8(%rip), %rdx     # 0x3653a
movl $0x2c5, %ecx            # imm = 0x2C5
leaq 0x221d3(%rip), %r8      # 0x36571
movb $0x0, %al
callq 0x243b0
jmp 0x143a7
leaq -0x68(%rbp), %rdi
callq 0x2d640
movq $0x0, -0x8(%rbp)
jmp 0x14552
movq -0x70(%rbp), %rdi
callq 0x3460
movq -0x68(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x120(%rax), %rdx
movq -0x20(%rbp), %rax
movl 0x130(%rax), %ecx
leaq 0x2101c(%rip), %rdi     # 0x35402
callq 0x1e3d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x14442
jmp 0x143f8
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1442a
movl $0x3, %edi
leaq 0x221f3(%rip), %rsi     # 0x36603
leaq 0x22123(%rip), %rdx     # 0x3653a
movl $0x2ce, %ecx            # imm = 0x2CE
leaq 0x220a9(%rip), %r8      # 0x364cc
movb $0x0, %al
callq 0x243b0
jmp 0x1442c
leaq -0x68(%rbp), %rdi
callq 0x2d640
movq $0x0, -0x8(%rbp)
jmp 0x14552
movq -0x28(%rbp), %rdi
leaq 0x2209c(%rip), %rsi     # 0x364e9
leaq 0x220a2(%rip), %rdx     # 0x364f6
callq 0x1e6c0
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x144b7
jmp 0x14464
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x14496
movl $0x3, %edi
leaq 0x22187(%rip), %rsi     # 0x36603
leaq 0x220b7(%rip), %rdx     # 0x3653a
movl $0x2d5, %ecx            # imm = 0x2D5
leaq 0x2207f(%rip), %r8      # 0x3650e
movb $0x0, %al
callq 0x243b0
jmp 0x14498
leaq -0x68(%rbp), %rdi
callq 0x2d640
movq -0x28(%rbp), %rdi
callq 0x1e4b0
movq $0x0, -0x8(%rbp)
jmp 0x14552
movq -0x28(%rbp), %rdi
leaq 0x2206d(%rip), %rsi     # 0x3652f
leaq 0x2206d(%rip), %rdx     # 0x36536
callq 0x1e6c0
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x14529
jmp 0x144d9
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1450b
movl $0x3, %edi
leaq 0x22112(%rip), %rsi     # 0x36603
leaq 0x22042(%rip), %rdx     # 0x3653a
movl $0x2dd, %ecx            # imm = 0x2DD
leaq 0x2200a(%rip), %r8      # 0x3650e
movb $0x0, %al
callq 0x243b0
jmp 0x1450d
leaq -0x68(%rbp), %rdi
callq 0x2d640
movq -0x28(%rbp), %rdi
callq 0x1e4b0
movq $0x0, -0x8(%rbp)
jmp 0x14552
movq -0x28(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl -0x60(%rbp), %edx
callq 0x1ea40
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x1e950
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nop