// File: /workspace/github_c_makefile_star2_O2/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 0x3320
movq %rax, 0x10(%rsp)
movq (%r14), %rbp
cmpq %r14, %rbp
je 0x15e47
movq %rbp, %r15
movq (%rbp), %rbp
leaq -0x90(%r15), %r12
movl -0x48(%r15), %esi
leal -0x3(%rsi), %eax
cmpl $0x2, %eax
jb 0x15d5b
movq 0x18(%rbx), %r8
movl -0x80(%r15), %edi
movl %edi, %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
movl %edx, %ecx
cltq
movq (%r8,%rax,8), %r8
pushq $0x1
popq %rdx
shlq %cl, %rdx
btq %rcx, %r8
jae 0x15c6e
callq 0x16d2f
movl %eax, %r13d
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x15d5b
movl %r13d, %edi
callq 0x3140
movq %rax, (%rsp)
pushq $0x3
popq %rdi
leaq 0xc0e8(%rip), %rsi      # 0x21d34
leaq 0xc4fa(%rip), %rdx      # 0x2214d
movl $0x6b5, %ecx            # imm = 0x6B5
leaq 0xe4ef(%rip), %r8       # 0x2414e
movl %r13d, %r9d
xorl %eax, %eax
callq 0x1662e
jmp 0x15d5b
decl %esi
cmpl $0x10, %esi
ja 0x15d85
leaq 0xc040(%rip), %rdi      # 0x21cc0
movslq (%rdi,%rsi,4), %rcx
addq %rdi, %rcx
jmpq *%rcx
movq 0x8(%rbx), %rcx
jmp 0x15c93
movq 0x10(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x15d85
movq (%rbx), %rdi
movq %r12, %rsi
callq 0x149cb
jmp 0x15d57
movq 0x10(%rbx), %rcx
jmp 0x15cf6
movq 0x10(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x15d85
movl $0x2, -0x48(%r15)
cmpl $0x0, -0x88(%r15)
je 0x15d00
movq (%rbx), %rdi
cmpl $0x0, 0x18(%rdi)
jg 0x15ca0
jmp 0x15d00
movl -0x10(%r15), %ecx
cmpl $0x3, %ecx
je 0x15d0a
cmpl $0x2, %ecx
jne 0x15d20
movq 0x8(%rbx), %rcx
jmp 0x15d0e
movq 0x8(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x15d85
movq %r12, %rdi
callq 0x155d6
jmp 0x15d57
movq 0x10(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x15d85
movl -0x58(%r15), %eax
cmpl -0x54(%r15), %eax
jg 0x15d34
jmp 0x15d48
movl -0x58(%r15), %ecx
cmpl -0x54(%r15), %ecx
jle 0x15d3e
movq 0x10(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x15d85
movq %r12, %rdi
callq 0x1579d
jmp 0x15d50
movq 0x8(%rbx), %rcx
testq %rdx, (%rcx,%rax,8)
je 0x15d85
movq %r12, %rdi
callq 0x15e56
movl %eax, %ecx
sarl $0x1f, %eax
andl %ecx, %eax
testl %eax, %eax
je 0x15d85
movq 0x10(%r15), %rdi
testq %rdi, %rdi
je 0x15d70
movq 0x18(%r15), %rdx
pushq $0x3
popq %rsi
callq 0x15a90
movq %r12, %rdi
callq 0x16093
movq %r12, %rdi
callq 0x159d6
jmp 0x15bd3
movq 0x10(%r15), %rax
testq %rax, %rax
je 0x15da6
movq 0x60(%rax), %rax
testq %rax, %rax
setle %cl
cmpq 0x10(%rsp), %rax
setg %al
orb %cl, %al
cmpb $0x1, %al
jne 0x15de9
movq 0x10(%rsp), %rax
cmpq %rax, -0x30(%r15)
jg 0x15bd3
xorl %eax, %eax
callq 0x165f5
cmpl $0x7, (%rax)
jl 0x15e25
movl -0x80(%r15), %edi
callq 0x16e1e
pushq $0x7
popq %rdi
leaq 0xbf60(%rip), %rsi      # 0x21d34
leaq 0xc372(%rip), %rdx      # 0x2214d
movl $0x70f, %ecx            # imm = 0x70F
leaq 0xc38e(%rip), %r8       # 0x22175
jmp 0x15e1b
xorl %eax, %eax
callq 0x165f5
cmpl $0x3, (%rax)
jl 0x15e25
movl -0x80(%r15), %edi
callq 0x16e1e
pushq $0x3
popq %rdi
leaq 0xbf2c(%rip), %rsi      # 0x21d34
leaq 0xc33e(%rip), %rdx      # 0x2214d
movl $0x70d, %ecx            # imm = 0x70D
leaq 0xc33f(%rip), %r8       # 0x2215a
movq %rax, %r9
xorl %eax, %eax
callq 0x1662e
movq 0x10(%r15), %rdi
testq %rdi, %rdi
je 0x15e3a
movq 0x18(%r15), %rdx
pushq $0x2
popq %rsi
callq 0x15a90
movq %r12, %rdi
callq 0x15740
jmp 0x15bd3
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq