// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movl -0x1c(%rbp), %eax
movl %eax, -0x3c(%rbp)
callq 0xb9c0
movl -0x3c(%rbp), %edi
movq %rax, %rsi
callq 0xb840
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x280000, %esi         # imm = 0x280000
movb $0x0, %al
callq 0x48d0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0xadb9
jmp 0xad66
movq 0xb283(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x6be6(%rip), %rsi      # 0x11961
movb $0x0, %al
callq 0x4830
leaq 0x201bf(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xadaf
leaq 0x201ab(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x3, %edi
leaq 0x6bf2(%rip), %rsi      # 0x1199a
movb $0x0, %al
callq 0x4120
movl $0x1, %edi
callq 0x41e0
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x46a0
movq %rax, -0x38(%rbp)
movl -0xc(%rbp), %esi
movl $0x1, %edi
xorl %edx, %edx
callq 0x4580
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0xae3d
jmp 0xadea
movq 0xb1ff(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
leaq 0x6bdf(%rip), %rsi      # 0x119de
movb $0x0, %al
callq 0x4830
leaq 0x2013b(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xae33
leaq 0x20127(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movq -0x38(%rbp), %rcx
movl $0x3, %edi
leaq 0x6bdd(%rip), %rsi      # 0x11a09
movb $0x0, %al
callq 0x4120
movl $0x1, %edi
callq 0x41e0
movq -0x38(%rbp), %rdi
callq 0x4290
cmpl $-0x1, %eax
jne 0xaeaa
callq 0x45c0
cmpl $0x2, (%rax)
je 0xaeaa
jmp 0xae57
movq 0xb192(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
leaq 0x6bd3(%rip), %rsi      # 0x11a3f
movb $0x0, %al
callq 0x4830
leaq 0x200ce(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xaea0
leaq 0x200ba(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movq -0x38(%rbp), %rcx
movl $0x3, %edi
leaq 0x6bdb(%rip), %rsi      # 0x11a74
movb $0x0, %al
callq 0x4120
movl $0x1, %edi
callq 0x41e0
movl -0x2c(%rbp), %edi
movl -0x20(%rbp), %esi
movq -0x8(%rbp), %rdx
callq 0xb680
movq -0x38(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x4030
cmpl $0x0, %eax
je 0xaf1f
jmp 0xaecc
movq 0xb11d(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
leaq 0x6bd3(%rip), %rsi      # 0x11ab4
movb $0x0, %al
callq 0x4830
leaq 0x20059(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xaf15
leaq 0x20045(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movq -0x38(%rbp), %rcx
movl $0x3, %edi
leaq 0x6bdd(%rip), %rsi      # 0x11aeb
movb $0x0, %al
callq 0x4120
movl $0x1, %edi
callq 0x41e0
movl -0x20(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x2c(%rbp), %rdi
callq 0xb630
leaq -0x28(%rbp), %rdi
callq 0xb660
movq -0x48(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)