// File: /workspace/github_c_makefile_star2_O1/jfriesse[P]omping/sockfunc.c
// Function: sf_create_unicast_socket
int
sf_create_unicast_socket(const struct sockaddr *local_addr, uint8_t ttl, int mcast_send,
    int allow_mcast_loop, const char *local_ifname, enum sf_transport_method transport_method,
    int receive_timestamp, int force_recvttl, int sndbuf_size, int rcvbuf_size,
    uint16_t *bind_port)
{
	struct sockaddr_storage bind_addr;
	socklen_t bind_addr_len;
	int sock;

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

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

	if (mcast_send) {
		switch (transport_method) {
		case SF_TM_ASM:
		case SF_TM_SSM:
			if (sfset_ttl(local_addr, SF_CT_MULTI, sock, ttl) == -1) {
				return (-1);
			}

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

			if (sfset_mcast_if(local_addr, sock, local_ifname) == -1) {
				return (-1);
			}
			break;
		case SF_TM_IPBC:
			if (sfset_broadcast(sock, 1) == -1) {
				return (-1);
			}
			break;
		}
	}

	af_copy_sa_to_sas(&bind_addr, local_addr);

	if (bind_port != NULL) {
		af_sa_set_port(AF_CAST_SA(&bind_addr), *bind_port);
	}

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

	if (bind_port != NULL && *bind_port == 0) {
		bind_addr_len = sizeof(bind_addr);

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

		*bind_port = af_sa_port(AF_CAST_SA(&bind_addr));
	}

	return (sock);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %r9d, %r13d
movq %r8, 0x8(%rsp)
movl %ecx, 0x4(%rsp)
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %r14
callq 0x8146
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x85c7
movl %eax, %ebx
movl 0xe8(%rsp), %eax
movl 0xe0(%rsp), %r10d
movl 0xd8(%rsp), %r8d
movl 0xd0(%rsp), %r9d
movzbl %r12b, %r12d
movl %ebx, %edi
movq %r14, %rsi
xorl %edx, %edx
movl %r12d, %ecx
pushq %rax
pushq %r10
callq 0x8181
addq $0x10, %rsp
cmpl $-0x1, %eax
je 0x85c7
testl %r15d, %r15d
je 0x8544
cmpl $0x2, %r13d
jae 0x852d
movq %r14, %rdi
movl $0x1, %esi
movl %ebx, %edx
movl %r12d, %ecx
callq 0x7dba
cmpl $-0x1, %eax
je 0x85c7
movq %r14, %rdi
movl %ebx, %esi
movl 0x4(%rsp), %edx
callq 0x7b2c
cmpl $-0x1, %eax
je 0x85c7
movq %r14, %rdi
movl %ebx, %esi
movq 0x8(%rsp), %rdx
callq 0x7a23
jmp 0x853b
jne 0x8544
movl %ebx, %edi
movl $0x1, %esi
callq 0x7971
cmpl $-0x1, %eax
je 0x85c7
movq 0xf0(%rsp), %r15
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x2808
testq %r15, %r15
je 0x856c
movzwl (%r15), %esi
leaq 0x18(%rsp), %rdi
callq 0x2c62
testq %r15, %r15
sete %r14b
leaq 0x18(%rsp), %rdi
movl %ebx, %esi
callq 0x7f08
cmpl $-0x1, %eax
sete %cl
movl %ebx, %ebp
cmovel %eax, %ebp
orb %r14b, %cl
jne 0x85c7
cmpw $0x0, (%r15)
jne 0x85c5
leaq 0x14(%rsp), %rdx
movl $0x80, (%rdx)
leaq 0x18(%rsp), %rsi
movl %ebx, %edi
callq 0x22d0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x85c7
leaq 0x18(%rsp), %rdi
callq 0x2c20
movw %ax, (%r15)
movl %ebx, %ebp
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq