// File: /workspace/github_c_makefile_star2_O2/containers[P]conmon/src/ctrl.c
// Function: read_from_ctrl_buffer
static gboolean read_from_ctrl_buffer(int fd, gboolean (*line_process_func)(char *))
{
#define CTLBUFSZ 200
	static char ctlbuf[CTLBUFSZ];
	static int readsz = CTLBUFSZ - 1;
	static char *readptr = ctlbuf;
	ssize_t num_read = read(fd, readptr, readsz);
	if (num_read <= 0) {
		nwarnf("Failed to read from fd %d", fd);
		return G_SOURCE_CONTINUE;
	}

	readptr[num_read] = '\0';
	ndebugf("Got ctl message: %s on fd %d", ctlbuf, fd);

	char *beg = ctlbuf;
	char *newline = strchrnul(beg, '\n');
	/* Process each message which ends with a line */
	while (*newline != '\0') {
		if (!line_process_func(beg))
			return G_SOURCE_CONTINUE;

		beg = newline + 1;
		newline = strchrnul(beg, '\n');
	}
	if (num_read == (CTLBUFSZ - 1) && beg == ctlbuf) {
		/*
		 * We did not find a newline in the entire buffer.
		 * This shouldn't happen as our buffer is larger than
		 * the message that we expect to receive.
		 */
		nwarn("Could not find newline in entire buffer");
	} else if (*beg == '\0') {
		/* We exhausted all messages that were complete */
		readptr = ctlbuf;
		readsz = CTLBUFSZ - 1;
	} else {
		/*
		 * We copy remaining data to beginning of buffer
		 * and advance readptr after that.
		 */
		int cp_rem = 0;
		do {
			ctlbuf[cp_rem++] = *beg++;
		} while (*beg != '\0');
		readptr = ctlbuf + cp_rem;
		readsz = CTLBUFSZ - 1 - cp_rem;
	}

	return G_SOURCE_CONTINUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %ebp
movq 0x1aa80(%rip), %rsi     # 0x24e58
movslq 0x1aa71(%rip), %rdx     # 0x24e50
callq 0x4230
testq %rax, %rax
jle 0xa43a
movq %rax, %r14
movq 0x1aa65(%rip), %rax     # 0x24e58
movb $0x0, (%rax,%r14)
leaq 0xa0a5(%rip), %r13      # 0x144a4
cmpl $0x3, (%r13)
jae 0xa571
leaq 0x1ec6f(%rip), %r15     # 0x29080
pushq $0xa
popq %rbp
movq %r15, %rdi
movl %ebp, %esi
callq 0x4300
cmpb $0x0, (%rax)
je 0xa49f
movq %rax, %r12
movq %r15, %rdi
callq *%rbx
incq %r12
movq %r12, %r15
testl %eax, %eax
jne 0xa414
jmp 0xa562
leaq 0xa063(%rip), %rax      # 0x144a4
cmpl $0x0, (%rax)
je 0xa562
movq 0x9b9f(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x5d5a(%rip), %rsi      # 0x101b5
movl %ebp, %edx
xorl %eax, %eax
callq 0x4830
leaq 0x1ea6d(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0xa562
leaq 0x1ea55(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x5d57(%rip), %rsi      # 0x101dc
pushq $0x6
popq %rdi
movl %ebp, %ecx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4120
xorq $0xc7, %r14
leaq 0x1ebd3(%rip), %rax     # 0x29080
movq %r15, %rcx
xorq %rax, %rcx
orq %r14, %rcx
jne 0xa51e
cmpl $0x0, (%r13)
je 0xa562
movq 0x9b26(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x2cc3(%rip), %rsi      # 0xd197
leaq 0x5d93(%rip), %rdx      # 0x1026e
xorl %eax, %eax
callq 0x4830
leaq 0x1e9ef(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0xa562
leaq 0x1e9db(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x2cd3(%rip), %rsi      # 0xd1d2
leaq 0x5d68(%rip), %rcx      # 0x1026e
pushq $0x6
popq %rdi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4120
movb (%r15), %dl
testb %dl, %dl
je 0xa551
xorl %ecx, %ecx
movb %dl, (%rcx,%rax)
movb 0x1(%r15,%rcx), %dl
incq %rcx
testb %dl, %dl
jne 0xa527
movl %ecx, %edx
addq %rdx, %rax
movq %rax, 0x1a916(%rip)     # 0x24e58
movl $0xc7, %eax
subl %ecx, %eax
movl %eax, 0x1a901(%rip)     # 0x24e50
jmp 0xa562
movq %rax, 0x1a900(%rip)     # 0x24e58
movl $0xc7, 0x1a8ee(%rip)    # 0x24e50
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9a78(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x5c8c(%rip), %rsi      # 0x1020e
leaq 0x1eaf7(%rip), %rdx     # 0x29080
movl %ebp, %ecx
xorl %eax, %eax
callq 0x4830
leaq 0x1e93f(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0xa40a
leaq 0x1e927(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x5c85(%rip), %rsi      # 0x10238
leaq 0x1eac6(%rip), %rcx     # 0x29080
pushq $0x6
popq %rdi
movl %ebp, %r8d
xorl %eax, %eax
callq 0x4120
jmp 0xa40a