// File: /workspace/github_c_makefile_star2_O2/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
subq $0x10, %rsp
movq %rdi, %r14
orl $-0x1, 0xc(%rsp)
testq %rsi, %rsi
je 0x8d14
movq %rsi, %r12
movq %rsi, %rdi
callq 0x45f0
movq %rax, %rbx
movq %r12, %rdi
callq 0x45f0
movq %rax, %r15
movq %r12, %rdi
callq 0x45f0
testq %rbx, %rbx
je 0x8e4c
testq %r15, %r15
je 0x8e4c
movq %rax, %r12
testq %rax, %rax
je 0x8e4c
movq %r15, %rdi
callq 0x4080
testq %rax, %rax
je 0x8e98
movq %rax, %rdi
movl $0x280040, %esi         # imm = 0x280040
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x48d0
movl %eax, 0xc(%rsp)
testl %eax, %eax
js 0x8ed9
movl %eax, %ebp
movq %r12, %rdi
callq 0x43b0
testq %rax, %rax
je 0x8f25
movq %r12, %rdi
callq 0x48f8
movq %r15, %rdi
callq 0x48f8
xorl %r15d, %r15d
jmp 0x8d67
callq 0x4040
movq %rax, %r15
leaq 0x6764(%rip), %rsi      # 0xf487
movq %rax, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4690
movq %rax, %rbx
movq %rax, %rdi
callq 0x47b0
testl %eax, %eax
js 0x8f6c
movl %eax, %edi
callq 0x4100
movq %rbx, %rdi
callq 0x4290
testl %eax, %eax
js 0x8fb1
movq %r15, %rdi
callq 0x48f8
pushq $-0x1
popq %rbp
movq %rbx, %r15
pushq $0x1
popq %rdi
movl $0x80001, %esi          # imm = 0x80001
xorl %edx, %edx
callq 0x4580
movl %eax, (%r14)
testl %eax, %eax
js 0x8db4
movl %ebp, %edi
movl %eax, %esi
movq %r15, %rdx
callq 0x9a4e
movl (%r14), %edi
movl $0x80, %esi
callq 0x43c0
testl %eax, %eax
js 0x8e00
leaq 0xc(%rsp), %rdi
callq 0x9a3a
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0xb235(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x424e(%rip), %rsi      # 0xd013
leaq 0x6727(%rip), %rdx      # 0xf4f3
xorl %eax, %eax
callq 0x4830
leaq 0x200fe(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x8ffe
leaq 0x200e6(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x4249(%rip), %rsi      # 0xd03d
leaq 0x66f8(%rip), %rcx      # 0xf4f3
jmp 0x8ff4
movq 0xb1e9(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x4202(%rip), %rsi      # 0xd013
leaq 0x66f3(%rip), %rdx      # 0xf50b
xorl %eax, %eax
callq 0x4830
leaq 0x200b2(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x8ffe
leaq 0x2009a(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x41fd(%rip), %rsi      # 0xd03d
leaq 0x66c4(%rip), %rcx      # 0xf50b
jmp 0x8ff4
movq 0xb19d(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x41b6(%rip), %rsi      # 0xd013
leaq 0x6520(%rip), %rdx      # 0xf384
xorl %eax, %eax
callq 0x4830
leaq 0x20066(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x8ffe
leaq 0x2004e(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x41b1(%rip), %rsi      # 0xd03d
leaq 0x64f1(%rip), %rcx      # 0xf384
jmp 0x8ff4
movq 0xb151(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x64f5(%rip), %rsi      # 0xf39e
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4830
leaq 0x2001e(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x8ffe
leaq 0x20006(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x64f4(%rip), %rsi      # 0xf3c8
jmp 0x8f61
movq 0xb110(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x4129(%rip), %rsi      # 0xd013
leaq 0x650c(%rip), %rdx      # 0xf3fd
xorl %eax, %eax
callq 0x4830
leaq 0x1ffd9(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x8ffe
leaq 0x1ffc1(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x4124(%rip), %rsi      # 0xd03d
leaq 0x64dd(%rip), %rcx      # 0xf3fd
jmp 0x8ff4
movq 0xb0c4(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x64f0(%rip), %rsi      # 0xf426
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4830
leaq 0x1ff91(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x8ffe
leaq 0x1ff79(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x64f0(%rip), %rsi      # 0xf451
pushq $0x3
popq %rdi
movq %rbx, %rcx
jmp 0x8ff7
movq 0xb07d(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x4096(%rip), %rsi      # 0xd013
leaq 0x6516(%rip), %rdx      # 0xf49a
xorl %eax, %eax
callq 0x4830
leaq 0x1ff46(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x8ffe
leaq 0x1ff32(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x4095(%rip), %rsi      # 0xd03d
leaq 0x64eb(%rip), %rcx      # 0xf49a
jmp 0x8ff4
movq 0xb038(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x4051(%rip), %rsi      # 0xd013
leaq 0x6503(%rip), %rdx      # 0xf4cc
xorl %eax, %eax
callq 0x4830
leaq 0x1ff01(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x8ffe
leaq 0x1feed(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x4050(%rip), %rsi      # 0xd03d
leaq 0x64d8(%rip), %rcx      # 0xf4cc
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x4120
pushq $0x1
popq %rdi
callq 0x41e0