// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq 0x1a58f(%rip), %rsi     # 0x26e58
movslq 0x1a580(%rip), %rdx     # 0x26e50
callq 0x4230
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jg 0xc945
leaq 0x9bbd(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0xc939
jmp 0xc8ee
movq 0x96fb(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movl -0x8(%rbp), %edx
leaq 0x5bee(%rip), %rsi      # 0x124f0
movb $0x0, %al
callq 0x4830
leaq 0x1e638(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc935
leaq 0x1e624(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl -0x8(%rbp), %ecx
movl $0x6, %edi
leaq 0x5be9(%rip), %rsi      # 0x12517
movb $0x0, %al
callq 0x4120
jmp 0xc937
jmp 0xc939
movl $0x1, -0x4(%rbp)
jmp 0xcb2b
movq 0x1a50c(%rip), %rax     # 0x26e58
movq -0x18(%rbp), %rcx
movb $0x0, (%rax,%rcx)
leaq 0x9b49(%rip), %rax      # 0x164a4
cmpl $0x3, (%rax)
jb 0xc9bc
jmp 0xc962
movq 0x9687(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movl -0x8(%rbp), %ecx
leaq 0x5bd3(%rip), %rsi      # 0x12549
leaq 0x1e773(%rip), %rdx     # 0x2b0f0
movb $0x0, %al
callq 0x4830
leaq 0x1e5bd(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xc9b8
leaq 0x1e5a9(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl -0x8(%rbp), %r8d
movl $0x6, %edi
leaq 0x5bc9(%rip), %rsi      # 0x12573
leaq 0x1e73f(%rip), %rcx     # 0x2b0f0
movb $0x0, %al
callq 0x4120
jmp 0xc9ba
jmp 0xc9bc
leaq 0x1e72d(%rip), %rax     # 0x2b0f0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl $0xa, %esi
callq 0x4300
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xca20
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rdi
callq *%rax
cmpl $0x0, %eax
jne 0xca00
movl $0x1, -0x4(%rbp)
jmp 0xcb2b
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl $0xa, %esi
callq 0x4300
movq %rax, -0x28(%rbp)
jmp 0xc9d9
cmpq $0xc7, -0x18(%rbp)
jne 0xca9d
leaq 0x1e6bf(%rip), %rax     # 0x2b0f0
cmpq %rax, -0x20(%rbp)
jne 0xca9d
leaq 0x9a66(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0xca98
jmp 0xca45
movq 0x95a4(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2741(%rip), %rsi      # 0xf197
leaq 0x5b4c(%rip), %rdx      # 0x125a9
movb $0x0, %al
callq 0x4830
leaq 0x1e4dd(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0xca94
leaq 0x1e4c9(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x274c(%rip), %rsi      # 0xf1d2
leaq 0x5b1c(%rip), %rcx      # 0x125a9
movb $0x0, %al
callq 0x4120
jmp 0xca96
jmp 0xca98
jmp 0xcb24
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xcac3
leaq 0x1e640(%rip), %rax     # 0x2b0f0
movq %rax, 0x1a3a1(%rip)     # 0x26e58
movl $0xc7, 0x1a38f(%rip)    # 0x26e50
jmp 0xcb22
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movb (%rax), %dl
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
movslq %eax, %rcx
leaq 0x1e600(%rip), %rax     # 0x2b0f0
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xcaca
movslq -0x2c(%rbp), %rcx
leaq 0x1e5e6(%rip), %rax     # 0x2b0f0
addq %rcx, %rax
movq %rax, 0x1a344(%rip)     # 0x26e58
movl $0xc7, %eax
subl -0x2c(%rbp), %eax
movl %eax, 0x1a32e(%rip)     # 0x26e50
jmp 0xcb24
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)