// File: /workspace/github_c_makefile_star2_O3/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 0x1e0d1(%rip), %rax     # 0x29f48
cmpl $0x0, (%rax)
leaq 0x2602(%rip), %rax      # 0xe483
leaq 0x46b1(%rip), %rcx      # 0x10539
cmoveq %rax, %rcx
leaq 0x1e0b9(%rip), %rax     # 0x29f4c
cmpl $0x0, (%rax)
leaq 0x258e(%rip), %r14      # 0xe42b
cmovleq %rcx, %r14
cmpl $-0x1, (%rdi)
je 0xc00f
movq %rdx, %r15
movl %esi, %edx
movq %rdi, %rbx
testq %r15, %r15
je 0xc01e
movl %edx, 0x4(%rsp)
movq %r15, %rdi
callq 0x4360
movq %rax, %rdi
callq 0x4330
movq %rax, %r12
movb (%r15), %bpl
testb %bpl, %bpl
je 0xbfdd
incq %r15
movsbl %bpl, %r13d
movzbl %r13b, %eax
cmpl $0x21, %eax
jg 0xbf0b
cmpl $0x9, %eax
je 0xbfbd
cmpl $0xa, %eax
jne 0xbf41
movq %r12, %rdi
leaq 0x4698(%rip), %rsi      # 0x1059e
jmp 0xbfc7
cmpl $0x5c, %eax
je 0xbf15
cmpl $0x22, %eax
jne 0xbf41
movq 0x8(%r12), %rax
leaq 0x1(%rax), %rcx
cmpq 0x10(%r12), %rcx
jae 0xbf69
movq (%r12), %rdx
movq %rcx, 0x8(%r12)
movb $0x5c, (%rdx,%rax)
movq (%r12), %rax
movq 0x8(%r12), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xbf7d
cmpb $0x1f, %bpl
setae %al
cmpb $0x7f, %bpl
setne %cl
testb %cl, %al
jne 0xbf7d
movq %r12, %rdi
leaq 0x4647(%rip), %rsi      # 0x105a4
movl %r13d, %edx
xorl %eax, %eax
callq 0x4880
jmp 0xbfce
movq %r12, %rdi
movq $-0x1, %rsi
movl $0x5c, %edx
callq 0x4670
movq 0x8(%r12), %rax
leaq 0x1(%rax), %rcx
cmpq 0x10(%r12), %rcx
jae 0xbfa9
movq (%r12), %rdx
movq %rcx, 0x8(%r12)
movb %bpl, (%rdx,%rax)
movq (%r12), %rax
movq 0x8(%r12), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xbfce
movq %r12, %rdi
movq $-0x1, %rsi
movl %r13d, %edx
callq 0x4670
jmp 0xbfce
movq %r12, %rdi
leaq 0x45da(%rip), %rsi      # 0x105a1
xorl %eax, %eax
callq 0x4880
movb (%r15), %bpl
incq %r15
testb %bpl, %bpl
jne 0xbee1
movq %r12, %rdi
xorl %esi, %esi
callq 0x43a0
movq %rax, %r15
leaq 0x4552(%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 0x48e8
jmp 0xc032
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x453b(%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 0x9bec
cmpq %r15, %rax
je 0xc066
callq 0x45b0
cmpl $0x20, (%rax)
jne 0xc07c
movl (%rbx), %edi
callq 0x4100
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x48e8
callq 0x7b08
nopl (%rax)