// File: /workspace/github_c_makefile_star2_O1/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 0x1dddd(%rip), %rax     # 0x29f48
cmpl $0x0, (%rax)
leaq 0x232e(%rip), %rax      # 0xe4a3
leaq 0x43dd(%rip), %rcx      # 0x10559
cmoveq %rax, %rcx
leaq 0x1ddc5(%rip), %rax     # 0x29f4c
cmpl $0x0, (%rax)
leaq 0x22ba(%rip), %r14      # 0xe44b
cmovleq %rcx, %r14
cmpl $-0x1, (%rdi)
je 0xc303
movq %rdx, %r15
movl %esi, %edx
movq %rdi, %rbx
testq %r15, %r15
je 0xc312
movl %edx, 0x4(%rsp)
movq %r15, %rdi
callq 0x4360
movq %rax, %rdi
callq 0x4330
movq %rax, %r12
movb (%r15), %bpl
testb %bpl, %bpl
je 0xc2d1
incq %r15
movsbl %bpl, %r13d
movzbl %r13b, %eax
cmpl $0x21, %eax
jg 0xc1ff
cmpl $0x9, %eax
je 0xc2b1
cmpl $0xa, %eax
jne 0xc235
movq %r12, %rdi
leaq 0x43c4(%rip), %rsi      # 0x105be
jmp 0xc2bb
cmpl $0x5c, %eax
je 0xc209
cmpl $0x22, %eax
jne 0xc235
movq 0x8(%r12), %rax
leaq 0x1(%rax), %rcx
cmpq 0x10(%r12), %rcx
jae 0xc25d
movq (%r12), %rdx
movq %rcx, 0x8(%r12)
movb $0x5c, (%rdx,%rax)
movq (%r12), %rax
movq 0x8(%r12), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xc271
cmpb $0x1f, %bpl
setae %al
cmpb $0x7f, %bpl
setne %cl
testb %cl, %al
jne 0xc271
movq %r12, %rdi
leaq 0x4373(%rip), %rsi      # 0x105c4
movl %r13d, %edx
xorl %eax, %eax
callq 0x4880
jmp 0xc2c2
movq %r12, %rdi
movq $-0x1, %rsi
movl $0x5c, %edx
callq 0x4670
movq 0x8(%r12), %rax
leaq 0x1(%rax), %rcx
cmpq 0x10(%r12), %rcx
jae 0xc29d
movq (%r12), %rdx
movq %rcx, 0x8(%r12)
movb %bpl, (%rdx,%rax)
movq (%r12), %rax
movq 0x8(%r12), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xc2c2
movq %r12, %rdi
movq $-0x1, %rsi
movl %r13d, %edx
callq 0x4670
jmp 0xc2c2
movq %r12, %rdi
leaq 0x4306(%rip), %rsi      # 0x105c1
xorl %eax, %eax
callq 0x4880
movb (%r15), %bpl
incq %r15
testb %bpl, %bpl
jne 0xc1d5
movq %r12, %rdi
xorl %esi, %esi
callq 0x43a0
movq %rax, %r15
leaq 0x427e(%rip), %rdi      # 0x10563
movq %r14, %rsi
movl 0x4(%rsp), %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4380
movq %rax, %r14
movq %r15, %rdi
callq 0x48e8
jmp 0xc326
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4267(%rip), %rdi      # 0x10580
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 0x9da4
cmpq %r15, %rax
je 0xc35a
callq 0x45b0
cmpl $0x20, (%rax)
jne 0xc370
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 0x7a50
nopl (%rax)