// File: /workspace/github_c_makefile_star2_O3/GangZhuo[P]dohclient/src/http.c
// Function: dl_step_func
static void dl_step_func(dllist_t* conns, http_step_state* st)
{
	dlitem_t* cur, * nxt;
	http_conn_t* conn;
	conn_status cs;
	http_request_t* req;
	http_response_t* res;
	time_t now;
	int r = 0;
	int is_sending;
	int is_req_expired;
	now = time(NULL);
	dllist_foreach(conns, cur, nxt,
		http_conn_t, 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, st->errorset)) {
			int err = getsockerr(conn->conn.sock);
			loge("sock error: errno=%d, %s \n",
				err, strerror(err));
			r = -1;
		}
		else {
			if (cs == cs_ssl_handshaked) {
				if (conn->ssl_status == SSL_ERROR_WANT_READ) {
					if (FD_ISSET(conn->conn.sock, st->readset)) {
						is_sending = stream_rsize(&conn->conn.ws) > 0;
						if (is_sending) {
							r = http_conn_send(conn);
							if (r >= 0)
								r = 0;
						}
						else {
							r = http_conn_recv(conn);
							if (r >= 0)
								r = 0;
						}
					}
				}
				else if (conn->ssl_status == SSL_ERROR_WANT_WRITE) {
					if (FD_ISSET(conn->conn.sock, st->writeset)) {
						is_sending = stream_rsize(&conn->conn.ws) > 0;
						if (is_sending) {
							r = http_conn_send(conn);
							if (r >= 0)
								r = 0;
						}
						else {
							r = http_conn_recv(conn);
							if (r >= 0)
								r = 0;
						}
					}
				}
				else {
					is_sending = stream_rsize(&conn->conn.ws) > 0;
					if (is_sending) {
						if (FD_ISSET(conn->conn.sock, st->writeset)) {
							r = http_conn_send(conn);
							if (r >= 0)
								r = 0;
						}
					}
					else if (FD_ISSET(conn->conn.sock, st->readset)) {
						r = http_conn_recv(conn);
						if (r >= 0)
							r = 0;
					}
				}
			}
			else if (cs == cs_ssl_handshaking_want_read) {
				if (FD_ISSET(conn->conn.sock, st->readset)) {
					r = http_ssl_handshake(st->ctx, conn);
				}
			}
			else if (cs == cs_ssl_handshaking_want_write) {
				if (FD_ISSET(conn->conn.sock, st->writeset)) {
					r = http_ssl_handshake(st->ctx, conn);
				}
			}
			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, st->readset)) {
					r = http_proxy_handshake(st->ctx, conn);
				}
			}
			else if (cs == cs_socks5_sending_method || cs == cs_socks5_sending_connect ||
					cs == cs_hp_sending_connect) {
				if (FD_ISSET(conn->conn.sock, st->writeset)) {
					r = http_proxy_handshake(st->ctx, conn);
				}
			}
			else if (cs == cs_connecting) {
				if (FD_ISSET(conn->conn.sock, st->writeset)) {
					conn->conn.status = cs_connected;
					if (conn->use_proxy && st->ctx->proxy_num > 0) {
						r = http_proxy_handshake(st->ctx, conn);
					}
					else {
						r = http_ssl_handshake(st->ctx, conn);
					}
				}
			}
		}

		if (r == 0 && ((is_req_expired = http_is_request_expired(conn, now)) || http_is_expired(conn, now))) {
			if (is_req_expired)
				loge("http request timeout - %s\n", get_sockname(conn->conn.sock));
			else
				logd("http connection timeout - %s\n", get_sockname(conn->conn.sock));
			r = -1;
			req = conn->request;
			res = conn->response;
			if (req) {
				http_call_callback(req, HTTP_TIMEOUT, res);
			}
			http_conn_close(conn);
		}
		else if (r != 0) {
			req = conn->request;
			res = conn->response;
			if (req) {
				http_call_callback(req, HTTP_ERROR, res);
			}
			http_remove_conn(conn);
			http_conn_free(conn);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorl %edi, %edi
callq 0x3310
movq %rax, 0x10(%rsp)
movq (%r14), %r15
cmpq %r14, %r15
je 0x16e24
movq %r15, %r13
movq (%r15), %r15
leaq -0x90(%r13), %rbp
movl -0x48(%r13), %esi
leal -0x3(%rsi), %eax
cmpl $0x2, %eax
jb 0x16cd8
movq 0x18(%rbx), %rcx
movl -0x80(%r13), %edi
leal 0x3f(%rdi), %edx
testl %edi, %edi
cmovnsl %edi, %edx
movl %edx, %eax
sarl $0x6, %eax
cltq
movq (%rcx,%rax,8), %r8
andl $-0x40, %edx
movl %edi, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
btq %rcx, %r8
jae 0x16be3
callq 0x17e19
movl %eax, %r12d
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x16cd8
movl %r12d, %edi
callq 0x3140
movq %rax, (%rsp)
movl $0x3, %edi
leaq 0xd173(%rip), %rsi      # 0x23d34
leaq 0xd585(%rip), %rdx      # 0x2414d
movl $0x6b5, %ecx            # imm = 0x6B5
leaq 0xf58c(%rip), %r8       # 0x26160
movl %r12d, %r9d
xorl %eax, %eax
callq 0x1771e
jmp 0x16cd8
decl %esi
cmpl $0x10, %esi
ja 0x16d30
leaq 0xd0cb(%rip), %rdi      # 0x23cc0
movslq (%rdi,%rsi,4), %rcx
addq %rdi, %rcx
jmpq *%rcx
movq 0x8(%rbx), %rcx
jmp 0x16c08
movq 0x10(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x16d30
movq (%rbx), %rax
movq 0x10(%rax), %rdi
movq %rbp, %rsi
callq 0x15830
jmp 0x16cd4
movq 0x10(%rbx), %rcx
jmp 0x16c6f
movq 0x10(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x16d30
movl $0x2, -0x48(%r13)
cmpl $0x0, -0x88(%r13)
je 0x16c79
movq (%rbx), %rax
cmpl $0x0, 0x18(%rax)
jg 0x16c15
jmp 0x16c79
movl -0x10(%r13), %ecx
cmpl $0x3, %ecx
je 0x16c83
cmpl $0x2, %ecx
jne 0x16c9d
movq 0x8(%rbx), %rcx
jmp 0x16c87
movq 0x8(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x16d30
movq %rbp, %rdi
callq 0x164c8
jmp 0x16cd4
movq 0x10(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x16d30
movl -0x58(%r13), %eax
cmpl -0x54(%r13), %eax
jg 0x16cb1
jmp 0x16cc5
movl -0x58(%r13), %ecx
cmpl -0x54(%r13), %ecx
jle 0x16cbb
movq 0x10(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x16d30
movq %rbp, %rdi
callq 0x166e5
jmp 0x16ccd
movq 0x8(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x16d30
movq %rbp, %rdi
callq 0x16e33
movl %eax, %ecx
sarl $0x1f, %eax
andl %ecx, %eax
testl %eax, %eax
je 0x16d30
movq 0x10(%r13), %rsi
testq %rsi, %rsi
je 0x16d1b
movq 0x18(%r13), %rdx
movq 0x38(%rsi), %rax
testq %rax, %rax
je 0x16cfb
xorl %ecx, %ecx
movq %rcx, 0xa0(%rax)
movq %rcx, 0x38(%rsi)
movq 0x40(%rsi), %rax
testq %rax, %rax
je 0x16d1b
leaq 0x40(%rsi), %r12
movq 0x48(%rsi), %rcx
movl $0x3, %edi
callq *%rax
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movq %rbp, %rdi
callq 0x170a6
movq %rbp, %rdi
callq 0x1690e
jmp 0x16b3b
movq 0x10(%r13), %rax
testq %rax, %rax
je 0x16d51
movq 0x60(%rax), %rax
testq %rax, %rax
setle %cl
cmpq 0x10(%rsp), %rax
setg %al
orb %cl, %al
cmpb $0x1, %al
jne 0x16d96
movq 0x10(%rsp), %rax
cmpq %rax, -0x30(%r13)
jg 0x16b3b
xorl %eax, %eax
callq 0x176e5
cmpl $0x7, (%rax)
jl 0x16dd4
movl -0x80(%r13), %edi
callq 0x17f1b
movl $0x7, %edi
leaq 0xcfb3(%rip), %rsi      # 0x23d34
leaq 0xd3c5(%rip), %rdx      # 0x2414d
movl $0x70f, %ecx            # imm = 0x70F
leaq 0xd3e1(%rip), %r8       # 0x24175
jmp 0x16dca
xorl %eax, %eax
callq 0x176e5
cmpl $0x3, (%rax)
jl 0x16dd4
movl -0x80(%r13), %edi
callq 0x17f1b
movl $0x3, %edi
leaq 0xcf7d(%rip), %rsi      # 0x23d34
leaq 0xd38f(%rip), %rdx      # 0x2414d
movl $0x70d, %ecx            # imm = 0x70D
leaq 0xd390(%rip), %r8       # 0x2415a
movq %rax, %r9
xorl %eax, %eax
callq 0x1771e
movq 0x10(%r13), %rsi
testq %rsi, %rsi
je 0x16e17
movq 0x18(%r13), %rdx
movq 0x38(%rsi), %rax
testq %rax, %rax
je 0x16df7
xorl %ecx, %ecx
movq %rcx, 0xa0(%rax)
movq %rcx, 0x38(%rsi)
movq 0x40(%rsi), %rax
testq %rax, %rax
je 0x16e17
leaq 0x40(%rsi), %r12
movq 0x48(%rsi), %rcx
movl $0x2, %edi
callq *%rax
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movq %rbp, %rdi
callq 0x16648
jmp 0x16b3b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq