// File: establishment[P]sandman/src/cgroups.hpp
// Function: CGroups::writeStat(CGroups::CGSubsystem, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool)
int writeStat(CGSubsystem subsystem, const std::string& parameter, const std::string& value, bool maybe=false) {
        int success = 0;
        ssize_t writeSize = 0;

        Base::Msg(2, "CG: Write %s = %s\n", parameter.c_str(), value.c_str());

        std::string path = getPath(subsystem, parameter);

        /// check file descriptor
        int fd = open(path.c_str(), O_WRONLY | O_TRUNC);
        if (fd < 0) {
            if (maybe) {
                goto fail;
            } else {
                Base::Die("Cannot write %s: %m", path.c_str());
            }
        }

        /// write and sanity check
        writeSize = write(fd, value.c_str(), value.size());
        if (writeSize < 0) {
            if (maybe) {
                goto fail_close;
            } else {
                Base::Die("Cannot set %s to %s: %m", path.c_str(), value.c_str());
            }
        }

        if (writeSize != (ssize_t)value.size()) {
            Base::Die("Short write to %s (%zd out of %zu bytes) err:%m", path.c_str(), writeSize, value.size());
        }

        success = 1;
        fail_close:
        if (success == 0) {
            Base::Msg(2, "Failed to write %s=%s\n", path.c_str(), value.c_str());
        }
        close(fd);
        fail:

        return success;
    }

// Assembly:
subq $0xf8, %rsp
movq %rsi, 0x58(%rsp)
movb %r8b, %al
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
movq %rcx, 0xd8(%rsp)
andb $0x1, %al
movb %al, 0xd7(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x60(%rsp)
movl $0x0, 0xd0(%rsp)
movq $0x0, 0xc8(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x8c1f0
movq %rax, 0x50(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x8c1f0
movq 0x50(%rsp), %rdx
movq %rax, %rcx
leaq 0x49479(%rip), %rsi     # 0xf6143
xorl %eax, %eax
movl $0x2, %edi
callq 0x94d30
movq 0x58(%rsp), %rsi
leaq 0x80(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0xa2a40
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0xe0(%rsp), %rcx
leaq 0xa8(%rsp), %rdi
callq 0xaac50
jmp 0xacd0e
leaq 0x80(%rsp), %rdi
callq 0xa2a30
leaq 0xa8(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rdi
xorl %eax, %eax
movl $0x201, %esi            # imm = 0x201
callq 0x8c430
movl %eax, 0x4c(%rsp)
jmp 0xacd3d
movl 0x4c(%rsp), %eax
movl %eax, 0x70(%rsp)
cmpl $0x0, 0x70(%rsp)
jge 0xacdbb
testb $0x1, 0xd7(%rsp)
je 0xacd9b
jmp 0xacf2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xa2a30
jmp 0xacf50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x8cbd8
jmp 0xacf50
leaq 0xa8(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rsi
leaq 0x493a4(%rip), %rdi     # 0xf6156
xorl %eax, %eax
callq 0x94bf0
jmp 0xacdbb
movl 0x70(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x8c1f0
movq %rax, 0x38(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x8c3f0
movl 0x34(%rsp), %edi
movq 0x38(%rsp), %rsi
movq %rax, %rdx
callq 0x8c180
movq %rax, 0x40(%rsp)
jmp 0xacdfa
movq 0x40(%rsp), %rax
movq %rax, 0xc8(%rsp)
cmpq $0x0, 0xc8(%rsp)
jge 0xace5c
testb $0x1, 0xd7(%rsp)
je 0xace21
jmp 0xaced7
leaq 0xa8(%rsp), %rdi
callq 0x8c1f0
movq %rax, 0x28(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x8c1f0
movq 0x28(%rsp), %rsi
testq %rax, %rax
setne %al
movzbl %al, %edx
leaq 0x49315(%rip), %rdi     # 0xf616a
callq 0x94580
jmp 0xace5c
movq 0xc8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x8c3f0
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
je 0xacecc
leaq 0xa8(%rsp), %rdi
callq 0x8c1f0
movq %rax, 0x10(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x8c3f0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
leaq 0x492bf(%rip), %rdi     # 0xf6182
xorl %eax, %eax
callq 0x94bf0
jmp 0xacecc
movl $0x1, 0xd0(%rsp)
cmpl $0x0, 0xd0(%rsp)
jne 0xacf1f
leaq 0xa8(%rsp), %rdi
callq 0x8c1f0
movq %rax, 0x8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x8c1f0
movq 0x8(%rsp), %rdx
movq %rax, %rcx
leaq 0x492a3(%rip), %rsi     # 0xf61b2
xorl %eax, %eax
movl $0x2, %edi
callq 0x94d30
jmp 0xacf1d
jmp 0xacf1f
movl 0x70(%rsp), %edi
callq 0x8cb80
jmp 0xacf2a
jmp 0xacf2c
movl 0xd0(%rsp), %eax
movl %eax, 0x4(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x8cbd8
movl 0x4(%rsp), %eax
addq $0xf8, %rsp
retq
movq 0x78(%rsp), %rdi
callq 0x8ca40
nopw (%rax,%rax)