// File: /workspace/github_c_makefile_star2_O0/containers[P]conmon/src/ctrl.c
// Function: terminal_accept_cb
gboolean terminal_accept_cb(int fd, G_GNUC_UNUSED GIOCondition condition, G_GNUC_UNUSED gpointer user_data)
{

	ndebugf("about to accept from console_socket_fd: %d", fd);

	int connfd;
	do {
		connfd = accept4(fd, NULL, NULL, SOCK_CLOEXEC);
	} while (connfd < 0 && errno == EINTR);
	if (connfd < 0) {
		pexit("Failed to accept console-socket connection");
	}

	/* Not accepting anything else. */
	const char *csname = user_data;
	if (unlink(csname) < 0)
		nwarnf("failed to unlink %s", csname);

	close(fd);

	/* We exit if this fails. */
	ndebugf("about to recvfd from connfd: %d", connfd);
	struct file_t console = recvfd(connfd);

	if (console.fd < 0) {
		pexit("Failed to receive console file descriptor");
	}

	ndebugf("console = {.name = '%s'; .fd = %d}", console.name, console.fd);
	free(console.name);

	/* We change the terminal settings to match kube settings */
	struct termios tset;
	if (tcgetattr(console.fd, &tset) == -1) {
		nwarn("Failed to get console terminal settings");
		goto exit;
	}

	tset.c_oflag |= ONLCR;

	if (tcsetattr(console.fd, TCSANOW, &tset) == -1)
		nwarn("Failed to set console terminal settings");

exit:
	/* We only have a single fd for both pipes, so we just treat it as
	 * stdout. stderr is ignored. */
	mainfd_stdin = console.fd;
	mainfd_stdout = dup(console.fd);
	if (mainfd_stdout < 0)
		pexit("Failed to dup console file descriptor");

	/* Now that we have a fd to the tty, make sure we handle any pending data
	 * that was already buffered. */
	schedule_main_stdin_write();

	/* now that we've set mainfd_stdout, we can register the ctrl_winsz_cb
	 * if we didn't set it here, we'd risk attempting to run ioctl on
	 * a negative fd, and fail to resize the window */
	g_unix_fd_add(winsz_fd_r, G_IO_IN, ctrl_winsz_cb, NULL);

	/* Clean up everything */
	close(connfd);

	/* Since we've gotten our console from the runtime, we no longer need to
	   be listening on this callback. */
	return G_SOURCE_REMOVE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
leaq 0xa088(%rip), %rax      # 0x164a4
cmpl $0x3, (%rax)
jb 0xc46e
jmp 0xc423
movq 0x9bc6(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movl -0x4(%rbp), %edx
leaq 0x5b71(%rip), %rsi      # 0x11fa8
movb $0x0, %al
callq 0x4830
leaq 0x1eb03(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc46a
leaq 0x1eaef(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl -0x4(%rbp), %ecx
movl $0x6, %edi
leaq 0x5b7d(%rip), %rsi      # 0x11fe0
movb $0x0, %al
callq 0x4120
jmp 0xc46c
jmp 0xc46e
jmp 0xc470
movl -0x4(%rbp), %edi
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0x80000, %ecx          # imm = 0x80000
callq 0x45e0
movl %eax, -0x14(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x75(%rbp)
jge 0xc4a9
callq 0x45c0
cmpl $0x4, (%rax)
sete %al
movb %al, -0x75(%rbp)
movb -0x75(%rbp), %al
testb $0x1, %al
jne 0xc470
cmpl $0x0, -0x14(%rbp)
jge 0xc511
jmp 0xc4b8
movq 0x9b31(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2b4a(%rip), %rsi      # 0xf013
leaq 0x5b54(%rip), %rdx      # 0x12024
movb $0x0, %al
callq 0x4830
leaq 0x1ea6a(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc507
leaq 0x1ea56(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x3, %edi
leaq 0x2b44(%rip), %rsi      # 0xf03d
leaq 0x5b24(%rip), %rcx      # 0x12024
movb $0x0, %al
callq 0x4120
movl $0x1, %edi
callq 0x41e0
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x4290
cmpl $0x0, %eax
jge 0xc584
leaq 0x9f76(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0xc582
jmp 0xc535
movq 0x9ab4(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x5b05(%rip), %rsi      # 0x1204f
movb $0x0, %al
callq 0x4830
leaq 0x1e9f0(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc57e
leaq 0x1e9dc(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x6, %edi
leaq 0x5af9(%rip), %rsi      # 0x12070
movb $0x0, %al
callq 0x4120
jmp 0xc580
jmp 0xc582
jmp 0xc584
movl -0x4(%rbp), %edi
callq 0x4100
leaq 0x9f11(%rip), %rax      # 0x164a4
cmpl $0x3, (%rax)
jb 0xc5e5
jmp 0xc59a
movq 0x9a4f(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x5aee(%rip), %rsi      # 0x1209c
movb $0x0, %al
callq 0x4830
leaq 0x1e98c(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc5e1
leaq 0x1e978(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl -0x14(%rbp), %ecx
movl $0x6, %edi
leaq 0x5aef(%rip), %rsi      # 0x120c9
movb $0x0, %al
callq 0x4120
jmp 0xc5e3
jmp 0xc5e5
movl -0x14(%rbp), %edi
callq 0x6d90
movq %rax, -0x38(%rbp)
movl %edx, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jge 0xc655
jmp 0xc5fc
movq 0x99ed(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2a06(%rip), %rsi      # 0xf013
leaq 0x5aee(%rip), %rdx      # 0x12102
movb $0x0, %al
callq 0x4830
leaq 0x1e926(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc64b
leaq 0x1e912(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x3, %edi
leaq 0x2a00(%rip), %rsi      # 0xf03d
leaq 0x5abe(%rip), %rcx      # 0x12102
movb $0x0, %al
callq 0x4120
movl $0x1, %edi
callq 0x41e0
leaq 0x9e48(%rip), %rax      # 0x164a4
cmpl $0x3, (%rax)
jb 0xc6b7
jmp 0xc663
movq 0x9986(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
movl -0x30(%rbp), %ecx
leaq 0x5ab1(%rip), %rsi      # 0x1212c
movb $0x0, %al
callq 0x4830
leaq 0x1e8bf(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc6b3
leaq 0x1e8ab(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movq -0x38(%rbp), %rcx
movl -0x30(%rbp), %r8d
movl $0x6, %edi
leaq 0x5ab0(%rip), %rsi      # 0x1215c
movb $0x0, %al
callq 0x4120
jmp 0xc6b5
jmp 0xc6b7
movq -0x38(%rbp), %rdi
callq 0x48f8
movl -0x30(%rbp), %edi
leaq -0x74(%rbp), %rsi
callq 0x4530
cmpl $-0x1, %eax
jne 0xc737
leaq 0x9dcc(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0xc732
jmp 0xc6df
movq 0x990a(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2aa7(%rip), %rsi      # 0xf197
leaq 0x5aa1(%rip), %rdx      # 0x12198
movb $0x0, %al
callq 0x4830
leaq 0x1e843(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc72e
leaq 0x1e82f(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x2ab2(%rip), %rsi      # 0xf1d2
leaq 0x5a71(%rip), %rcx      # 0x12198
movb $0x0, %al
callq 0x4120
jmp 0xc730
jmp 0xc732
jmp 0xc7b8
movl -0x70(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x70(%rbp)
movl -0x30(%rbp), %edi
xorl %esi, %esi
leaq -0x74(%rbp), %rdx
callq 0x4060
cmpl $-0x1, %eax
jne 0xc7b6
leaq 0x9d4a(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0xc7b4
jmp 0xc761
movq 0x9888(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2a25(%rip), %rsi      # 0xf197
leaq 0x5a47(%rip), %rdx      # 0x121c0
movb $0x0, %al
callq 0x4830
leaq 0x1e7c1(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc7b0
leaq 0x1e7ad(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x2a30(%rip), %rsi      # 0xf1d2
leaq 0x5a17(%rip), %rcx      # 0x121c0
movb $0x0, %al
callq 0x4120
jmp 0xc7b2
jmp 0xc7b4
jmp 0xc7b6
jmp 0xc7b8
movl -0x30(%rbp), %ecx
leaq 0xa586(%rip), %rax      # 0x16d48
movl %ecx, (%rax)
movl -0x30(%rbp), %edi
callq 0x4270
movl %eax, %ecx
leaq 0xa577(%rip), %rax      # 0x16d4c
movl %ecx, (%rax)
leaq 0xa56e(%rip), %rax      # 0x16d4c
cmpl $0x0, (%rax)
jge 0xc83e
jmp 0xc7e5
movq 0x9804(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x281d(%rip), %rsi      # 0xf013
leaq 0x59eb(%rip), %rdx      # 0x121e8
movb $0x0, %al
callq 0x4830
leaq 0x1e73d(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc834
leaq 0x1e729(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x3, %edi
leaq 0x2817(%rip), %rsi      # 0xf03d
leaq 0x59bb(%rip), %rcx      # 0x121e8
movb $0x0, %al
callq 0x4120
movl $0x1, %edi
callq 0x41e0
movb $0x0, %al
callq 0xb300
leaq 0xa520(%rip), %rax      # 0x16d6c
movl (%rax), %edi
movl $0x1, %esi
leaq 0x26(%rip), %rdx        # 0xc880
xorl %eax, %eax
movl %eax, %ecx
callq 0x4440
movl -0x14(%rbp), %edi
callq 0x4100
xorl %eax, %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)