// File: /workspace/github_c_makefile_star2_O3/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 0x801f
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x7fc1
cmpl $0x3, %r13d
jae 0x7fee
movl %eax, %ebp
movl 0xf0(%rsp), %eax
movl 0xe8(%rsp), %r10d
movl 0xe0(%rsp), %r8d
movl 0xd8(%rsp), %r9d
movl %r13d, %ecx
leaq 0x3cf2(%rip), %rdx      # 0xbbe0
movl (%rdx,%rcx,4), %edx
movzbl %r15b, %ecx
movl %ebp, %edi
movq %r12, %rsi
pushq %rax
pushq %r10
callq 0x8059
addq $0x10, %rsp
cmpl $-0x1, %eax
je 0x7fc1
movl %ebp, %edi
callq 0x7bba
cmpl $-0x1, %eax
je 0x7fc1
movzwl 0xf8(%rsp), %r15d
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x2803
testw %r15w, %r15w
je 0x7f49
movzwl %r15w, %esi
leaq 0x18(%rsp), %rdi
callq 0x2c66
leaq 0x18(%rsp), %rdi
movl %ebp, %esi
callq 0x7de8
cmpl $0x2, %r13d
jne 0x7f64
cmpl $-0x1, %eax
je 0x7fc1
movl %ebp, %ebx
jmp 0x7fc1
cmpl $-0x1, %eax
je 0x7fc1
movq %r12, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x7a0c
cmpl $-0x1, %eax
je 0x7fc1
testl %r13d, %r13d
je 0x7fd5
movq 0xd0(%rsp), %rax
movq (%rax), %r14
testq %r14, %r14
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %r13
je 0x7f60
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
movl %ebp, %r8d
callq 0x84b1
cmpl $-0x1, %eax
je 0x7fc1
movq 0x88(%r14), %r14
testq %r14, %r14
jne 0x7f9a
jmp 0x7f60
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 0x81aa
jmp 0x7f5b
leaq 0x3a54(%rip), %rdi      # 0xba49
leaq 0x2af5(%rip), %rbx      # 0xaaf1
movl $0x7f, %esi
movl $0x2, %edx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x4ad6
movl $0x1, %edi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0