// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/channel_udp.c
// Function: udp_query
static int udp_query(udpreq_t* rq, subnet_t* subnet)
{
	channel_udp_t* c = rq->ctx;
	int r = 0;
	ns_msg_t msg;
	int len;
	stream_t s = STREAM_INIT();
	int i = 0, n = 0;

	init_ns_msg(&msg);

	msg.id = rq->req_id;
	msg.flags = rq->flags;
	msg.qdcount = 1;
	msg.qrs = ns_qr_clone(&rq->qr, 1);

	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 -1;
			}
		}

		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 -1;
		}
	}

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

	ns_msg_free(&msg);


	for (i = 0, n = 0; i < c->upstream_num; i++) {
		s.pos = 0;
		r = udp_send(c->upstreams[i].sock, &s,
				(const struct sockaddr*)&c->upstreams[i].addr.addr,
				c->upstreams[i].addr.addrlen);
		if (r != s.size) {
			logw("udp_send() error - %s\n",
					get_sockaddrname(&c->upstreams[i].addr));
		}
		else {
			n++;
		}
	}

	if (n == 0) {
		loge("udp_send() error, no available upstream\n");
		stream_free(&s);
		return -1;
	}

	stream_free(&s);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3200
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x270f0
movq -0x10(%rbp), %rax
movw (%rax), %ax
movw %ax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movw 0x4(%rax), %ax
movw %ax, -0x46(%rbp)
movw $0x1, -0x44(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movl $0x1, %esi
callq 0x271c0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1907e
leaq -0x48(%rbp), %rdi
movl $0x29, %esi
callq 0x29010
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x19005
leaq -0x48(%rbp), %rdi
callq 0x29220
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x19003
jmp 0x18fba
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x18fec
movl $0x3, %edi
leaq 0x1dc21(%rip), %rsi     # 0x36bf3
leaq 0x1dc34(%rip), %rdx     # 0x36c0d
movl $0x8c, %ecx
leaq 0x1d447(%rip), %r8      # 0x3642c
movb $0x0, %al
callq 0x243b0
jmp 0x18fee
leaq -0x48(%rbp), %rdi
callq 0x27870
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x19253
jmp 0x19005
movq -0x78(%rbp), %rax
movw $0x400, 0xa(%rax)       # imm = 0x400
movq -0x78(%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 0x1907c
jmp 0x19033
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x19065
movl $0x3, %edi
leaq 0x1dba8(%rip), %rsi     # 0x36bf3
leaq 0x1dbbb(%rip), %rdx     # 0x36c0d
movl $0x95, %ecx
leaq 0x1d3f3(%rip), %r8      # 0x36451
movb $0x0, %al
callq 0x243b0
jmp 0x19067
leaq -0x48(%rbp), %rdi
callq 0x27870
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x19253
jmp 0x1907e
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
xorl %edx, %edx
callq 0x29ec0
movl %eax, -0x4c(%rbp)
cmpl $0x0, %eax
jg 0x190e9
jmp 0x19097
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x190c9
movl $0x3, %edi
leaq 0x1db44(%rip), %rsi     # 0x36bf3
leaq 0x1db57(%rip), %rdx     # 0x36c0d
movl $0x9c, %ecx
leaq 0x1cca0(%rip), %r8      # 0x35d62
movb $0x0, %al
callq 0x243b0
jmp 0x190cb
leaq -0x68(%rbp), %rdi
callq 0x2d640
leaq -0x48(%rbp), %rdi
callq 0x27870
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x19253
leaq -0x48(%rbp), %rdi
callq 0x27870
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x6c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x500(%rcx), %eax
jge 0x191f5
movl $0x0, -0x5c(%rbp)
movq -0x20(%rbp), %rax
addq $0x80, %rax
movslq -0x6c(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movl 0x88(%rax), %edi
movq -0x20(%rbp), %rdx
addq $0x80, %rdx
movslq -0x6c(%rbp), %rax
imulq $0x90, %rax, %rax
addq %rax, %rdx
movq -0x20(%rbp), %rax
addq $0x80, %rax
movslq -0x6c(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movl 0x80(%rax), %ecx
leaq -0x68(%rbp), %rsi
callq 0x26880
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x60(%rbp), %eax
je 0x191dc
jmp 0x19185
movb $0x0, %al
callq 0x242d0
cmpl $0x4, (%rax)
jl 0x191d8
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
movslq -0x6c(%rbp), %rax
imulq $0x90, %rax, %rax
addq %rax, %rdi
callq 0x198f0
movq %rax, %r9
movl $0x4, %edi
leaq 0x1da35(%rip), %rsi     # 0x36bf3
leaq 0x1da48(%rip), %rdx     # 0x36c0d
movl $0xac, %ecx
leaq 0x1dab4(%rip), %r8      # 0x36c85
movb $0x0, %al
callq 0x243b0
jmp 0x191da
jmp 0x191e5
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x191e7
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x19100
cmpl $0x0, -0x70(%rbp)
jne 0x19243
jmp 0x191fd
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x1922f
movl $0x3, %edi
leaq 0x1d9de(%rip), %rsi     # 0x36bf3
leaq 0x1d9f1(%rip), %rdx     # 0x36c0d
movl $0xb4, %ecx
leaq 0x1da74(%rip), %r8      # 0x36c9c
movb $0x0, %al
callq 0x243b0
jmp 0x19231
leaq -0x68(%rbp), %rdi
callq 0x2d640
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x19253
leaq -0x68(%rbp), %rdi
callq 0x2d640
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop