// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movb %cl, %al
movw 0x38(%rbp), %cx
movl 0x30(%rbp), %ecx
movl 0x28(%rbp), %ecx
movl 0x20(%rbp), %ecx
movl 0x18(%rbp), %ecx
movq 0x10(%rbp), %rcx
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movb %al, -0x21(%rbp)
movl %r8d, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb250
movl %eax, -0xb4(%rbp)
cmpl $-0x1, -0xb4(%rbp)
jne 0xb03c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb244
movl -0x2c(%rbp), %eax
movl %eax, -0xbc(%rbp)
subl $0x2, %eax
jb 0xb059
jmp 0xb04c
movl -0xbc(%rbp), %eax
subl $0x2, %eax
je 0xb065
jmp 0xb071
movl $0x1, -0xb8(%rbp)
jmp 0xb0a3
movl $0x2, -0xb8(%rbp)
jmp 0xb0a3
leaq 0x4a42(%rip), %rdi      # 0xfaba
movl $0x7f, %esi
movl $0x2, %edx
leaq 0x3aaf(%rip), %rcx      # 0xeb38
movb $0x0, %al
callq 0x5dc0
movl $0x1, %edi
leaq 0x3a9c(%rip), %rsi      # 0xeb38
movb $0x0, %al
callq 0x20d0
movl -0xb4(%rbp), %edi
movq -0x10(%rbp), %rsi
movl -0xb8(%rbp), %edx
movb -0x21(%rbp), %cl
movl 0x20(%rbp), %r8d
movl 0x18(%rbp), %r9d
movl 0x28(%rbp), %r10d
movl 0x30(%rbp), %eax
movzbl %cl, %ecx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
callq 0xb2b0
cmpl $-0x1, %eax
jne 0xb0ee
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb244
movl -0xb4(%rbp), %edi
callq 0xabc0
cmpl $-0x1, %eax
jne 0xb10a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb244
movq -0x10(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x2bd0
movzwl 0x38(%rbp), %eax
cmpl $0x0, %eax
je 0xb133
leaq -0xb0(%rbp), %rdi
movzwl 0x38(%rbp), %esi
callq 0x3220
movl -0x2c(%rbp), %eax
movl %eax, -0xc0(%rbp)
subl $0x2, %eax
jb 0xb150
jmp 0xb143
movl -0xc0(%rbp), %eax
subl $0x2, %eax
je 0xb198
jmp 0xb1bd
movl -0xb4(%rbp), %esi
leaq -0xb0(%rbp), %rdi
callq 0xaed0
cmpl $-0x1, %eax
jne 0xb173
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb244
movq -0x10(%rbp), %rdi
movl -0xb4(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0xa990
cmpl $-0x1, %eax
jne 0xb196
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb244
jmp 0xb1bd
movl -0xb4(%rbp), %esi
leaq -0xb0(%rbp), %rdi
callq 0xaed0
cmpl $-0x1, %eax
jne 0xb1bb
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb244
jmp 0xb1bd
movl -0x2c(%rbp), %eax
movl %eax, -0xc4(%rbp)
testl %eax, %eax
je 0xb1e6
jmp 0xb1cc
movl -0xc4(%rbp), %eax
subl $0x1, %eax
je 0xb20d
jmp 0xb1d9
movl -0xc4(%rbp), %eax
subl $0x2, %eax
je 0xb239
jmp 0xb23b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0xb4(%rbp), %ecx
callq 0xb430
cmpl $-0x1, %eax
jne 0xb20b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb244
jmp 0xb23b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl -0xb4(%rbp), %r8d
callq 0xb5d0
cmpl $-0x1, %eax
jne 0xb237
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb244
jmp 0xb23b
jmp 0xb23b
movl -0xb4(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq