// File: /workspace/github_c_makefile_star2_O1/jfriesse[P]omping/sockfunc.c
// Function: sf_create_multicast_socket
int
sf_create_multicast_socket(const struct sockaddr *mcast_addr, const struct sockaddr *local_addr,
    const char *local_ifname, uint8_t ttl, int allow_mcast_loop,
    enum sf_transport_method transport_method, const struct aii_list *remote_addrs,
    int receive_timestamp, int force_recvttl, int sndbuf_size, int rcvbuf_size, uint16_t bind_port)
{
#ifdef __CYGWIN__
	struct sockaddr_storage any_sas;
#endif
	struct sockaddr_storage bind_addr;
	int sock;
	enum sf_cast_type cast_type;

	sock = sf_create_udp_socket(mcast_addr);
	if (sock == -1) {
		return (-1);
	}

	switch (transport_method) {
	case SF_TM_ASM:
	case SF_TM_SSM:
		cast_type = SF_CT_MULTI;
		break;
	case SF_TM_IPBC:
		cast_type = SF_CT_BROAD;
		break;
	default:
		DEBUG_PRINTF("Internal error - unknown transport method");
		errx(1, "Internal error - unknown transport method");
		/* NOTREACHED */
	}

	if (sf_set_socket_common_options(sock, mcast_addr, cast_type, ttl, force_recvttl,
	    receive_timestamp, sndbuf_size, rcvbuf_size, 1) == -1) {
		return (-1);
	}

	if (sfset_reuse(sock) == -1) {
		return (-1);
	}

	af_copy_sa_to_sas(&bind_addr, mcast_addr);
	if (bind_port != 0) {
		af_sa_set_port(AF_CAST_SA(&bind_addr), bind_port);
	}

	switch (transport_method) {
	case SF_TM_ASM:
	case SF_TM_SSM:
#ifdef __CYGWIN__
		af_sa_to_any_addr(AF_CAST_SA(&any_sas), AF_CAST_SA(&bind_addr));
		memcpy(&bind_addr, &any_sas, sizeof(*any_sas));
#endif

		if (sf_bind_socket(AF_CAST_SA(&bind_addr), sock) == -1) {
			return (-1);
		}

		if (sfset_mcast_loop(mcast_addr, sock, allow_mcast_loop) == -1) {
			return (-1);
		}

		break;
	case SF_TM_IPBC:
		if (sf_bind_socket(AF_CAST_SA(&bind_addr), sock) == -1) {
			return (-1);
		}
		break;
	}


	switch (transport_method) {
	case SF_TM_ASM:
		if (sf_mcast_join_asm_group(mcast_addr, local_addr, local_ifname, sock) == -1) {
			return (-1);
		}
		break;
	case SF_TM_SSM:
		if (sf_mcast_join_ssm_group_list(mcast_addr, local_addr, remote_addrs,
		    local_ifname, sock) == -1) {
			return (-1);
		}
		break;
	case SF_TM_IPBC:
		/*
		 * Broadcast packet doesn't need any special handling on receiver side
		 */
		break;
	}

	return (sock);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %r9d, %r13d
movl %r8d, 0xc(%rsp)
movl %ecx, %r15d
movq %rdx, %r14
movq %rsi, 0x10(%rsp)
movq %rdi, %r12
callq 0x8146
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x80cd
cmpl $0x3, %r13d
jae 0x8115
movl %eax, %ebp
movl 0xf0(%rsp), %eax
movl 0xe8(%rsp), %r10d
movl 0xe0(%rsp), %r8d
movl 0xd8(%rsp), %r9d
movl %r13d, %ecx
leaq 0x3c12(%rip), %rdx      # 0xbc20
movl (%rdx,%rcx,4), %edx
movzbl %r15b, %ecx
movl %ebp, %edi
movq %r12, %rsi
pushq %rax
pushq %r10
callq 0x8181
addq $0x10, %rsp
cmpl $-0x1, %eax
je 0x80cd
movl %ebp, %edi
callq 0x7cda
cmpl $-0x1, %eax
je 0x80cd
movzwl 0xf8(%rsp), %r15d
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x2808
testw %r15w, %r15w
je 0x8069
movzwl %r15w, %esi
leaq 0x18(%rsp), %rdi
callq 0x2c62
cmpl $0x2, %r13d
jae 0x8093
leaq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x7f08
cmpl $-0x1, %eax
je 0x80cd
movq %r14, %r15
movq %r12, %rdi
movl %ebp, %esi
movl 0xc(%rsp), %edx
callq 0x7b2c
jmp 0x80a4
jne 0x80cb
movq %r14, %r15
leaq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x7f08
cmpl $-0x1, %eax
je 0x80cd
cmpl $0x1, %r13d
je 0x80e1
testl %r13d, %r13d
jne 0x80cb
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
movl %ebp, %ecx
callq 0x82d2
cmpl $-0x1, %eax
je 0x80cd
movl %ebp, %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd0(%rsp), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x80cb
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
movl %ebp, %r8d
callq 0x85e7
cmpl $-0x1, %eax
je 0x80cd
movq 0x88(%r14), %r14
jmp 0x80ec
leaq 0x396e(%rip), %rdi      # 0xba8a
leaq 0x29ce(%rip), %rbx      # 0xaaf1
movl $0x7f, %esi
movl $0x2, %edx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x4ada
movl $0x1, %edi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0