// File: /workspace/github_c_makefile_star2_O3/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
movl $0x0, 0xc(%rsp)
testb $0x1, %bpl
je 0xbb50
leaq 0xc(%rsp), %rdx
movl %ebx, %edi
movl %r14d, %esi
callq 0xbc3c
movl 0xc(%rsp), %eax
cmpl $0x2, %r14d
jne 0xbbb1
movl %ebp, %ecx
andl $0x10, %ecx
je 0xbbb1
leaq 0x1e36c(%rip), %rcx     # 0x29ed4
cmpl $0x0, (%rcx)
je 0xbbb1
testl %eax, %eax
setne %al
testb $0x1, %bpl
sete %cl
orb %al, %cl
movl $0x1, %eax
cmpb $0x1, %cl
jne 0xbc33
cmpb $0x0, 0x1e5a8(%rip)     # 0x2a138
jne 0xbba5
leaq 0x189(%rip), %rsi       # 0xbd22
movl $0x64, %edi
xorl %edx, %edx
callq 0x47e0
movb $0x1, 0x1e58c(%rip)     # 0x2a138
jmp 0xbc31
testl %eax, %eax
sete %cl
andl $0x11, %ebp
cmpl $0x10, %ebp
setne %dl
movl $0x1, %eax
testb %cl, %dl
jne 0xbc33
cmpl $0x2, %r14d
jne 0xbbf0
leaq 0xa167(%rip), %rax      # 0x15d3c
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0xa152(%rip), %rax      # 0x15d34
cmpl $0x0, (%rax)
js 0xbc2a
leaq 0xa152(%rip), %rax      # 0x15d40
jmp 0xbc16
cmpl $0x3, %r14d
jne 0xbc2a
leaq 0xa143(%rip), %rax      # 0x15d40
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0xa12a(%rip), %rax      # 0x15d34
cmpl $0x0, (%rax)
js 0xbc2a
leaq 0xa126(%rip), %rax      # 0x15d3c
cmpl $0x0, (%rax)
jns 0xbc2a
leaq 0x1e3be(%rip), %rax     # 0x29fe0
movq (%rax), %rdi
callq 0x4160
movl %ebx, %edi
callq 0x4100
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq