// File: /workspace/github_c_makefile_star2_O0/containers[P]conmon/src/ctr_logging.c
// Function: write_journald
static int write_journald(int pipe, char *buf, ssize_t buflen)
{
	static char stdout_partial_buf[STDIO_BUF_SIZE];
	static size_t stdout_partial_buf_len = 0;
	static char stderr_partial_buf[STDIO_BUF_SIZE];
	static size_t stderr_partial_buf_len = 0;

	char *partial_buf;
	size_t *partial_buf_len;

	/* Since we know the priority values for the journal (6 being log info and 3 being log err
	 * we can set it statically here. This will also save on runtime, at the expense of needing
	 * to be changed if this convention is changed.
	 */
	const char *message_priority = "PRIORITY=6";
	if (pipe == STDERR_PIPE) {
		message_priority = "PRIORITY=3";
		partial_buf = stderr_partial_buf;
		partial_buf_len = &stderr_partial_buf_len;
	} else {
		partial_buf = stdout_partial_buf;
		partial_buf_len = &stdout_partial_buf_len;
	}

	ptrdiff_t line_len = 0;

	while (buflen > 0 || *partial_buf_len > 0) {
		writev_buffer_t bufv = {0};

		bool partial = buflen == 0 || get_line_len(&line_len, buf, buflen);

		/* If this is a partial line, and we have capacity to buffer it, buffer it and return.
		 * The capacity of the partial_buf is one less than its size so that we can always add
		 * a null terminating char later */
		if (buflen && partial && ((unsigned long)line_len < (STDIO_BUF_SIZE - *partial_buf_len))) {
			memcpy(partial_buf + *partial_buf_len, buf, line_len);
			*partial_buf_len += line_len;
			return 0;
		}

		ssize_t msg_len = line_len + MESSAGE_EQ_LEN + *partial_buf_len;
		partial_buf[*partial_buf_len] = '\0';

		_cleanup_free_ char *message = g_malloc(msg_len);

		memcpy(message, "MESSAGE=", MESSAGE_EQ_LEN);
		memcpy(message + MESSAGE_EQ_LEN, partial_buf, *partial_buf_len);
		memcpy(message + MESSAGE_EQ_LEN + *partial_buf_len, buf, line_len);

		if (writev_buffer_append_segment_no_flush(&bufv, message, msg_len) < 0)
			return -1;

		if (writev_buffer_append_segment_no_flush(&bufv, container_id_full, cuuid_len + CID_FULL_EQ_LEN) < 0)
			return -1;

		if (writev_buffer_append_segment_no_flush(&bufv, message_priority, PRIORITY_EQ_LEN) < 0)
			return -1;

		if (writev_buffer_append_segment_no_flush(&bufv, container_id, TRUNC_ID_LEN + CID_EQ_LEN) < 0)
			return -1;

		if (container_tag && writev_buffer_append_segment_no_flush(&bufv, container_tag, container_tag_len) < 0)
			return -1;

		/* only print the name if we have a name to print */
		if (name && writev_buffer_append_segment_no_flush(&bufv, container_name, name_len + NAME_EQ_LEN) < 0)
			return -1;

		if (writev_buffer_append_segment_no_flush(&bufv, syslog_identifier, syslog_identifier_len) < 0)
			return -1;

		/* per docker journald logging format, CONTAINER_PARTIAL_MESSAGE is set to true if it's partial, but otherwise not set. */
		if (partial && writev_buffer_append_segment_no_flush(&bufv, "CONTAINER_PARTIAL_MESSAGE=true", PARTIAL_MESSAGE_EQ_LEN) < 0)
			return -1;
		if (container_labels) {
			for (gchar **label = container_labels; *label; ++label) {
				if (writev_buffer_append_segment_no_flush(&bufv, *label, strlen(*label)) < 0)
					return -1;
			}
		}

		int err = sd_journal_sendv(bufv.iov, bufv.iovcnt);
		if (err < 0) {
			nwarnf("sd_journal_sendv: %s", strerror(-err));
			return err;
		}

		buf += line_len;
		buflen -= line_len;
		*partial_buf_len = 0;
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x890, %rsp            # imm = 0x890
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0x81da(%rip), %rax      # 0xffa7
movq %rax, -0x30(%rbp)
cmpl $0x3, -0x8(%rbp)
jne 0x7dfa
leaq 0x81d4(%rip), %rax      # 0xffb2
movq %rax, -0x30(%rbp)
leaq 0x21147(%rip), %rax     # 0x28f30
movq %rax, -0x20(%rbp)
leaq 0x2313c(%rip), %rax     # 0x2af30
movq %rax, -0x28(%rbp)
jmp 0x7e10
leaq 0x1f11f(%rip), %rax     # 0x26f20
movq %rax, -0x20(%rbp)
leaq 0x21114(%rip), %rax     # 0x28f20
movq %rax, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movb $0x1, %al
cmpq $0x0, -0x18(%rbp)
movb %al, -0x86d(%rbp)
jg 0x7e38
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
seta %al
movb %al, -0x86d(%rbp)
movb -0x86d(%rbp), %al
testb $0x1, %al
jne 0x7e47
jmp 0x82e9
leaq -0x840(%rbp), %rdi
xorl %esi, %esi
movl $0x808, %edx            # imm = 0x808
callq 0x40b0
movb $0x1, %al
cmpq $0x0, -0x18(%rbp)
movb %al, -0x86e(%rbp)
je 0x7e80
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x8510
movb %al, -0x86e(%rbp)
movb -0x86e(%rbp), %al
andb $0x1, %al
movb %al, -0x841(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x7ee5
testb $0x1, -0x841(%rbp)
je 0x7ee5
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rdx
movl $0x2000, %ecx           # imm = 0x2000
subq (%rdx), %rcx
cmpq %rcx, %rax
jae 0x7ee5
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
addq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x48b0
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x82f0
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq -0x28(%rbp), %rcx
addq (%rcx), %rax
movq %rax, -0x850(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
movq -0x850(%rbp), %rdi
callq 0x42c0
movq %rax, -0x858(%rbp)
movq -0x858(%rbp), %rax
movq 0x8092(%rip), %rcx      # 0xffbd
movq %rcx, (%rax)
movq -0x858(%rbp), %rdi
addq $0x8, %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
callq 0x48b0
movq -0x858(%rbp), %rdi
addq $0x8, %rdi
movq -0x28(%rbp), %rax
addq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x48b0
movq -0x858(%rbp), %rsi
movq -0x850(%rbp), %rdx
leaq -0x840(%rbp), %rdi
callq 0x85a0
cmpq $0x0, %rax
jge 0x7f9e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x85c(%rbp)
jmp 0x82ca
movq 0x1ef2b(%rip), %rsi     # 0x26ed0
movq 0x1eefc(%rip), %rdx     # 0x26ea8
addq $0x12, %rdx
leaq -0x840(%rbp), %rdi
callq 0x85a0
cmpq $0x0, %rax
jge 0x7fd8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x85c(%rbp)
jmp 0x82ca
movq -0x30(%rbp), %rsi
leaq -0x840(%rbp), %rdi
movl $0xa, %edx
callq 0x85a0
cmpq $0x0, %rax
jge 0x8009
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x85c(%rbp)
jmp 0x82ca
movq 0x1eec8(%rip), %rsi     # 0x26ed8
leaq -0x840(%rbp), %rdi
movl $0x19, %edx
callq 0x85a0
cmpq $0x0, %rax
jge 0x803d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x85c(%rbp)
jmp 0x82ca
cmpq $0x0, 0x1eebb(%rip)     # 0x26f00
je 0x807d
movq 0x1eeb2(%rip), %rsi     # 0x26f00
movq 0x1eeb3(%rip), %rdx     # 0x26f08
leaq -0x840(%rbp), %rdi
callq 0x85a0
cmpq $0x0, %rax
jge 0x807d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x85c(%rbp)
jmp 0x82ca
cmpq $0x0, 0x1ee43(%rip)     # 0x26ec8
je 0x80c1
movq 0x1ee6a(%rip), %rsi     # 0x26ef8
movq 0x1ee5b(%rip), %rdx     # 0x26ef0
addq $0xf, %rdx
leaq -0x840(%rbp), %rdi
callq 0x85a0
cmpq $0x0, %rax
jge 0x80c1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x85c(%rbp)
jmp 0x82ca
movq 0x1ee18(%rip), %rsi     # 0x26ee0
movq 0x1ee19(%rip), %rdx     # 0x26ee8
leaq -0x840(%rbp), %rdi
callq 0x85a0
cmpq $0x0, %rax
jge 0x80f7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x85c(%rbp)
jmp 0x82ca
testb $0x1, -0x841(%rbp)
je 0x8134
leaq -0x840(%rbp), %rdi
leaq 0x7eb8(%rip), %rsi      # 0xffc6
movl $0x1e, %edx
callq 0x85a0
cmpq $0x0, %rax
jge 0x8134
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x85c(%rbp)
jmp 0x82ca
cmpq $0x0, 0x1edd4(%rip)     # 0x26f10
je 0x81c7
movq 0x1edc7(%rip), %rax     # 0x26f10
movq %rax, -0x868(%rbp)
movq -0x868(%rbp), %rax
cmpq $0x0, (%rax)
je 0x81c5
movq -0x868(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x878(%rbp)
movq -0x868(%rbp), %rax
movq (%rax), %rdi
callq 0x4360
movq -0x878(%rbp), %rsi
movq %rax, %rdx
leaq -0x840(%rbp), %rdi
callq 0x85a0
cmpq $0x0, %rax
jge 0x81af
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x85c(%rbp)
jmp 0x82ca
jmp 0x81b1
movq -0x868(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x868(%rbp)
jmp 0x8150
jmp 0x81c7
leaq -0x840(%rbp), %rdi
addq $0x8, %rdi
movl -0x840(%rbp), %esi
callq 0x8640
movl %eax, -0x86c(%rbp)
cmpl $0x0, -0x86c(%rbp)
jge 0x829a
leaq 0xe2ad(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0x8285
jmp 0x8202
movq 0xdde7(%rip), %rax      # 0x15ff0
movq (%rax), %rax
movq %rax, -0x880(%rbp)
xorl %edi, %edi
subl -0x86c(%rbp), %edi
callq 0x44b0
movq -0x880(%rbp), %rdi
movq %rax, %rdx
leaq 0x7db4(%rip), %rsi      # 0xffe5
movb $0x0, %al
callq 0x4830
leaq 0x22d09(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0x827f
leaq 0x22cf5(%rip), %rax     # 0x2af40
movq (%rax), %rax
movq %rax, -0x888(%rbp)
xorl %edi, %edi
subl -0x86c(%rbp), %edi
callq 0x44b0
movq -0x888(%rbp), %rdx
movq %rax, %rcx
movl $0x6, %edi
leaq 0x7d8f(%rip), %rsi      # 0x10007
movb $0x0, %al
callq 0x4120
jmp 0x8281
jmp 0x8283
jmp 0x8285
movl -0x86c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x85c(%rbp)
jmp 0x82ca
movq -0x38(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x85c(%rbp)
leaq -0x858(%rbp), %rdi
callq 0x8580
movl -0x85c(%rbp), %eax
testl %eax, %eax
je 0x82e4
jmp 0x82e2
jmp 0x82f0
jmp 0x7e18
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x890, %rsp            # imm = 0x890
popq %rbp
retq
nopl (%rax)