// File: /workspace/github_c_makefile_star2_O0/containers[P]conmon/src/ctr_stdio.c
// Function: read_stdio
static bool read_stdio(int fd, stdpipe_t pipe, gboolean *eof)
{
	/* We use two extra bytes. One at the start, which we don't read into, instead
	   we use that for marking the pipe when we write to the attached socket.
	   One at the end to guarantee a null-terminated buffer for journald logging*/

	char real_buf[STDIO_BUF_SIZE + 2];
	char *buf = real_buf + 1;
	ssize_t num_read = 0;

	if (eof)
		*eof = false;

	num_read = read(fd, buf, STDIO_BUF_SIZE);
	if (num_read == 0) {
		if (eof)
			*eof = true;
		return false;
	} else if (num_read < 0) {
		if (errno == EAGAIN || errno == EWOULDBLOCK) {
			// Non-blocking mode - no data available, return gracefully
			return true;
		}
		/* Ignore EIO if fd is a tty, since this can happen when the tty is closed
		   while we are reading from it. */
		if (errno == EIO && isatty(fd)) {
			if (eof)
				*eof = true;
			return false;
		}
		nwarnf("stdio_input read failed: %m");
		return false;
	} else {
		// Always null terminate the buffer, just in case.
		buf[num_read] = '\0';

		bool written = write_to_logs(pipe, buf, num_read);
		if (!written)
			return false;

		real_buf[0] = pipe;
		write_back_to_remote_consoles(real_buf, num_read + 1);
		return true;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2040, %rsp           # imm = 0x2040
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x2020(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2028(%rbp)
movq $0x0, -0x2030(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xd503
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movl -0x8(%rbp), %edi
movq -0x2028(%rbp), %rsi
movl $0x2000, %edx           # imm = 0x2000
callq 0x4230
movq %rax, -0x2030(%rbp)
cmpq $0x0, -0x2030(%rbp)
jne 0xd542
cmpq $0x0, -0x18(%rbp)
je 0xd539
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0xd65c
cmpq $0x0, -0x2030(%rbp)
jge 0xd5f7
callq 0x45c0
cmpl $0xb, (%rax)
je 0xd564
callq 0x45c0
cmpl $0xb, (%rax)
jne 0xd56d
movb $0x1, -0x1(%rbp)
jmp 0xd65c
callq 0x45c0
cmpl $0x5, (%rax)
jne 0xd59e
movl -0x8(%rbp), %edi
callq 0x41b0
cmpl $0x0, %eax
je 0xd59e
cmpq $0x0, -0x18(%rbp)
je 0xd595
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0xd65c
leaq 0x8eff(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0xd5f1
jmp 0xd5ac
movq 0x8a3d(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x51aa(%rip), %rsi      # 0x12767
movb $0x0, %al
callq 0x4830
leaq 0x1d97d(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xd5ed
leaq 0x1d969(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x51aa(%rip), %rsi      # 0x12790
movb $0x0, %al
callq 0x4120
jmp 0xd5ef
jmp 0xd5f1
movb $0x0, -0x1(%rbp)
jmp 0xd65c
movq -0x2028(%rbp), %rax
movq -0x2030(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0xc(%rbp), %edi
movq -0x2028(%rbp), %rsi
movq -0x2030(%rbp), %rdx
callq 0x7740
andb $0x1, %al
movb %al, -0x2031(%rbp)
testb $0x1, -0x2031(%rbp)
jne 0xd636
movb $0x0, -0x1(%rbp)
jmp 0xd65c
movl -0xc(%rbp), %eax
movb %al, -0x2020(%rbp)
leaq -0x2020(%rbp), %rdi
movq -0x2030(%rbp), %rax
addq $0x1, %rax
movl %eax, %esi
callq 0xb360
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2040, %rsp           # imm = 0x2040
popq %rbp
retq
nopw (%rax,%rax)