// File: /workspace/github_c_makefile_star2_O1/containers[P]conmon/src/conn_sock.c
// Function: setup_socket
static char *setup_socket(int *fd, const char *path)
{
	char *csname = NULL;
	char *bname = NULL;
	_cleanup_close_ int sfd = -1;

	if (path != NULL) {
		_cleanup_free_ char *dname_buf = NULL;
		_cleanup_free_ char *bname_buf = NULL;
		char *dname = NULL, *bname = NULL;

		csname = strdup(path);
		dname_buf = strdup(path);
		bname_buf = strdup(path);
		if (csname == NULL || dname_buf == NULL || bname_buf == NULL) {
			pexit("Failed to allocate memory");
			return NULL;
		}
		dname = dirname(dname_buf);
		if (dname == NULL)
			pexitf("Cannot get dirname for %s", csname);

		sfd = open(dname, O_CREAT | O_PATH | O_CLOEXEC, 0600);
		if (sfd < 0)
			pexit("Failed to create file for console-socket");

		bname = basename(bname_buf);
		if (bname == NULL)
			pexitf("Cannot get basename for %s", csname);
	} else {
		_cleanup_free_ const char *tmpdir = g_get_tmp_dir();

		csname = g_build_filename(tmpdir, "conmon-term.XXXXXX", NULL);
		/*
		 * Generate a temporary name. Is this unsafe? Probably, but we can
		 * replace it with a rename(2) setup if necessary.
		 */
		int unusedfd = g_mkstemp(csname);
		if (unusedfd < 0)
			pexit("Failed to generate random path for console-socket");
		close(unusedfd);
		/* XXX: This should be handled with a rename(2). */
		if (unlink(csname) < 0)
			pexit("Failed to unlink temporary random path");

		bname = csname;
	}

	/* Bind to the console socket path. */
	*fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
	if (*fd < 0)
		pexit("Failed to create socket");
	bind_relative_to_dir(sfd, *fd, bname);
	if (listen(*fd, 128) < 0)
		pexit("Failed to listen on console-socket");

	return csname;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
testq %rsi, %rsi
je 0xac0b
movq %rsi, %r12
movq %rsi, %rdi
callq 0x45e0
movq %rax, %r14
movq %r12, %rdi
callq 0x45e0
movq %rax, %r15
movq %r12, %rdi
callq 0x45e0
testq %r14, %r14
je 0xacb4
testq %r15, %r15
je 0xacb4
movq %rax, %r12
testq %rax, %rax
je 0xacb4
movq %r15, %rdi
callq 0x4080
testq %rax, %rax
je 0xacb9
movq %rax, %rdi
movl $0x280040, %esi         # imm = 0x280040
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x48c0
testl %eax, %eax
js 0xacc1
movl %eax, %ebp
movq %r12, %rdi
callq 0x43b0
testq %rax, %rax
je 0xacc6
movq %r12, %rdi
callq 0x48e8
xorl %r12d, %r12d
jmp 0xac58
callq 0x4040
movq %rax, %r15
leaq 0x488d(%rip), %rsi      # 0xf4a7
movq %rax, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4680
movq %rax, %r14
movq %rax, %rdi
callq 0x47a0
testl %eax, %eax
js 0xacce
movl %eax, %edi
callq 0x4100
movq %r14, %rdi
callq 0x4290
testl %eax, %eax
js 0xacd3
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %r14, %r12
movq %r15, %rdi
callq 0x48e8
movl $0x1, %edi
movl $0x80001, %esi          # imm = 0x80001
xorl %edx, %edx
callq 0x4570
movl %eax, (%rbx)
testl %eax, %eax
js 0xacaa
movl %ebp, %edi
movl %eax, %esi
movq %r12, %rdx
callq 0xb408
movl (%rbx), %edi
movl $0x80, %esi
callq 0x43c0
testl %eax, %eax
js 0xacaf
testl %ebp, %ebp
js 0xac9e
movl %ebp, %edi
callq 0x4100
movq %r14, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x6a65
callq 0x6a0f
callq 0x69b9
movq %r14, %rdi
callq 0x6968
callq 0x6912
movq %r14, %rdi
callq 0x68c1
callq 0x6b11
callq 0x6abb