// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movq %rcx, %r12
movl %edx, %ebp
movl %esi, %r13d
movq %rdi, 0x10(%rsp)
testl %r8d, %r8d
je 0x9103
leaq 0x1fe2a(%rip), %rax     # 0x28f20
movq (%rax), %rdi
callq 0x45f0
movq %rax, %rbx
jmp 0x9177
leaq 0xb3b6(%rip), %rax      # 0x144c0
movq (%rax), %rdi
leaq 0x1fdf4(%rip), %rax     # 0x28f08
movq (%rax), %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4690
movq %rax, %rbx
movq %rax, %rdi
callq 0x4360
cmpq $0x6b, %rax
jne 0x9135
movb $0x0, 0x6a(%rbx)
movq %rbx, %rdi
callq 0x4290
cmpl $-0x1, %eax
jne 0x9150
callq 0x45c0
cmpl $0x2, (%rax)
jne 0x9386
leaq 0x1fdc9(%rip), %rax     # 0x28f20
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x4050
cmpl $-0x1, %eax
je 0x92f1
leaq 0x2889(%rip), %rdi      # 0xb9fb
callq 0xc0b0
movq %rbx, %rdi
movl $0x280000, %esi         # imm = 0x280000
xorl %eax, %eax
callq 0x48d0
movl %eax, 0xc(%rsp)
testl %eax, %eax
js 0x9228
movl %eax, %r14d
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4690
movq %rax, %r15
pushq $0x1
popq %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x4580
cmpl $-0x1, %eax
je 0x926f
movl %eax, %r13d
movq %r15, %rdi
callq 0x4290
cmpl $-0x1, %eax
jne 0x91dd
callq 0x45c0
cmpl $0x2, (%rax)
jne 0x9339
movl %r14d, %edi
movl %r13d, %esi
movq 0x10(%rsp), %rdx
callq 0x9a4e
movq %r15, %rdi
movl %ebp, %esi
callq 0x4030
testl %eax, %eax
jne 0x92b0
movl %r13d, 0x4(%r12)
leaq 0xc(%rsp), %rdi
callq 0x9a3a
movq %rbx, %rdi
callq 0x48f8
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xadc1(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x63c8(%rip), %rsi      # 0xf601
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4830
leaq 0x1fc8e(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x937e
leaq 0x1fc76(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x63d6(%rip), %rsi      # 0xf63a
pushq $0x3
popq %rdi
movq %rbx, %rcx
jmp 0x9377
movq 0xad7a(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x63fe(%rip), %rsi      # 0xf67e
movq %r15, %rdx
xorl %eax, %eax
callq 0x4830
leaq 0x1fc47(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x937e
leaq 0x1fc2f(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x63fe(%rip), %rsi      # 0xf6a9
jmp 0x9371
movq 0xad39(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x6493(%rip), %rsi      # 0xf754
movq %r15, %rdx
xorl %eax, %eax
callq 0x4830
leaq 0x1fc06(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x937e
leaq 0x1fbee(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x649f(%rip), %rsi      # 0xf78b
jmp 0x9371
movq 0xacf8(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x3d11(%rip), %rsi      # 0xd013
leaq 0x6563(%rip), %rdx      # 0xf86c
xorl %eax, %eax
callq 0x4830
leaq 0x1fbc1(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x937e
leaq 0x1fbad(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x3d10(%rip), %rsi      # 0xd03d
leaq 0x6538(%rip), %rcx      # 0xf86c
pushq $0x3
popq %rdi
jmp 0x9377
movq 0xacb0(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x6395(%rip), %rsi      # 0xf6df
movq %r15, %rdx
xorl %eax, %eax
callq 0x4830
leaq 0x1fb7d(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x937e
leaq 0x1fb69(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x63a3(%rip), %rsi      # 0xf714
pushq $0x3
popq %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x4120
pushq $0x1
popq %rdi
callq 0x41e0
movq 0xac63(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x6436(%rip), %rsi      # 0xf7cd
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4830
leaq 0x1fb30(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x937e
leaq 0x1fb1c(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x6459(%rip), %rsi      # 0xf817
jmp 0x9264