// File: /workspace/github_c_makefile_star2_O0/GangZhuo[P]dohclient/src/channel_tcp.c
// Function: req_step
static int req_step(channel_t* ctx, tcpreq_t *req, time_t now,
	fd_set* readset, fd_set* writeset, fd_set* errorset)
{
	channel_tcp_t *c = (channel_tcp_t*)ctx;
	dlitem_t *cur, *nxt;
	reqconn_t *conn;
	conn_status cs;
	int is_sending;
	int r = 0, rv = -1;
	dllist_foreach(&req->conns, cur, nxt, reqconn_t, conn, conn.entry) {
		cs = conn->conn.status;
		r = 0;
		if (cs == cs_closing || cs == cs_rsp_closing) {
			r = -1;
		}
		else if (FD_ISSET(conn->conn.sock, errorset)) {
			int err = getsockerr(conn->conn.sock);
			loge("sock error: errno=%d, %s - %s\n",
				err, strerror(err), get_sockaddrname(&c->upstreams[conn->upstream]));
			r = -1;
		}
		else {
			if (cs == cs_socks5_handshaked || cs == cs_hp_handshaked ||
					(!conn->use_proxy && cs == cs_connected)) {
				is_sending = stream_rsize(&conn->conn.ws) > 0;
				if (is_sending) {
					if (FD_ISSET(conn->conn.sock, writeset)) {
						r = tcp_send(conn->conn.sock, &conn->conn.ws);
						if (r >= 0)
							r = 0;
					}
				}
				else if (FD_ISSET(conn->conn.sock, readset)) {
					r = req_recv(req, conn);
					if (r >= 0)
						r = 0;
				}
			}
			else if (cs == cs_socks5_waiting_method || cs == cs_socks5_waiting_connect ||
					cs == cs_hp_waiting_connect || cs == cs_hp_waiting_data) {
				if (FD_ISSET(conn->conn.sock, readset)) {
					r = proxy_handshake(c, req, conn);
				}
			}
			else if (cs == cs_socks5_sending_method || cs == cs_socks5_sending_connect ||
					cs == cs_hp_sending_connect) {
				if (FD_ISSET(conn->conn.sock, writeset)) {
					r = proxy_handshake(c, req, conn);
				}
			}
			else if (cs == cs_connecting) {
				if (FD_ISSET(conn->conn.sock, writeset)) {
					conn->conn.status = cs_connected;
					if (conn->use_proxy) {
						r = proxy_handshake(c, req, conn);
					}
					else {
						if (stream_rsize(&conn->conn.ws) > 0) {
							r = tcp_send(conn->conn.sock, &conn->conn.ws);
							if (r >= 0)
								r = 0;
						}
					}
				}
			}
		}

		if (r == 0) {
			/* Return success when more than one connection have no error */
			rv = 0;
		}
		else if (r != 0) {
			dllist_init_remove(&conn->conn.entry);
			reqconn_destroy(conn);
		}
	}

	return rv;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0xffffffff, -0x60(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
xorl %eax, %eax
movq %rax, %rcx
addq $0x40, %rcx
subq %rcx, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
addq $0x48, %rcx
cmpq %rcx, %rax
sete %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x18151
jmp 0x1862e
movq -0x50(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x54(%rbp)
movl $0x0, -0x5c(%rbp)
cmpl $0x3, -0x54(%rbp)
je 0x1816e
cmpl $0x4, -0x54(%rbp)
jne 0x1817a
movl $0xffffffff, -0x5c(%rbp) # imm = 0xFFFFFFFF
jmp 0x1859d
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x78(%rbp), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x70(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x18266
movq -0x50(%rbp), %rax
movl (%rax), %edi
callq 0x24f80
movl %eax, -0x64(%rbp)
movb $0x0, %al
callq 0x242d0
cmpl $0x3, (%rax)
jl 0x18258
movl -0x64(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x64(%rbp), %edi
callq 0x3150
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rdi
addq $0x70, %rdi
movq -0x50(%rbp), %rax
movslq 0x90(%rax), %rax
imulq $0x88, %rax, %rax
addq %rax, %rdi
callq 0x17bd0
movl -0x84(%rbp), %r9d
movq -0x80(%rbp), %r10
movl $0x3, %edi
leaq 0x1e5fb(%rip), %rsi     # 0x36830
leaq 0x1e8fb(%rip), %rdx     # 0x36b37
movl $0x327, %ecx            # imm = 0x327
leaq 0x1e8f8(%rip), %r8      # 0x36b40
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x243b0
jmp 0x1825a
movl $0xffffffff, -0x5c(%rbp) # imm = 0xFFFFFFFF
jmp 0x1859b
cmpl $0x9, -0x54(%rbp)
je 0x1828a
cmpl $0xd, -0x54(%rbp)
je 0x1828a
movq -0x50(%rbp), %rax
cmpl $0x0, 0x68(%rax)
jne 0x183b3
cmpl $0x2, -0x54(%rbp)
jne 0x183b3
movq -0x50(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x50(%rbp), %rcx
subl 0x2c(%rcx), %eax
cmpl $0x0, %eax
setg %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x18332
movq -0x28(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x98(%rbp), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x90(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x90(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x18330
movq -0x50(%rbp), %rax
movl (%rax), %edi
movq -0x50(%rbp), %rsi
addq $0x20, %rsi
callq 0x265a0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jl 0x1832e
movl $0x0, -0x5c(%rbp)
jmp 0x18330
jmp 0x183ae
movq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xa8(%rbp), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xa0(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x183ac
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x18670
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jl 0x183aa
movl $0x0, -0x5c(%rbp)
jmp 0x183ac
jmp 0x183ae
jmp 0x18599
cmpl $0x6, -0x54(%rbp)
je 0x183cb
cmpl $0x8, -0x54(%rbp)
je 0x183cb
cmpl $0xb, -0x54(%rbp)
je 0x183cb
cmpl $0xc, -0x54(%rbp)
jne 0x1843f
movq -0x20(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xb8(%rbp), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xb0(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xb0(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x1843a
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x16b20
movl %eax, -0x5c(%rbp)
jmp 0x18597
cmpl $0x5, -0x54(%rbp)
je 0x18451
cmpl $0x7, -0x54(%rbp)
je 0x18451
cmpl $0xa, -0x54(%rbp)
jne 0x184c5
movq -0x28(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xc8(%rbp), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xc0(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xc0(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x184c0
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x16b20
movl %eax, -0x5c(%rbp)
jmp 0x18595
cmpl $0x1, -0x54(%rbp)
jne 0x18593
movq -0x28(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xd8(%rbp), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xd0(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xd0(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x18591
movq -0x50(%rbp), %rax
movl $0x2, 0x38(%rax)
movq -0x50(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x18555
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x16b20
movl %eax, -0x5c(%rbp)
jmp 0x1858f
movq -0x50(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x50(%rbp), %rcx
subl 0x2c(%rcx), %eax
cmpl $0x0, %eax
jle 0x1858d
movq -0x50(%rbp), %rax
movl (%rax), %edi
movq -0x50(%rbp), %rsi
addq $0x20, %rsi
callq 0x265a0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jl 0x1858b
movl $0x0, -0x5c(%rbp)
jmp 0x1858d
jmp 0x1858f
jmp 0x18591
jmp 0x18593
jmp 0x18595
jmp 0x18597
jmp 0x18599
jmp 0x1859b
jmp 0x1859d
cmpl $0x0, -0x5c(%rbp)
jne 0x185ac
movl $0x0, -0x60(%rbp)
jmp 0x18600
cmpl $0x0, -0x5c(%rbp)
je 0x185fe
jmp 0x185b4
jmp 0x185b6
movq -0x50(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x50(%rbp), %rax
movq 0x40(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x50(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x50(%rbp), %rdi
callq 0x16ae0
jmp 0x18600
jmp 0x18602
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
xorl %eax, %eax
movq %rax, %rcx
addq $0x40, %rcx
subq %rcx, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x18134
movl -0x60(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopw (%rax,%rax)