// File: /workspace/github_c_makefile_star2_O3/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 0x801f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x8491
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 0x8059
addq $0x10, %rsp
cmpl $-0x1, %eax
je 0x8491
testl %r15d, %r15d
je 0x840e
cmpl $0x2, %r13d
jae 0x83f7
movq %r14, %rdi
movl $0x1, %esi
movl %ebx, %edx
movl %r12d, %ecx
callq 0x7c9a
cmpl $-0x1, %eax
je 0x8491
movq %r14, %rdi
movl %ebx, %esi
movl 0x4(%rsp), %edx
callq 0x7a0c
cmpl $-0x1, %eax
je 0x8491
movq %r14, %rdi
movl %ebx, %esi
movq 0x8(%rsp), %rdx
callq 0x7903
jmp 0x8405
jne 0x840e
movl %ebx, %edi
movl $0x1, %esi
callq 0x7851
cmpl $-0x1, %eax
je 0x8491
movq 0xf0(%rsp), %r15
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x2803
testq %r15, %r15
je 0x8436
movzwl (%r15), %esi
leaq 0x18(%rsp), %rdi
callq 0x2c66
testq %r15, %r15
sete %r14b
leaq 0x18(%rsp), %rdi
movl %ebx, %esi
callq 0x7de8
cmpl $-0x1, %eax
sete %cl
movl %ebx, %ebp
cmovel %eax, %ebp
orb %r14b, %cl
jne 0x8491
cmpw $0x0, (%r15)
jne 0x848f
leaq 0x14(%rsp), %rdx
movl $0x80, (%rdx)
leaq 0x18(%rsp), %rsi
movl %ebx, %edi
callq 0x22e0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x8491
leaq 0x18(%rsp), %rdi
callq 0x2c24
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