// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/channel_tcp.c
// Function: tcp_query
static int tcp_query(tcpreq_t *rq, int upstream, int proxy_index, subnet_t *subnet)
{
	channel_tcp_t* c = rq->ctx;
	int r = 0;
	int len;
	reqconn_t *conn;
	stream_t *s;
	conn_status cs;

	conn = reqconn_new(rq, upstream, proxy_index);
	if (!conn) {
		loge("Can't create reqconn_t\n");
		return -1;
	}

	s = &conn->conn.ws;

	len = tcp_create_nsmsg(s, rq, subnet);
	if (len <= 0) {
		loge("Can't create ns_msg_t binary data\n");
		reqconn_destroy(conn);
		return -1;
	}

	dllist_add(&rq->conns, &conn->conn.entry);

	cs = conn->conn.status;
	if (!conn->use_proxy && cs == cs_connected) {
		r = tcp_send(conn->conn.sock, s);
		if (r == -1) {
			loge("tcp_send() error\n");
			stream_free(s);
			return -1;
		}
		else if (stream_rsize(s) == 0) {
			stream_free(s);
		}
	}
	else if (conn->use_proxy && cs == cs_connected) {
		r = proxy_handshake(c, rq, conn);
		if (r == -1) {
			loge("proxy_handshake() error\n");
			stream_free(s);
			return -1;
		}
	}
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x16660
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x159e5
jmp 0x159a5
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x159d7
movl $0x3, %edi
leaq 0x20e73(%rip), %rsi     # 0x36830
leaq 0x20e86(%rip), %rdx     # 0x3684a
movl $0x16e, %ecx            # imm = 0x16E
leaq 0x20ebf(%rip), %r8      # 0x3688f
movb $0x0, %al
callq 0x243b0
jmp 0x159d9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x15bbd
movq -0x38(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x16850
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jg 0x15a56
jmp 0x15a0d
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x15a3f
movl $0x3, %edi
leaq 0x20e0b(%rip), %rsi     # 0x36830
leaq 0x20e1e(%rip), %rdx     # 0x3684a
movl $0x176, %ecx            # imm = 0x176
leaq 0x20e6f(%rip), %r8      # 0x368a7
movb $0x0, %al
callq 0x243b0
jmp 0x15a41
movq -0x38(%rbp), %rdi
callq 0x16ae0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x15bbd
jmp 0x15a58
movq -0x10(%rbp), %rcx
addq $0x48, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x38(%rbp), %rcx
addq $0x40, %rcx
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
addq $0x40, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x68(%rax)
jne 0x15b40
cmpl $0x2, -0x44(%rbp)
jne 0x15b40
movq -0x38(%rbp), %rax
movl (%rax), %edi
movq -0x40(%rbp), %rsi
callq 0x265a0
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0x15b20
jmp 0x15ad7
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x15b09
movl $0x3, %edi
leaq 0x20d41(%rip), %rsi     # 0x36830
leaq 0x20d54(%rip), %rdx     # 0x3684a
movl $0x181, %ecx            # imm = 0x181
leaq 0x20dc8(%rip), %r8      # 0x368ca
movb $0x0, %al
callq 0x243b0
jmp 0x15b0b
movq -0x40(%rbp), %rdi
callq 0x2d640
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x15bbd
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x40(%rbp), %rcx
subl 0xc(%rcx), %eax
cmpl $0x0, %eax
jne 0x15b3c
movq -0x40(%rbp), %rdi
callq 0x2d640
jmp 0x15b3e
jmp 0x15bb6
movq -0x38(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x15bb4
cmpl $0x2, -0x44(%rbp)
jne 0x15bb4
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x16b20
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0x15bb2
jmp 0x15b6c
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x15b9e
movl $0x3, %edi
leaq 0x20cac(%rip), %rsi     # 0x36830
leaq 0x20cbf(%rip), %rdx     # 0x3684a
movl $0x18c, %ecx            # imm = 0x18C
leaq 0x20d45(%rip), %r8      # 0x368dc
movb $0x0, %al
callq 0x243b0
jmp 0x15ba0
movq -0x40(%rbp), %rdi
callq 0x2d640
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x15bbd
jmp 0x15bb4
jmp 0x15bb6
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)