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

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

        int fd = open(path.c_str(), O_RDONLY);
        if (fd < 0) {
            if (maybe) {
                goto fail;
            }
            Base::Die("Cannot read %s: %m", path.c_str());
        }

        readSize = read(fd, buffer, kCGBufferSize);

        /// check read
        if (readSize < 0) {
            if (maybe) {
                goto fail_close;
            }
            Base::Die("Cannot read %s: %m", path.c_str());
        }

        if (readSize >= kCGBufferSize - 1) {
            Base::Die("Attribute %s too long", path.c_str());
        }

        /// erase \n from answer
        if (readSize > 0 && buffer[readSize - 1] == '\n') {
            readSize -= 1;
        }

        /// set end of read
        buffer[readSize] = 0;

        Base::Msg(2, "CG: Read '%s' = '%s'\n", parameter.c_str(), buffer);

        success = 1;

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

// Assembly:
subq $0xb8, %rsp
movb %cl, %al
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
andb $0x1, %al
movb %al, 0x9f(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x98(%rsp)
movl $0x0, 0x94(%rsp)
leaq 0x48(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xa2a40
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0xa0(%rsp), %rcx
leaq 0x70(%rsp), %rdi
callq 0xaac50
jmp 0xaaa3a
leaq 0x48(%rsp), %rdi
callq 0xa2a30
leaq 0x70(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rdi
xorl %esi, %esi
movb %sil, %al
callq 0x8c430
movl %eax, 0x24(%rsp)
jmp 0xaaa61
movl 0x24(%rsp), %eax
movl %eax, 0x38(%rsp)
cmpl $0x0, 0x38(%rsp)
jge 0xaaad6
testb $0x1, 0x9f(%rsp)
je 0xaaab9
jmp 0xaac25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0xa2a30
jmp 0xaac46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x8cbd8
jmp 0xaac46
leaq 0x70(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rsi
leaq 0x4b511(%rip), %rdi     # 0xf5fde
xorl %eax, %eax
callq 0x94bf0
jmp 0xaaad6
movq 0x28(%rsp), %rsi
movl 0x38(%rsp), %edi
addq $0x28, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x8c890
movq %rax, 0x18(%rsp)
jmp 0xaaaf4
movq 0x18(%rsp), %rax
movl %eax, 0x94(%rsp)
cmpl $0x0, 0x94(%rsp)
jge 0xaab36
testb $0x1, 0x9f(%rsp)
je 0xaab19
jmp 0xaabea
leaq 0x70(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rsi
leaq 0x4b4b1(%rip), %rdi     # 0xf5fde
xorl %eax, %eax
callq 0x94bf0
jmp 0xaab36
cmpl $0xfff, 0x94(%rsp) # imm = 0xFFF
jl 0xaab60
leaq 0x70(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rsi
leaq 0x4b49a(%rip), %rdi     # 0xf5ff1
xorl %eax, %eax
callq 0x94bf0
jmp 0xaab60
cmpl $0x0, 0x94(%rsp)
jle 0xaab97
movq 0x28(%rsp), %rax
movl 0x94(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl 0x28(%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0xaab97
movl 0x94(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x94(%rsp)
movq 0x28(%rsp), %rax
movq %rax, %rcx
addq $0x28, %rcx
movq %rcx, 0x10(%rsp)
movslq 0x94(%rsp), %rcx
movb $0x0, 0x28(%rax,%rcx)
movq 0xa0(%rsp), %rdi
callq 0x8c1f0
movq 0x10(%rsp), %rcx
movq %rax, %rdx
leaq 0x4b436(%rip), %rsi     # 0xf6007
xorl %eax, %eax
movl $0x2, %edi
callq 0x94d30
jmp 0xaabdf
movl $0x1, 0x98(%rsp)
cmpl $0x0, 0x98(%rsp)
jne 0xaac18
leaq 0x70(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rdx
leaq 0x4b415(%rip), %rsi     # 0xf601d
xorl %eax, %eax
movl $0x2, %edi
callq 0x94d30
jmp 0xaac16
jmp 0xaac18
movl 0x38(%rsp), %edi
callq 0x8cb80
jmp 0xaac23
jmp 0xaac25
movl 0x98(%rsp), %eax
movl %eax, 0xc(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x8cbd8
movl 0xc(%rsp), %eax
addq $0xb8, %rsp
retq
movq 0x40(%rsp), %rdi
callq 0x8ca40