// File: /workspace/github_cpp_makefile_star2_O1/AGWA[P]logmailer/logmailer.cpp
// Function: Log_mailer::run(int const volatile&, int volatile&)
void run (const volatile sig_atomic_t& is_running, volatile sig_atomic_t& flush_requested)
	{
		fd_set			rfds;
		FD_ZERO(&rfds);
		const int		nfds = fd + 1;

		sigset_t		empty_sigset;
		sigemptyset(&empty_sigset);

		while (is_running) {
			FD_SET(fd, &rfds);

			struct timespec	timeout;
			if (flush_requested) {
				flush();
				flush_requested = 0;
			} else if (has_complete_message()) {
				timeout.tv_sec = min_wait_time;
				timeout.tv_nsec = 0;

				const std::time_t	now = get_time();

				// If now < start_time, it means that the system clock moved backwards. If this
				// happens, just flush the current messages out so we can start fresh with the
				// correct time when we receive the next message.
				if (now < start_time || now >= start_time + max_wait_time || buffer.size() >= max_buffer_size) {
					flush();
				} else if ((start_time + max_wait_time) - now < timeout.tv_sec) {
					timeout.tv_sec = (start_time + max_wait_time) - now;
				}
			}

			const int	select_res = pselect(nfds, &rfds, NULL, NULL,
								has_complete_message() ? &timeout : NULL,
								&empty_sigset);
			if (select_res == -1) {
				if (errno == EINTR) {
					continue;
				}
				throw System_error("pselect", "", errno);
			}
			if (select_res == 0) {
				// implied: has_complete_message() is true because otherwise we wouldn't
				// have passed a timeout to pselect() so pselect() could not have returned 0.
				flush();
				continue;
			}

			char		read_buffer[1024];
			const ssize_t	bytes_read = read(fd, read_buffer, sizeof(read_buffer));
			if (bytes_read == -1) {
				if (errno == EAGAIN) {
					continue;
				}
				throw System_error("pselect", "", errno);
			}
			if (bytes_read == 0) {
				// need to re-open the FIFO
				open_fifo();
				continue;
			}

			if (const char* newline = find_last_newline(read_buffer, bytes_read)) {
				if (!has_complete_message()) {
					start_time = get_time();
				}
				last_newline = buffer.size() + (newline - read_buffer);
			}

			buffer.append(read_buffer, bytes_read);
		}

		flush();
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x568, %rsp            # imm = 0x568
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movl 0x78(%rdi), %ebp
leaq 0xe0(%rsp), %rdi
callq 0x2310
cmpl $0x0, (%r15)
je 0x39cc
incl %ebp
leaq 0x80(%rbx), %rax
movq %rax, 0x30(%rsp)
leaq 0x160(%rsp), %r13
movq %r15, 0x38(%rsp)
movl 0x78(%rbx), %ecx
leal 0x3f(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movl %eax, %edx
andl $-0x40, %edx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0x60(%rsp,%rax,8)
cmpl $0x0, (%r14)
je 0x3879
movq %rbx, %rdi
callq 0x3e2c
movl $0x0, (%r14)
jmp 0x38d2
cmpq $-0x1, 0xa0(%rbx)
je 0x38d2
movq 0x60(%rbx), %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
callq 0x3555
movq 0xa8(%rbx), %rcx
cmpq %rcx, %rax
jl 0x38ca
addq 0x68(%rbx), %rcx
subq %rax, %rcx
jle 0x38ca
movq 0x88(%rbx), %rax
cmpq 0x70(%rbx), %rax
jae 0x38ca
cmpq 0x20(%rsp), %rcx
jge 0x38d2
movq %rcx, 0x20(%rsp)
jmp 0x38d2
movq %rbx, %rdi
callq 0x3e2c
cmpq $-0x1, 0xa0(%rbx)
leaq 0x20(%rsp), %r8
movl $0x0, %eax
cmoveq %rax, %r8
movl %ebp, %edi
leaq 0x60(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0xe0(%rsp), %r9
callq 0x22a0
testl %eax, %eax
je 0x391c
cmpl $-0x1, %eax
jne 0x3929
callq 0x2040
cmpl $0x4, (%rax)
je 0x39c2
jmp 0x39e6
movq %rbx, %rdi
callq 0x3e2c
jmp 0x39c2
movl 0x78(%rbx), %edi
movl $0x400, %edx            # imm = 0x400
movq %r13, %rsi
callq 0x2370
testq %rax, %rax
je 0x3956
movq %rax, %r12
cmpq $-0x1, %rax
jne 0x3960
callq 0x2040
cmpl $0xb, (%rax)
je 0x39c2
jmp 0x3a6c
movq %rbx, %rdi
callq 0x367e
jmp 0x39c2
leaq (%rsp,%r12), %rax
addq $0x160, %rax            # imm = 0x160
cmpq %r13, %rax
jbe 0x397e
leaq -0x1(%rax), %r15
cmpb $0xa, -0x1(%rax)
movq %r15, %rax
jne 0x396a
jmp 0x3981
xorl %r15d, %r15d
testq %r15, %r15
je 0x39ad
cmpq $-0x1, 0xa0(%rbx)
jne 0x399c
callq 0x3555
movq %rax, 0xa8(%rbx)
subq %r13, %r15
addq 0x88(%rbx), %r15
movq %r15, 0xa0(%rbx)
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2060
movq 0x38(%rsp), %r15
cmpl $0x0, (%r15)
jne 0x383e
movq %rbx, %rdi
callq 0x3e2c
addq $0x568, %rsp            # imm = 0x568
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
movl $0x48, %edi
callq 0x2130
movq %rax, %r14
leaq 0x170(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x17a4(%rip), %rsi      # 0x51ad
leaq 0x17a4(%rip), %rdx      # 0x51b4
leaq 0x160(%rsp), %rdi
callq 0x3cde
leaq 0x10(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x17a4(%rip), %rdx      # 0x51d1
movq %rsp, %rdi
movq %rdx, %rsi
callq 0x3cde
movl (%r12), %ecx
movb $0x1, %bpl
leaq 0x160(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0x3c38
xorl %ebp, %ebp
leaq 0x3325(%rip), %rsi      # 0x6d80
leaq 0x246(%rip), %rdx       # 0x3ca8
movq %r14, %rdi
callq 0x2430
jmp 0x3ae7
movq %rax, %r12
movl $0x48, %edi
callq 0x2130
movq %rax, %r14
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1721(%rip), %rsi      # 0x51ad
leaq 0x1721(%rip), %rdx      # 0x51b4
movq %rsp, %rdi
callq 0x3cde
leaq 0x50(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x1726(%rip), %rdx      # 0x51d1
leaq 0x40(%rsp), %rdi
movq %rdx, %rsi
callq 0x3cde
movl (%r12), %ecx
movb $0x1, %bpl
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
callq 0x3c38
xorl %ebp, %ebp
leaq 0x32a8(%rip), %rsi      # 0x6d80
leaq 0x1c9(%rip), %rdx       # 0x3ca8
movq %r14, %rdi
callq 0x2430
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0x3b09
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2280
jmp 0x3b09
movq %rax, %rbx
movb $0x1, %bpl
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x3b61
movq 0x10(%rsp), %rsi
jmp 0x3b51
jmp 0x3b5b
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x3b3c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2280
jmp 0x3b3c
movq %rax, %rbx
movb $0x1, %bpl
movq 0x160(%rsp), %rdi
cmpq %r15, %rdi
je 0x3b61
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x2280
jmp 0x3b61
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x3b6e
movq %r14, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2450