// File: /workspace/github_c_makefile_star2_O2/containers[P]conmon/src/parent_pipe_fd.c
// Function: write_or_close_sync_fd
void write_or_close_sync_fd(int *fd, int res, const char *message)
{
	const char *res_key;
	if (opt_api_version >= 1)
		res_key = "data";
	else if (opt_exec)
		res_key = "exit_code";
	else
		res_key = "pid";

	ssize_t len;

	if (*fd == -1)
		return;

	_cleanup_free_ char *json = NULL;
	if (message) {
		_cleanup_free_ char *escaped_message = escape_json_string(message);
		json = g_strdup_printf("{\"%s\": %d, \"message\": \"%s\"}\n", res_key, res, escaped_message);
	} else {
		json = g_strdup_printf("{\"%s\": %d}\n", res_key, res);
	}

	len = strlen(json);
	if (write_all(*fd, json, len) != len) {
		if (errno == EPIPE) {
			close(*fd);
			*fd = -1;
			return;
		}
		pexit("Unable to send container stderr message to parent");
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x1df40(%rip), %rax     # 0x28f58
cmpl $0x0, (%rax)
leaq 0x3461(%rip), %rax      # 0xe483
leaq 0x5510(%rip), %rcx      # 0x10539
cmoveq %rax, %rcx
leaq 0x1df28(%rip), %rax     # 0x28f5c
cmpl $0x0, (%rax)
leaq 0x33ed(%rip), %r14      # 0xe42b
cmovleq %rcx, %r14
cmpl $-0x1, (%rdi)
je 0xb12d
movq %rdx, %r15
movl %esi, %edx
movq %rdi, %rbx
testq %r15, %r15
je 0xb13c
movl %edx, 0x4(%rsp)
movq %r15, %rdi
callq 0x4360
movq %rax, %rdi
callq 0x4330
movq %rax, %r12
pushq $0x5c
popq %r13
movsbl (%r15), %ebp
testl %ebp, %ebp
je 0xb0fb
incq %r15
cmpb $0x9, %bpl
je 0xb0be
movzbl %bpl, %eax
cmpl $0xa, %eax
je 0xb0b2
cmpl $0x5c, %eax
je 0xb09b
cmpl $0x22, %eax
jne 0xb0d1
movq %r12, %rdi
movl %r13d, %esi
callq 0xb1ec
movq %r12, %rdi
movl %ebp, %esi
callq 0xb1ec
jmp 0xb077
movq %r12, %rdi
leaq 0x54e2(%rip), %rsi      # 0x1059e
jmp 0xb0c8
movq %r12, %rdi
leaq 0x54d9(%rip), %rsi      # 0x105a1
xorl %eax, %eax
callq 0x4890
jmp 0xb077
cmpb $0x1f, %bpl
setae %al
cmpb $0x7f, %bpl
setne %cl
testb %cl, %al
jne 0xb0a6
movq %r12, %rdi
leaq 0x54b7(%rip), %rsi      # 0x105a4
movl %ebp, %edx
xorl %eax, %eax
callq 0x4890
jmp 0xb077
movq %r12, %rdi
xorl %esi, %esi
callq 0x43a0
movq %rax, %r15
leaq 0x5434(%rip), %rdi      # 0x10543
movq %r14, %rsi
movl 0x4(%rsp), %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4380
movq %rax, %r14
movq %r15, %rdi
callq 0x48f8
jmp 0xb150
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x541d(%rip), %rdi      # 0x10560
movq %r14, %rsi
xorl %eax, %eax
callq 0x4380
movq %rax, %r14
movq %r14, %rdi
callq 0x4360
movq %rax, %r15
movl (%rbx), %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x770f
cmpq %r15, %rax
je 0xb181
callq 0x45c0
cmpl $0x20, (%rax)
jne 0xb197
movl (%rbx), %edi
callq 0x4100
orl $-0x1, (%rbx)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x48f8
movq 0x8e52(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x1e6b(%rip), %rsi      # 0xd013
leaq 0x53bd(%rip), %rdx      # 0x1056c
xorl %eax, %eax
callq 0x4830
leaq 0x1dd1b(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0xb1e4
leaq 0x1dd07(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x1e6a(%rip), %rsi      # 0xd03d
leaq 0x5392(%rip), %rcx      # 0x1056c
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x4120
pushq $0x1
popq %rdi
callq 0x41e0