// File: /workspace/github_c_makefile_star2_O1/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 0xbe48
leaq 0xc(%rsp), %rdx
movl %ebx, %edi
movl %r14d, %esi
callq 0xbf46
movl 0xc(%rsp), %eax
cmpl $0x2, %r14d
jne 0xbea9
movl %ebp, %ecx
andl $0x10, %ecx
je 0xbea9
leaq 0x1e074(%rip), %rcx     # 0x29ed4
cmpl $0x0, (%rcx)
je 0xbea9
testl %eax, %eax
setne %al
testb $0x1, %bpl
sete %cl
orb %al, %cl
movl $0x1, %eax
cmpb $0x1, %cl
jne 0xbf3d
cmpb $0x0, 0x1e2b0(%rip)     # 0x2a138
jne 0xbe9d
leaq 0x185(%rip), %rsi       # 0xc016
movl $0x64, %edi
xorl %edx, %edx
callq 0x47e0
movb $0x1, 0x1e294(%rip)     # 0x2a138
jmp 0xbf3b
testl %eax, %eax
sete %cl
andl $0x11, %ebp
cmpl $0x10, %ebp
setne %dl
movl $0x1, %eax
testb %cl, %dl
jne 0xbf3d
cmpl $0x2, %r14d
jne 0xbefa
leaq 0x9e6f(%rip), %rax      # 0x15d3c
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x9e5a(%rip), %rax      # 0x15d34
cmpl $0x0, (%rax)
js 0xbefa
leaq 0x9e5a(%rip), %rax      # 0x15d40
cmpl $0x0, (%rax)
jns 0xbefa
leaq 0x1e0ee(%rip), %rax     # 0x29fe0
movq (%rax), %rdi
callq 0x4160
cmpl $0x3, %r14d
jne 0xbf34
leaq 0x9e39(%rip), %rax      # 0x15d40
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x9e20(%rip), %rax      # 0x15d34
cmpl $0x0, (%rax)
js 0xbf34
leaq 0x9e1c(%rip), %rax      # 0x15d3c
cmpl $0x0, (%rax)
jns 0xbf34
leaq 0x1e0b4(%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