// File: /workspace/github_c_makefile_star2_O2/containers[P]conmon/src/ctr_stdio.c
// Function: stdio_cb
gboolean stdio_cb(int fd, GIOCondition condition, gpointer user_data)
{
	stdpipe_t pipe = GPOINTER_TO_INT(user_data);
	gboolean read_eof = FALSE;
	gboolean has_input = (condition & G_IO_IN) != 0;
	gboolean has_hup = (condition & G_IO_HUP) != 0;

	/* When we get here, condition can be G_IO_IN and/or G_IO_HUP.
	   IN means there is some data to read.
	   HUP means the other side closed the fd. In the case of a pine
	   this in final, and we will never get more data. However, in the
	   terminal case this just means that nobody has the terminal
	   open at this point, and this can be change whenever someone
	   opens the tty */

	/* Read any data before handling hup */
	if (has_input) {
		read_stdio(fd, pipe, &read_eof);
	}

	if (has_hup && opt_terminal && pipe == STDOUT_PIPE) {
		/* We got a HUP from the terminal main this means there
		   are no open workers ptys atm, and we will get a lot
		   of wakeups until we have one, switch to polling
		   mode. */

		/* If we read some data this cycle, wait one more, maybe there
		   is more in the buffer before we handle the hup */
		if (has_input && !read_eof) {
			return G_SOURCE_CONTINUE;
		}

		if (!tty_hup_timeout_scheduled) {
			g_timeout_add(100, tty_hup_timeout_cb, NULL);
		}
		tty_hup_timeout_scheduled = true;
		return G_SOURCE_REMOVE;
	}

	/* End of input */
	if (read_eof || (has_hup && !has_input)) {
		/* There exists a case that the process has already exited
		 * and we know about it (because we checked our child processes)
		 * but we needed to run the main_loop to catch all the rest of the output
		 * (specifically, when we are exec, but not terminal)
		 * In this case, after both the stderr and stdout pipes have closed
		 * we should quit the loop. Otherwise, conmon will hang forever
		 * waiting for container_exit_cb that will never be called.
		 */
		if (pipe == STDOUT_PIPE) {
			mainfd_stdout = -1;
			if (container_status >= 0 && mainfd_stderr < 0) {
				g_main_loop_quit(main_loop);
			}
		}
		if (pipe == STDERR_PIPE) {
			mainfd_stderr = -1;
			if (container_status >= 0 && mainfd_stdout < 0) {
				g_main_loop_quit(main_loop);
			}
		}

		close(fd);
		return G_SOURCE_REMOVE;
	}

	return G_SOURCE_CONTINUE;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movl %esi, %ebp
movl %edi, %ebx
andl $0x0, 0xc(%rsp)
testb $0x1, %bpl
je 0xac8d
leaq 0xc(%rsp), %rdx
movl %ebx, %edi
movl %r14d, %esi
callq 0xad65
movl 0xc(%rsp), %eax
cmpl $0x2, %r14d
jne 0xace0
movl %ebp, %ecx
andl $0x10, %ecx
je 0xace0
leaq 0x1e23f(%rip), %rcx     # 0x28ee4
cmpl $0x0, (%rcx)
je 0xace0
testl %eax, %eax
setne %al
testb $0x1, %bpl
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xad17
cmpb $0x0, 0x1e484(%rip)     # 0x29148
jne 0xacd7
leaq 0x192(%rip), %rsi       # 0xae5f
pushq $0x64
popq %rdi
xorl %edx, %edx
callq 0x47f0
movb $0x1, 0x1e46a(%rip)     # 0x29148
jmp 0xad5a
testl %eax, %eax
sete %al
andl $0x11, %ebp
cmpl $0x10, %ebp
setne %cl
testb %al, %cl
jne 0xad17
cmpl $0x2, %r14d
jne 0xad1c
leaq 0xa04d(%rip), %rax      # 0x14d4c
orl $-0x1, (%rax)
leaq 0xa03b(%rip), %rax      # 0x14d44
cmpl $0x0, (%rax)
js 0xad53
leaq 0xa03b(%rip), %rax      # 0x14d50
jmp 0xad3f
pushq $0x1
popq %rax
jmp 0xad5c
cmpl $0x3, %r14d
jne 0xad53
leaq 0xa027(%rip), %rax      # 0x14d50
orl $-0x1, (%rax)
leaq 0xa011(%rip), %rax      # 0x14d44
cmpl $0x0, (%rax)
js 0xad53
leaq 0xa00d(%rip), %rax      # 0x14d4c
cmpl $0x0, (%rax)
jns 0xad53
leaq 0x1e2a5(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
callq 0x4160
movl %ebx, %edi
callq 0x4100
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq