// File: /workspace/github_c_makefile_star2_O0/containers[P]conmon/src/ctr_logging.c
// Function: write_k8s_log
static int write_k8s_log(stdpipe_t pipe, const char *buf, ssize_t buflen)
{
	writev_buffer_t bufv = {0};
	int64_t bytes_to_be_written = 0;

	/*
	 * Use the same timestamp for every line of the log in this buffer.
	 * There is no practical difference in the output since write(2) is
	 * fast.
	 */
	char tsbuf[TSBUFLEN];
	set_k8s_timestamp(tsbuf, sizeof tsbuf, stdpipe_name(pipe));

	ptrdiff_t line_len = 0;
	while (buflen > 0) {
		bool partial = get_line_len(&line_len, buf, buflen);

		/* This is line_len bytes + TSBUFLEN - 1 + 2 (- 1 is for ignoring \0). */
		bytes_to_be_written = line_len + TSBUFLEN + 1;

		/* If partial, then we add a \n */
		if (partial) {
			bytes_to_be_written += 1;
		}

		/* If the caller specified a global max, enforce it before writing */
		if (log_global_size_max > 0 && k8s_total_bytes_written >= log_global_size_max)
			break;

		/*
		 * We re-open the log file if writing out the bytes will exceed the max
		 * log size. We also reset the state so that the new file is started with
		 * a timestamp.
		 */
		if ((log_size_max > 0) && (k8s_bytes_written + bytes_to_be_written) > log_size_max) {
			if (writev_buffer_flush(k8s_log_fd, &bufv) < 0) {
				nwarn("failed to flush buffer to log");
			}
			/*
			 * Always reset the buffer after rotation to ensure clean state
			 * with the new file descriptor. Any unflushed data is lost, but
			 * this prevents corruption of subsequent log entries.
			 */
			bufv.iovcnt = 0;
			reopen_k8s_file();
		}

		/* Output the timestamp */
		if (writev_buffer_append_segment(k8s_log_fd, &bufv, tsbuf, TSBUFLEN - 1) < 0) {
			nwarn("failed to write (timestamp, stream) to log");
			goto next;
		}

		/* Output log tag for partial or newline */
		if (partial) {
			if (writev_buffer_append_segment(k8s_log_fd, &bufv, "P ", 2) < 0) {
				nwarn("failed to write partial log tag");
				goto next;
			}
		} else {
			if (writev_buffer_append_segment(k8s_log_fd, &bufv, "F ", 2) < 0) {
				nwarn("failed to write end log tag");
				goto next;
			}
		}

		/* Output the actual contents. */
		if (writev_buffer_append_segment(k8s_log_fd, &bufv, buf, line_len) < 0) {
			nwarn("failed to write buffer to log");
			goto next;
		}

		/* Output a newline for partial */
		if (partial) {
			if (writev_buffer_append_segment(k8s_log_fd, &bufv, "\n", 1) < 0) {
				nwarn("failed to write newline to log");
				goto next;
			}
		}

		k8s_bytes_written += bytes_to_be_written;
		k8s_total_bytes_written += bytes_to_be_written;
	next:
		/* Update the head of the buffer remaining to output. */
		buf += line_len;
		buflen -= line_len;
	}

	if (writev_buffer_flush(k8s_log_fd, &bufv) < 0) {
		nwarn("failed to flush buffer to log");
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x880, %rsp            # imm = 0x880
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x820(%rbp), %rdi
xorl %esi, %esi
movl $0x808, %edx            # imm = 0x808
callq 0x40b0
movq $0x0, -0x828(%rbp)
leaq -0x860(%rbp), %rax
movq %rax, -0x878(%rbp)
movl -0x4(%rbp), %edi
callq 0x8850
movq -0x878(%rbp), %rdi
movq %rax, %rdx
movl $0x2c, %esi
callq 0x8660
movq $0x0, -0x868(%rbp)
cmpq $0x0, -0x18(%rbp)
jle 0x7d24
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x868(%rbp), %rdi
callq 0x8510
andb $0x1, %al
movb %al, -0x869(%rbp)
movq -0x868(%rbp), %rax
addq $0x2c, %rax
addq $0x1, %rax
movq %rax, -0x828(%rbp)
testb $0x1, -0x869(%rbp)
je 0x7931
movq -0x828(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x828(%rbp)
cmpq $0x0, 0xeb5f(%rip)      # 0x16498
jle 0x7950
movq 0x1f556(%rip), %rax     # 0x26e98
cmpq 0xeb4f(%rip), %rax      # 0x16498
jl 0x7950
jmp 0x7d24
cmpq $0x0, 0xeb38(%rip)      # 0x16490
jle 0x7a03
movq 0x1f52b(%rip), %rax     # 0x26e90
addq -0x828(%rbp), %rax
cmpq 0xeb1d(%rip), %rax      # 0x16490
jle 0x7a03
movl 0xeb21(%rip), %edi      # 0x164a0
leaq -0x820(%rbp), %rsi
callq 0x88b0
cmpq $0x0, %rax
jge 0x79f4
leaq 0xeb0c(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0x79f2
jmp 0x799f
movq 0xe64a(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x77e7(%rip), %rsi      # 0xf197
leaq 0x867d(%rip), %rdx      # 0x10034
movb $0x0, %al
callq 0x4830
leaq 0x23583(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0x79ee
leaq 0x2356f(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x77f2(%rip), %rsi      # 0xf1d2
leaq 0x864d(%rip), %rcx      # 0x10034
movb $0x0, %al
callq 0x4120
jmp 0x79f0
jmp 0x79f2
jmp 0x79f4
movl $0x0, -0x820(%rbp)
callq 0x8340
movl 0xea97(%rip), %edi      # 0x164a0
leaq -0x860(%rbp), %rdx
leaq -0x820(%rbp), %rsi
movl $0x2b, %ecx
callq 0x89b0
cmpq $0x0, %rax
jge 0x7a8d
leaq 0xea76(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0x7a88
jmp 0x7a35
movq 0xe5b4(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x7751(%rip), %rsi      # 0xf197
leaq 0x8605(%rip), %rdx      # 0x10052
movb $0x0, %al
callq 0x4830
leaq 0x234ed(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0x7a84
leaq 0x234d9(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x775c(%rip), %rsi      # 0xf1d2
leaq 0x85d5(%rip), %rcx      # 0x10052
movb $0x0, %al
callq 0x4120
jmp 0x7a86
jmp 0x7a88
jmp 0x7cfe
testb $0x1, -0x869(%rbp)
je 0x7b29
movl 0xea00(%rip), %edi      # 0x164a0
leaq -0x820(%rbp), %rsi
leaq 0x85cf(%rip), %rdx      # 0x1007d
movl $0x2, %ecx
callq 0x89b0
cmpq $0x0, %rax
jge 0x7b24
leaq 0xe9df(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0x7b1f
jmp 0x7acc
movq 0xe51d(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x76ba(%rip), %rsi      # 0xf197
leaq 0x859c(%rip), %rdx      # 0x10080
movb $0x0, %al
callq 0x4830
leaq 0x23456(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0x7b1b
leaq 0x23442(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x76c5(%rip), %rsi      # 0xf1d2
leaq 0x856c(%rip), %rcx      # 0x10080
movb $0x0, %al
callq 0x4120
jmp 0x7b1d
jmp 0x7b1f
jmp 0x7cfe
jmp 0x7bb5
movl 0xe971(%rip), %edi      # 0x164a0
leaq -0x820(%rbp), %rsi
leaq 0x8563(%rip), %rdx      # 0x100a0
movl $0x2, %ecx
callq 0x89b0
cmpq $0x0, %rax
jge 0x7bb3
leaq 0xe950(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0x7bae
jmp 0x7b5b
movq 0xe48e(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x762b(%rip), %rsi      # 0xf197
leaq 0x8530(%rip), %rdx      # 0x100a3
movb $0x0, %al
callq 0x4830
leaq 0x233c7(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0x7baa
leaq 0x233b3(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x7636(%rip), %rsi      # 0xf1d2
leaq 0x8500(%rip), %rcx      # 0x100a3
movb $0x0, %al
callq 0x4120
jmp 0x7bac
jmp 0x7bae
jmp 0x7cfe
jmp 0x7bb5
movl 0xe8e5(%rip), %edi      # 0x164a0
movq -0x10(%rbp), %rdx
movq -0x868(%rbp), %rcx
leaq -0x820(%rbp), %rsi
callq 0x89b0
cmpq $0x0, %rax
jge 0x7c3e
leaq 0xe8c5(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0x7c39
jmp 0x7be6
movq 0xe403(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x75a0(%rip), %rsi      # 0xf197
leaq 0x84c1(%rip), %rdx      # 0x100bf
movb $0x0, %al
callq 0x4830
leaq 0x2333c(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0x7c35
leaq 0x23328(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x75ab(%rip), %rsi      # 0xf1d2
leaq 0x8491(%rip), %rcx      # 0x100bf
movb $0x0, %al
callq 0x4120
jmp 0x7c37
jmp 0x7c39
jmp 0x7cfe
testb $0x1, -0x869(%rbp)
je 0x7cd4
movl 0xe84f(%rip), %edi      # 0x164a0
leaq -0x820(%rbp), %rsi
leaq 0x8095(%rip), %rdx      # 0xfcf4
movl $0x1, %ecx
callq 0x89b0
cmpq $0x0, %rax
jge 0x7cd2
leaq 0xe82e(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0x7cd0
jmp 0x7c7d
movq 0xe36c(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x7509(%rip), %rsi      # 0xf197
leaq 0x8448(%rip), %rdx      # 0x100dd
movb $0x0, %al
callq 0x4830
leaq 0x232a5(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0x7ccc
leaq 0x23291(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x7514(%rip), %rsi      # 0xf1d2
leaq 0x8418(%rip), %rcx      # 0x100dd
movb $0x0, %al
callq 0x4120
jmp 0x7cce
jmp 0x7cd0
jmp 0x7cfe
jmp 0x7cd4
movq -0x828(%rbp), %rax
addq 0x1f1ae(%rip), %rax     # 0x26e90
movq %rax, 0x1f1a7(%rip)     # 0x26e90
movq -0x828(%rbp), %rax
addq 0x1f1a1(%rip), %rax     # 0x26e98
movq %rax, 0x1f19a(%rip)     # 0x26e98
movq -0x868(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x868(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
jmp 0x78d9
movl 0xe776(%rip), %edi      # 0x164a0
leaq -0x820(%rbp), %rsi
callq 0x88b0
cmpq $0x0, %rax
jge 0x7d9f
leaq 0xe761(%rip), %rax      # 0x164a4
cmpl $0x1, (%rax)
jb 0x7d9d
jmp 0x7d4a
movq 0xe29f(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x743c(%rip), %rsi      # 0xf197
leaq 0x82d2(%rip), %rdx      # 0x10034
movb $0x0, %al
callq 0x4830
leaq 0x231d8(%rip), %rax     # 0x2af48
cmpl $0x0, (%rax)
je 0x7d99
leaq 0x231c4(%rip), %rax     # 0x2af40
movq (%rax), %rdx
movl $0x6, %edi
leaq 0x7447(%rip), %rsi      # 0xf1d2
leaq 0x82a2(%rip), %rcx      # 0x10034
movb $0x0, %al
callq 0x4120
jmp 0x7d9b
jmp 0x7d9d
jmp 0x7d9f
xorl %eax, %eax
addq $0x880, %rsp            # imm = 0x880
popq %rbp
retq
nopw (%rax,%rax)