// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/mmulti.c
// Function: netsend
int netsend (int other, void *dabuf, int bufsiz) //0:buffer full... can't send
{
    #if defined(__linux) || defined(_WIN32)
	char msg_control[CMSG_SPACE(sizeof(struct in_pktinfo)) + CMSG_SPACE(sizeof(struct in6_pktinfo))];
	#else
	char msg_control[CMSG_SPACE(sizeof(struct in_addr)) + CMSG_SPACE(sizeof(struct in6_pktinfo))];
	#endif
	if (otherhost[other].ss_family == AF_UNSPEC) return(0);

	if (otherhost[other].ss_family != domain) {
#ifdef MMULTI_DEBUG_SENDRECV_WIRE
		debugprintf("mmulti debug send error: tried sending to a different protocol family\n");
#endif
		return 0;
	}

	if (IS_INVALID_SOCKET(mysock)) {
#ifdef MMULTI_DEBUG_SENDRECV_WIRE
		debugprintf("mmulti debug send error: invalid socket\n");
#endif
		return 0;
	}

#ifdef MMULTI_DEBUG_SENDRECV_WIRE
	{
		int i;
		const unsigned char *pakbuf = dabuf;
		debugprintf("mmulti debug send: "); for(i=0;i<bufsiz;i++) debugprintf("%02x ",pakbuf[i]); debugprintf("\n");
	}
#endif

#ifdef _WIN32
	WSABUF iovec;
	WSAMSG msg;
	WSACMSGHDR *cmsg;
	DWORD len = 0;

	iovec.buf = dabuf;
	iovec.len = bufsiz;
	msg.name = (LPSOCKADDR)&otherhost[other];
	if (otherhost[other].ss_family == AF_INET) {
		msg.namelen = sizeof(struct sockaddr_in);
	} else {
		msg.namelen = sizeof(struct sockaddr_in6);
	}
	msg.lpBuffers = &iovec;
	msg.dwBufferCount = 1;
	msg.Control.buf = msg_control;
	msg.Control.len = sizeof(msg_control);
	msg.dwFlags = 0;
#else
	struct iovec iovec;
	struct msghdr msg;
	struct cmsghdr *cmsg;
	int len;

	iovec.iov_base = dabuf;
	iovec.iov_len = bufsiz;
	msg.msg_name = &otherhost[other];
	if (otherhost[other].ss_family == AF_INET) {
		msg.msg_namelen = sizeof(struct sockaddr_in);
	} else {
		msg.msg_namelen = sizeof(struct sockaddr_in6);
	}
	msg.msg_iov = &iovec;
	msg.msg_iovlen = 1;
	msg.msg_control = msg_control;
	msg.msg_controllen = sizeof(msg_control);
	msg.msg_flags = 0;
#endif

	len = 0;
	memset(msg_control, 0, sizeof(msg_control));

	cmsg = CMSG_FIRSTHDR(&msg);
#if !defined(__APPLE__) && !defined(__HAIKU__)
	// OS X doesn't implement setting the UDP4 source. We'll
	// just have to cross our fingers.
	if (replyfrom4[other].s_addr != INADDR_ANY) {
		cmsg->cmsg_level = IPPROTO_IP;
#if defined(__linux) || defined(_WIN32)
		cmsg->cmsg_type = IP_PKTINFO;
		cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
		#ifdef _WIN32
		((struct in_pktinfo *)CMSG_DATA(cmsg))->ipi_addr = replyfrom4[other];
		#else
		((struct in_pktinfo *)CMSG_DATA(cmsg))->ipi_spec_dst = replyfrom4[other];
		#endif
		len += CMSG_SPACE(sizeof(struct in_pktinfo));
#else
		cmsg->cmsg_type = IP_SENDSRCADDR;
		cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
		*(struct in_addr *)CMSG_DATA(cmsg) = replyfrom4[other];
		len += CMSG_SPACE(sizeof(struct in_addr));
#endif
		cmsg = CMSG_NXTHDR(&msg, cmsg);
	}
#endif
	if (!IN6_IS_ADDR_UNSPECIFIED(&replyfrom6[other])) {
		cmsg->cmsg_level = IPPROTO_IPV6;
		cmsg->cmsg_type = IPV6_PKTINFO;
		cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
		((struct in6_pktinfo *)CMSG_DATA(cmsg))->ipi6_addr = replyfrom6[other];
		len += CMSG_SPACE(sizeof(struct in6_pktinfo));
		cmsg = CMSG_NXTHDR(&msg, cmsg);
	}
#ifdef _WIN32
	msg.Control.len = len;
	if (len == 0) {
		msg.Control.buf = NULL;
	}
#else
	msg.msg_controllen = len;
	if (len == 0) {
		msg.msg_control = NULL;
	}
#endif

#ifdef _WIN32
	if (WSASendMsgPtr(mysock, &msg, 0, &len, NULL, NULL) == SOCKET_ERROR)
#else
	if ((len = (int)sendmsg(mysock, &msg, 0)) < 0)
#endif
	{
#ifdef MMULTI_DEBUG_SENDRECV_WIRE
		debugprintf("mmulti debug send error: %s\n", strerror(errno));
#endif
		return 0;
	}

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x71d6f0(%rip), %rax    # 0x7a4570
shlq $0x7, %rcx
addq %rcx, %rax
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0x86e9b
movl $0x0, -0x4(%rbp)
jmp 0x8717a
movslq -0x8(%rbp), %rcx
leaq 0x71d6ca(%rip), %rax    # 0x7a4570
shlq $0x7, %rcx
addq %rcx, %rax
movzwl (%rax), %eax
cmpl 0x71d6aa(%rip), %eax    # 0x7a4560
je 0x86ec4
movl $0x0, -0x4(%rbp)
jmp 0x8717a
cmpl $0x0, 0xa5239(%rip)     # 0x12c104
jge 0x86ed9
movl $0x0, -0x4(%rbp)
jmp 0x8717a
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, -0x68(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x71d67c(%rip), %rax    # 0x7a4570
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x71d663(%rip), %rax    # 0x7a4570
shlq $0x7, %rcx
addq %rcx, %rax
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0x86f28
movl $0x10, -0xa0(%rbp)
jmp 0x86f32
movl $0x1c, -0xa0(%rbp)
leaq -0x70(%rbp), %rax
movq %rax, -0x98(%rbp)
movq $0x1, -0x90(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x88(%rbp)
movq $0x48, -0x80(%rbp)
movl $0x0, -0x78(%rbp)
movl $0x0, -0xb4(%rbp)
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0x8410
cmpq $0x10, -0x80(%rbp)
jb 0x86f93
movq -0x88(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x86f9e
xorl %eax, %eax
movq %rax, -0xd0(%rbp)
jmp 0x86f9e
movq -0xd0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x71ddb9(%rip), %rax    # 0x7a4d70
cmpl $0x0, (%rax,%rcx,4)
je 0x8702a
movq -0xb0(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0xb0(%rbp), %rax
movl $0x8, 0xc(%rax)
movq -0xb0(%rbp), %rax
movq $0x1c, (%rax)
movq -0xb0(%rbp), %rax
movslq -0x8(%rbp), %rdx
leaq 0x71dd77(%rip), %rcx    # 0x7a4d70
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x14(%rax)
movslq -0xb4(%rbp), %rax
addq $0x20, %rax
movl %eax, -0xb4(%rbp)
movq -0xb0(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x85b0
movq %rax, -0xb0(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x71dd7b(%rip), %rax    # 0x7a4db0
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, (%rcx)
movb %al, -0xd1(%rbp)
jne 0x87095
movq -0xc0(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x4(%rcx)
movb %al, -0xd1(%rbp)
jne 0x87095
movq -0xc0(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x8(%rcx)
movb %al, -0xd1(%rbp)
jne 0x87095
movq -0xc0(%rbp), %rax
cmpl $0x0, 0xc(%rax)
sete %al
movb %al, -0xd1(%rbp)
movb -0xd1(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xc4(%rbp)
cmpl $0x0, -0xc4(%rbp)
jne 0x8712c
movq -0xb0(%rbp), %rax
movl $0x29, 0x8(%rax)
movq -0xb0(%rbp), %rax
movl $0x32, 0xc(%rax)
movq -0xb0(%rbp), %rax
movq $0x24, (%rax)
movq -0xb0(%rbp), %rax
movslq -0x8(%rbp), %rdx
leaq 0x71dcc5(%rip), %rcx    # 0x7a4db0
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x18(%rax)
movslq -0xb4(%rbp), %rax
addq $0x28, %rax
movl %eax, -0xb4(%rbp)
movq -0xb0(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x85b0
movq %rax, -0xb0(%rbp)
movslq -0xb4(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpl $0x0, -0xb4(%rbp)
jne 0x8714b
movq $0x0, -0x88(%rbp)
movl 0xa4fb3(%rip), %edi     # 0x12c104
leaq -0xa8(%rbp), %rsi
xorl %edx, %edx
callq 0x8830
movl %eax, -0xb4(%rbp)
cmpl $0x0, %eax
jge 0x87173
movl $0x0, -0x4(%rbp)
jmp 0x8717a
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)