// File: /workspace/github_c_makefile_star2_O1/containers[P]conmon/src/conn_sock.c
// Function: bind_unix_socket
static char *bind_unix_socket(char *socket_relative_name, int sock_type, mode_t perms, struct remote_sock_s *remote_sock,
			      gboolean use_full_attach_path)
{
	int socket_fd = -1;

	/* get the parent_dir of the socket. We'll use this to get the location of the socket. */
	_cleanup_free_ char *parent_dir = socket_parent_dir(use_full_attach_path, max_socket_path_len());

	/*
	 * To be able to access the location of the attach socket, without first creating the attach socket
	 * but also be able to handle arbitrary length paths, we open the parent dir (base_path), and then use
	 * the corresponding entry in `/proc/self/fd` to act as the path to base_path, then we use the socket_relative_name
	 * to actually refer to the file where the socket will be created below.
	 */
	_cleanup_close_ int parent_dir_fd = open(parent_dir, O_PATH | O_CLOEXEC);
	if (parent_dir_fd < 0)
		pexitf("failed to open socket path parent dir %s", parent_dir);

	/*
	 * We use the fullpath for operations that aren't as limited in length as socket_addr.sun_path
	 * Cleanup of this variable is up to the caller
	 */
	char *sock_fullpath = g_build_filename(parent_dir, socket_relative_name, NULL);

	/*
	 * We make the socket non-blocking to avoid a race where client aborts connection
	 * before the server gets a chance to call accept. In that scenario, the server
	 * accept blocks till a new client connection comes in.
	 */
	socket_fd = socket(AF_UNIX, sock_type, 0);
	if (socket_fd == -1)
		pexitf("Failed to create socket %s", sock_fullpath);

	if (unlink(sock_fullpath) == -1 && errno != ENOENT)
		pexitf("Failed to remove existing socket: %s", sock_fullpath);

	bind_relative_to_dir(parent_dir_fd, socket_fd, socket_relative_name);

	if (chmod(sock_fullpath, perms))
		pexitf("Failed to change socket permissions %s", sock_fullpath);

	remote_sock->fd = socket_fd;

	return sock_fullpath;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbp
movl %edx, %r14d
movl %esi, %r12d
movq %rdi, (%rsp)
testl %r8d, %r8d
je 0xad83
leaq 0x1f19a(%rip), %rax     # 0x29f10
movq (%rax), %rdi
callq 0x45e0
movq %rax, %r15
jmp 0xadf8
leaq 0xa726(%rip), %rax      # 0x154b0
movq (%rax), %rdi
leaq 0x1f164(%rip), %rax     # 0x29ef8
movq (%rax), %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4680
movq %rax, %r15
movq %rax, %rdi
callq 0x4360
cmpq $0x6b, %rax
jne 0xadb6
movb $0x0, 0x6a(%r15)
movq %r15, %rdi
callq 0x4290
cmpl $-0x1, %eax
jne 0xadd1
callq 0x45b0
cmpl $0x2, (%rax)
jne 0xaebc
leaq 0x1f138(%rip), %rax     # 0x29f10
movq (%rax), %rdi
movq %r15, %rsi
callq 0x4050
cmpl $-0x1, %eax
je 0xaeaf
leaq 0x1a3c(%rip), %rdi      # 0xc82f
callq 0xce90
movq %r15, %rdi
movl $0x280000, %esi         # imm = 0x280000
xorl %eax, %eax
callq 0x48c0
testl %eax, %eax
js 0xae97
movl %eax, %r13d
movq %r15, %rdi
movq (%rsp), %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4680
movq %rax, %rbx
movl $0x1, %edi
movl %r12d, %esi
xorl %edx, %edx
callq 0x4570
cmpl $-0x1, %eax
je 0xae9f
movl %eax, %r12d
movq %rbx, %rdi
callq 0x4290
cmpl $-0x1, %eax
jne 0xae53
callq 0x45b0
cmpl $0x2, (%rax)
jne 0xaeb4
movl %r13d, %edi
movl %r12d, %esi
movq (%rsp), %rdx
callq 0xb408
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4030
testl %eax, %eax
jne 0xaea7
movl %r12d, 0x4(%rbp)
movl %r13d, %edi
callq 0x4100
movq %r15, %rdi
callq 0x48e8
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x6d0a
movq %rbx, %rdi
callq 0x6cb9
movq %rbx, %rdi
callq 0x6c68
callq 0x6d5b
movq %rbx, %rdi
callq 0x6c17
movq %r15, %rdi
callq 0x6bc6