// File: establishment[P]sandman/src/cgroups.hpp
// Function: CGroups::prepare()
void prepare() {
        Base::Msg("Preparing control group %s\n", cgName.c_str());
        for (auto subsystem : cgAllSubSystems) {
            struct stat st;
            std::string path = getPath(subsystem, "");
            if (stat(path.c_str(), &st) >= 0 || errno != ENOENT) {
                Base::Msg("Control group %s already exists, trying to empty it.\n", path.c_str());
                if (rmdir(path.c_str()) < 0) {
                    Base::Die("Failed to reset control group %s: %m", path.c_str());
                }
            }

            if (mkdir(path.c_str(), 0777) < 0 && !subsystem.optional) {
                Base::Die("Failed to create control group %s: %m", path.c_str());
            }
        }

        /// If cpuset module is enabled, copy allowed cpus and memory nodes from parent group
        /// limits the cpus which can be used by target process
        /// usefull in a multi cored environment
        if (readStat(cgCpuset, "cpuset.cpus", true)) { /// try to read
            writeStat(cgCpuset, "cpuset.cpus", buffer); /// write what was just read
        }

        /// sets RAM nodes which this program can use
        /// can be specified to be the first 2 GB of ram for example
        if (readStat(cgCpuset, "cpuset.mems", true)) { /// try to read
            writeStat(cgCpuset, "cpuset.mems", buffer); /// write what was just read
        }
    }

// Assembly:
subq $0x358, %rsp            # imm = 0x358
movq %rdi, 0x350(%rsp)
movq 0x350(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x8c1f0
movq %rax, %rsi
leaq 0x2e4c2(%rip), %rdi     # 0xf66ed
movb $0x0, %al
callq 0x94e30
leaq 0x56937(%rip), %rax     # 0x11eb70
movq %rax, 0x348(%rsp)
leaq 0x56928(%rip), %rax     # 0x11eb70
movq %rax, 0x340(%rsp)
leaq 0x56919(%rip), %rax     # 0x11eb70
addq $0x78, %rax
movq %rax, 0x338(%rsp)
movq 0x340(%rsp), %rax
cmpq 0x338(%rsp), %rax
je 0xc84cf
movq 0x340(%rsp), %rsi
leaq 0x310(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0xa2a40
movq 0x60(%rsp), %rsi
leaq 0x238(%rsp), %rdi
callq 0xa2a40
jmp 0xc82a7
leaq 0x207(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x8ca50
movq 0x58(%rsp), %rdx
leaq 0x2cee7(%rip), %rsi     # 0xf51ac
leaq 0x208(%rsp), %rdi
callq 0xa0a90
jmp 0xc82d4
movq 0x68(%rsp), %rsi
leaq 0x260(%rsp), %rdi
leaq 0x238(%rsp), %rdx
leaq 0x208(%rsp), %rcx
callq 0xaac50
jmp 0xc82f8
leaq 0x208(%rsp), %rdi
callq 0x8cbd8
leaq 0x207(%rsp), %rdi
callq 0x8c630
leaq 0x238(%rsp), %rdi
callq 0xa2a30
leaq 0x260(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rdi
leaq 0x280(%rsp), %rsi
callq 0x8c500
cmpl $0x0, %eax
jge 0xc834f
callq 0x8c070
cmpl $0x2, (%rax)
je 0xc8441
leaq 0x260(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rsi
leaq 0x2e3a3(%rip), %rdi     # 0xf6709
xorl %eax, %eax
callq 0x94e30
jmp 0xc836f
leaq 0x260(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rdi
callq 0x8c200
cmpl $0x0, %eax
jge 0xc843f
leaq 0x260(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rsi
leaq 0x2e39b(%rip), %rdi     # 0xf673f
xorl %eax, %eax
callq 0x94bf0
jmp 0xc83ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
jmp 0xc84bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
jmp 0xc83fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
leaq 0x208(%rsp), %rdi
callq 0x8cbd8
leaq 0x207(%rsp), %rdi
callq 0x8c630
leaq 0x238(%rsp), %rdi
callq 0xa2a30
jmp 0xc84bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
leaq 0x260(%rsp), %rdi
callq 0x8cbd8
jmp 0xc84bd
jmp 0xc8441
leaq 0x260(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x8c260
cmpl $0x0, %eax
jge 0xc848a
testb $0x1, 0x330(%rsp)
jne 0xc848a
leaq 0x260(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rsi
leaq 0x2e2e3(%rip), %rdi     # 0xf6764
xorl %eax, %eax
callq 0x94bf0
jmp 0xc848a
leaq 0x260(%rsp), %rdi
callq 0x8cbd8
leaq 0x310(%rsp), %rdi
callq 0xa2a30
movq 0x340(%rsp), %rax
addq $0x28, %rax
movq %rax, 0x340(%rsp)
jmp 0xc8263
leaq 0x310(%rsp), %rdi
callq 0xa2a30
jmp 0xc8979
leaq 0x56672(%rip), %rsi     # 0x11eb48
leaq 0x1d8(%rsp), %rdi
callq 0xa2a40
leaq 0x1b7(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x8ca50
movq 0x50(%rsp), %rdx
leaq 0x2e289(%rip), %rsi     # 0xf678a
leaq 0x1b8(%rsp), %rdi
callq 0xa0a90
jmp 0xc8510
movq 0x68(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
leaq 0x1b8(%rsp), %rdx
movl $0x1, %ecx
callq 0xaa9c0
movl %eax, 0x4c(%rsp)
jmp 0xc8535
leaq 0x1b8(%rsp), %rdi
callq 0x8cbd8
leaq 0x1b7(%rsp), %rdi
callq 0x8c630
leaq 0x1d8(%rsp), %rdi
callq 0xa2a30
movl 0x4c(%rsp), %eax
cmpl $0x0, %eax
je 0xc872c
leaq 0x565d8(%rip), %rsi     # 0x11eb48
leaq 0x188(%rsp), %rdi
callq 0xa2a40
leaq 0x167(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x8ca50
movq 0x40(%rsp), %rdx
leaq 0x2e1ef(%rip), %rsi     # 0xf678a
leaq 0x168(%rsp), %rdi
callq 0xa0a90
jmp 0xc85aa
movq 0x68(%rsp), %rax
addq $0x28, %rax
movq %rax, 0x30(%rsp)
leaq 0x13f(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x8ca50
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0x140(%rsp), %rdi
callq 0xa0a90
jmp 0xc85e3
movq 0x68(%rsp), %rdi
leaq 0x188(%rsp), %rsi
leaq 0x168(%rsp), %rdx
leaq 0x140(%rsp), %rcx
xorl %r8d, %r8d
callq 0xacc40
jmp 0xc860a
leaq 0x140(%rsp), %rdi
callq 0x8cbd8
leaq 0x13f(%rsp), %rdi
callq 0x8c630
leaq 0x168(%rsp), %rdi
callq 0x8cbd8
leaq 0x167(%rsp), %rdi
callq 0x8c630
leaq 0x188(%rsp), %rdi
callq 0xa2a30
jmp 0xc872c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
jmp 0xc8687
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x8cbd8
leaq 0x1b7(%rsp), %rdi
callq 0x8c630
leaq 0x1d8(%rsp), %rdi
callq 0xa2a30
jmp 0xc8979
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
jmp 0xc870d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
jmp 0xc86f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x8cbd8
leaq 0x13f(%rsp), %rdi
callq 0x8c630
leaq 0x168(%rsp), %rdi
callq 0x8cbd8
leaq 0x167(%rsp), %rdi
callq 0x8c630
leaq 0x188(%rsp), %rdi
callq 0xa2a30
jmp 0xc8979
leaq 0x56415(%rip), %rsi     # 0x11eb48
leaq 0x110(%rsp), %rdi
callq 0xa2a40
leaq 0xef(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x8ca50
movq 0x28(%rsp), %rdx
leaq 0x2e038(%rip), %rsi     # 0xf6796
leaq 0xf0(%rsp), %rdi
callq 0xa0a90
jmp 0xc876d
movq 0x68(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
movl $0x1, %ecx
callq 0xaa9c0
movl %eax, 0x24(%rsp)
jmp 0xc8792
leaq 0xf0(%rsp), %rdi
callq 0x8cbd8
leaq 0xef(%rsp), %rdi
callq 0x8c630
leaq 0x110(%rsp), %rdi
callq 0xa2a30
movl 0x24(%rsp), %eax
cmpl $0x0, %eax
je 0xc8971
leaq 0x5637b(%rip), %rsi     # 0x11eb48
leaq 0xc0(%rsp), %rdi
callq 0xa2a40
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x8ca50
movq 0x18(%rsp), %rdx
leaq 0x2df9e(%rip), %rsi     # 0xf6796
leaq 0xa0(%rsp), %rdi
callq 0xa0a90
jmp 0xc8807
movq 0x68(%rsp), %rax
addq $0x28, %rax
movq %rax, 0x8(%rsp)
leaq 0x77(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x8ca50
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x78(%rsp), %rdi
callq 0xa0a90
jmp 0xc883a
movq 0x68(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
leaq 0x78(%rsp), %rcx
xorl %r8d, %r8d
callq 0xacc40
jmp 0xc885e
leaq 0x78(%rsp), %rdi
callq 0x8cbd8
leaq 0x77(%rsp), %rdi
callq 0x8c630
leaq 0xa0(%rsp), %rdi
callq 0x8cbd8
leaq 0x9f(%rsp), %rdi
callq 0x8c630
leaq 0xc0(%rsp), %rdi
callq 0xa2a30
jmp 0xc8971
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
jmp 0xc88d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x8cbd8
leaq 0xef(%rsp), %rdi
callq 0x8c630
leaq 0x110(%rsp), %rdi
callq 0xa2a30
jmp 0xc8979
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
jmp 0xc8955
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
jmp 0xc893e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x230(%rsp)
movl %eax, 0x22c(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x8cbd8
leaq 0x77(%rsp), %rdi
callq 0x8c630
leaq 0xa0(%rsp), %rdi
callq 0x8cbd8
leaq 0x9f(%rsp), %rdi
callq 0x8c630
leaq 0xc0(%rsp), %rdi
callq 0xa2a30
jmp 0xc8979
addq $0x358, %rsp            # imm = 0x358
retq
movq 0x230(%rsp), %rdi
callq 0x8ca40
nopw %cs:(%rax,%rax)