// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movl -0xc(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xd39d
movl -0x8(%rbp), %edi
movl -0x1c(%rbp), %esi
leaq -0x20(%rbp), %rdx
callq 0xd4c0
cmpl $0x0, -0x28(%rbp)
je 0xd401
leaq 0x1dbaa(%rip), %rax     # 0x2af54
cmpl $0x0, (%rax)
je 0xd401
cmpl $0x2, -0x1c(%rbp)
jne 0xd401
cmpl $0x0, -0x24(%rbp)
je 0xd3cd
cmpl $0x0, -0x20(%rbp)
jne 0xd3cd
movl $0x1, -0x4(%rbp)
jmp 0xd4ab
cmpl $0x0, 0x1dde4(%rip)     # 0x2b1b8
jne 0xd3eb
movl $0x64, %edi
leaq 0x28e(%rip), %rsi       # 0xd670
xorl %eax, %eax
movl %eax, %edx
callq 0x4800
movl $0x1, 0x1ddc3(%rip)     # 0x2b1b8
movl $0x0, -0x4(%rbp)
jmp 0xd4ab
cmpl $0x0, -0x20(%rbp)
jne 0xd41b
cmpl $0x0, -0x28(%rbp)
je 0xd4a4
cmpl $0x0, -0x24(%rbp)
jne 0xd4a4
cmpl $0x2, -0x1c(%rbp)
jne 0xd457
leaq 0x9924(%rip), %rax      # 0x16d4c
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x990f(%rip), %rax      # 0x16d44
cmpl $0x0, (%rax)
jl 0xd455
leaq 0x990f(%rip), %rax      # 0x16d50
cmpl $0x0, (%rax)
jge 0xd455
leaq 0x1dc13(%rip), %rax     # 0x2b060
movq (%rax), %rdi
callq 0x4160
jmp 0xd457
cmpl $0x3, -0x1c(%rbp)
jne 0xd493
leaq 0x98ec(%rip), %rax      # 0x16d50
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x98d3(%rip), %rax      # 0x16d44
cmpl $0x0, (%rax)
jl 0xd491
leaq 0x98cf(%rip), %rax      # 0x16d4c
cmpl $0x0, (%rax)
jge 0xd491
leaq 0x1dbd7(%rip), %rax     # 0x2b060
movq (%rax), %rdi
callq 0x4160
jmp 0xd493
movl -0x8(%rbp), %edi
callq 0x4100
movl $0x0, -0x4(%rbp)
jmp 0xd4ab
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)