// File: /workspace/github_c_makefile_star2_O3/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 0xaa27
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 0xaad0
testq %r15, %r15
je 0xaad0
movq %rax, %r12
testq %rax, %rax
je 0xaad0
movq %r15, %rdi
callq 0x4080
testq %rax, %rax
je 0xaad5
movq %rax, %rdi
movl $0x280040, %esi         # imm = 0x280040
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x48c0
testl %eax, %eax
js 0xaadd
movl %eax, %ebp
movq %r12, %rdi
callq 0x43b0
testq %rax, %rax
je 0xaae2
movq %r12, %rdi
callq 0x48e8
movq %r15, %rdi
callq 0x48e8
xorl %r15d, %r15d
jmp 0xaa7c
callq 0x4040
movq %rax, %r15
leaq 0x4a51(%rip), %rsi      # 0xf487
movq %rax, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4680
movq %rax, %r14
movq %rax, %rdi
callq 0x47a0
testl %eax, %eax
js 0xaaea
movl %eax, %edi
callq 0x4100
movq %r14, %rdi
callq 0x4290
testl %eax, %eax
js 0xaaef
movq %r15, %rdi
callq 0x48e8
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %r14, %r15
movl $0x1, %edi
movl $0x80001, %esi          # imm = 0x80001
xorl %edx, %edx
callq 0x4570
movl %eax, (%rbx)
testl %eax, %eax
js 0xaac6
movl %ebp, %edi
movl %eax, %esi
movq %r15, %rdx
callq 0xb1eb
movl (%rbx), %edi
movl $0x80, %esi
callq 0x43c0
testl %eax, %eax
js 0xaacb
testl %ebp, %ebp
js 0xaaba
movl %ebp, %edi
callq 0x4100
movq %r14, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x69f9
callq 0x69a3
callq 0x694d
movq %r14, %rdi
callq 0x68fc
callq 0x68a6
movq %r14, %rdi
callq 0x6855
callq 0x6aa5
callq 0x6a4f