// File: /workspace/github_c_makefile_star2_O2/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, %r14d
movl %ecx, %r15d
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
callq 0x7c8c
pushq $-0x1
popq %rbx
cmpl $-0x1, %eax
je 0x7c37
cmpl $0x3, %r13d
jae 0x7c61
movl %eax, %ebp
movl 0xf0(%rsp), %eax
movl 0xe8(%rsp), %r10d
movl 0xe0(%rsp), %r8d
movl 0xd8(%rsp), %r9d
movl %r13d, %ecx
leaq 0x3058(%rip), %rdx      # 0xabe0
movl (%rdx,%rcx,4), %edx
movzbl %r15b, %ecx
movl %ebp, %edi
movq %r12, %rsi
pushq %rax
pushq %r10
callq 0x7cc2
popq %rcx
popq %rdx
cmpl $-0x1, %eax
je 0x7c37
movl %ebp, %edi
callq 0x787d
cmpl $-0x1, %eax
je 0x7c37
movzwl 0xf8(%rsp), %r15d
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x27bc
testw %r15w, %r15w
je 0x7be1
movzwl %r15w, %esi
leaq 0x18(%rsp), %rdi
callq 0x2bec
leaq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x7a90
cmpl $0x2, %r13d
jne 0x7bfc
cmpl $-0x1, %eax
je 0x7c37
movl %ebp, %ebx
jmp 0x7c37
cmpl $-0x1, %eax
je 0x7c37
movq %r12, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x76f1
cmpl $-0x1, %eax
je 0x7c37
testl %r13d, %r13d
je 0x7c4b
movq 0xd0(%rsp), %rdx
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rcx
movl %ebp, %r8d
callq 0x7f08
jmp 0x7bf3
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
callq 0x7df6
jmp 0x7bf3
leaq 0x2de1(%rip), %rdi      # 0xaa49
leaq 0x1e82(%rip), %rbx      # 0x9af1
pushq $0x7f
popq %rsi
pushq $0x2
popq %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x4998
pushq $0x1
popq %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0