rem: len = min(min(mlen, resid), space);
add: len = min(min((uint64) mlen, resid), (uint64) space);
context: static int sosend(struct socket *so, struct mbuf *addr, struct uio *uio, struct mbuf *top,	   struct mbuf *control, int flags){	struct mbuf **mp;	struct mbuf *m;	int32 space;	int32 len;	uint64 resid;	int clen = 0;	int error, dontroute, mlen;	int atomic = sosendallatonce(so) || top;	if (uio)		resid = uio->uio_resid;	else		resid = top->m_pkthdr.len;	/* resid shouldn't be below 0 and also a flag of MSG_EOR on a 	 * SOCK_STREAM isn't allowed (doesn't even make sense!)	 */	if (resid < 0 || (so->so_type == SOCK_STREAM && (flags & MSG_EOR))) {		error = EINVAL;		goto release;	}	dontroute = (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&		    (so->so_proto->pr_flags & PR_ATOMIC);	if (control)		clen = control->m_len;#define snderr(err)	{ error = err; /* unlock */ goto release; } restart:	if ((error = sblock(&so->so_snd, SBLOCKWAIT(flags))))		goto out;		/* Main Loop! We should loop here until resid == 0 */	do { 		if ((so->so_state & SS_CANTSENDMORE))			snderr(EPIPE);		if (so->so_error)			snderr(so->so_error);		if ((so->so_state & SS_ISCONNECTED) == 0) {			if (so->so_proto->pr_flags & PR_CONNREQUIRED) {				/* we need to be connected and we're not... */				if ((so->so_state & SS_ISCONFIRMING) == 0 &&				    !(resid == 0 && clen != 0))					/* we're not even trying to connect and we					 * have data to send, so it's an error!					 * return ENOTCONN					 */					snderr(ENOTCONN);			} else if (addr == NULL)				/* UDP is a connectionless protocol, so it can work				 * without being connected as long as we tell it where we				 * want to send the data :)				 */				/* Doh! No address to send to (UDP) */				snderr(EDESTADDRREQ);		}		space = sbspace(&so->so_snd);		if (flags & MSG_OOB)			space += 1024;		if ((atomic && resid > so->so_snd.sb_hiwat) || clen > so->so_snd.sb_hiwat)			snderr(EMSGSIZE);		if (space < resid + clen && uio && 		    (atomic || space < so->so_snd.sb_lowat || space < clen)) {			if ((so->so_state & SS_NBIO)) { /* non blocking set */				printf("so->so_state & SS_NBIO (%d)\n", so->so_state & SS_NBIO);				snderr(EWOULDBLOCK);			}			/* free lock - we're waiting on send buffer space */			sbunlock(&so->so_snd);			error = sockbuf_wait(&so->so_snd);			if (error)				goto out;			goto restart;		}		mp = &top;		space -= clen;		do {			if (!uio) {				/* data is actually just packaged as top. */				resid = 0;				if (flags & MSG_EOR)					top->m_flags |= M_EOR;			} else do {				if (!top) {					MGETHDR(m, MT_DATA);					mlen = MHLEN;					m->m_pkthdr.len = 0;					m->m_pkthdr.rcvif = NULL;				} else {					MGET(m, MT_DATA);					mlen = MLEN;				}				if (resid >= MINCLSIZE && space >= MCLBYTES) {					MCLGET(m);					if ((m->m_flags & M_EXT) == 0)						/* didn't get a cluster */						goto nopages;					mlen = MCLBYTES;					if (atomic && !top) {						len = min(MCLBYTES - max_hdr, resid);						m->m_data += max_hdr;					} else						len = min(MCLBYTES, resid);					space -= len;				} else {nopages:					len = min(min(mlen, resid), space);					space -= len;					/* leave room for headers if required */					if (atomic && !top && len < mlen)						MH_ALIGN(m, len);				}				error = uiomove(mtod(m, caddr_t), (int)len, uio);				resid = uio->uio_resid;				m->m_len = len;				*mp = m;				top->m_pkthdr.len += len;				if (error)					goto release;				mp = &m->m_next;				if (resid <= 0) {					if (flags & MSG_EOR)						/* we're the last record */						top->m_flags |= M_EOR;					break;				}			} while (space > 0 && atomic);			if (dontroute)				so->so_options |= SO_DONTROUTE;			/* XXX - locking */			error = (*so->so_proto->pr_userreq)(so, (flags & MSG_OOB) ? PRU_SENDOOB: PRU_SEND,						        top, addr, control);			/* XXX - unlock */			if (dontroute)				so->so_options &= ~SO_DONTROUTE;			clen = 0;			top = NULL;			control = NULL;			mp = &top;			if (error)				goto release;		} while (resid && space > 0);	} while (resid);release:	sbunlock(&so->so_snd);out:	if (top)		m_freem(top);	if (control)		m_freem(control);	return (error);}