// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rdi, %r14
xorl %edi, %edi
callq 0x3310
movq %rax, 0x10(%rsp)
movq (%r14), %r12
cmpq %r14, %r12
je 0x17486
movq %r12, %r15
movq (%r12), %r12
leaq -0x90(%r15), %rbp
movl -0x48(%r15), %esi
leal -0x3(%rsi), %eax
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpl $0x2, %eax
jb 0x172da
movq 0x18(%r13), %rcx
movl -0x80(%r15), %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 0x1723c
movq %rbp, %rbx
movq %r14, %rbp
movq %r13, %r14
callq 0x1847d
movl %eax, %r13d
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x17228
movl %r13d, %edi
callq 0x3140
movq %rax, (%rsp)
movl $0x3, %edi
leaq 0xcb1d(%rip), %rsi      # 0x23d28
leaq 0xcf2f(%rip), %rdx      # 0x24141
movl $0x6b5, %ecx            # imm = 0x6B5
leaq 0xef00(%rip), %r8       # 0x2611e
movl %r13d, %r9d
xorl %eax, %eax
callq 0x17d92
movq %r14, %r13
movq %rbp, %r14
movq %rbx, %rbp
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
jmp 0x172da
xorl %r8d, %r8d
decl %esi
cmpl $0x10, %esi
ja 0x172da
leaq 0xca63(%rip), %rdi      # 0x23cb4
movslq (%rdi,%rsi,4), %rcx
addq %rdi, %rcx
jmpq *%rcx
movq 0x8(%r13), %rcx
jmp 0x17264
movq 0x10(%r13), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x172da
movq (%r13), %rdi
movq %rbp, %rsi
callq 0x15db1
jmp 0x172d7
movq 0x10(%r13), %rcx
jmp 0x172c9
movq 0x10(%r13), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x172da
movl $0x2, -0x48(%r15)
cmpl $0x0, -0x88(%r15)
je 0x172cf
movq (%r13), %rdi
cmpl $0x0, 0x18(%rdi)
jg 0x1726e
jmp 0x172cf
movl -0x10(%r15), %ecx
cmpl $0x3, %ecx
je 0x17425
cmpl $0x2, %ecx
jne 0x1743f
movq 0x8(%r13), %rcx
jmp 0x17429
movq 0x8(%r13), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x172da
movq %rbp, %rdi
callq 0x16a6d
movl %eax, %r8d
movq 0x10(%r15), %rsi
testl %r8d, %r8d
je 0x17336
testq %rsi, %rsi
je 0x17321
movq 0x18(%r15), %rdx
movq 0x38(%rsi), %rax
testq %rax, %rax
je 0x17302
xorl %ecx, %ecx
movq %rcx, 0xa0(%rax)
movq %rcx, 0x38(%rsi)
movq 0x40(%rsi), %rax
testq %rax, %rax
je 0x17321
leaq 0x40(%rsi), %r15
movq 0x48(%rsi), %rcx
movl $0x3, %edi
callq *%rax
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq %rbp, %rdi
callq 0x17707
movq %rbp, %rdi
callq 0x16efc
jmp 0x17179
testq %rsi, %rsi
je 0x17353
movq 0x60(%rsi), %rax
testq %rax, %rax
setle %cl
cmpq 0x10(%rsp), %rax
setg %al
orb %cl, %al
cmpb $0x1, %al
jne 0x17398
movq 0x10(%rsp), %rax
cmpq %rax, -0x30(%r15)
jg 0x17179
xorl %eax, %eax
callq 0x17d59
cmpl $0x7, (%rax)
jl 0x173d6
movl -0x80(%r15), %edi
callq 0x1857f
movl $0x7, %edi
leaq 0xc9a5(%rip), %rsi      # 0x23d28
leaq 0xcdb7(%rip), %rdx      # 0x24141
movl $0x70f, %ecx            # imm = 0x70F
leaq 0xcdd3(%rip), %r8       # 0x24169
jmp 0x173cc
xorl %eax, %eax
callq 0x17d59
cmpl $0x3, (%rax)
jl 0x173d6
movl -0x80(%r15), %edi
callq 0x1857f
movl $0x3, %edi
leaq 0xc96f(%rip), %rsi      # 0x23d28
leaq 0xcd81(%rip), %rdx      # 0x24141
movl $0x70d, %ecx            # imm = 0x70D
leaq 0xcd82(%rip), %r8       # 0x2414e
movq %rax, %r9
xorl %eax, %eax
callq 0x17d92
movq 0x10(%r15), %rsi
testq %rsi, %rsi
je 0x17418
movq 0x18(%r15), %rdx
movq 0x38(%rsi), %rax
testq %rax, %rax
je 0x173f9
xorl %ecx, %ecx
movq %rcx, 0xa0(%rax)
movq %rcx, 0x38(%rsi)
movq 0x40(%rsi), %rax
testq %rax, %rax
je 0x17418
leaq 0x40(%rsi), %r15
movq 0x48(%rsi), %rcx
movl $0x2, %edi
callq *%rax
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq %rbp, %rdi
callq 0x16bfa
jmp 0x17179
movq 0x10(%r13), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x172da
movl -0x58(%r15), %eax
cmpl -0x54(%r15), %eax
jg 0x17457
jmp 0x1746f
movl -0x58(%r15), %ecx
cmpl -0x54(%r15), %ecx
jle 0x17461
movq 0x10(%r13), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x172da
movq %rbp, %rdi
callq 0x16c97
jmp 0x17477
movq 0x8(%r13), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x172da
movq %rbp, %rdi
callq 0x17495
movl %eax, %r8d
sarl $0x1f, %r8d
andl %eax, %r8d
jmp 0x172da
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq