// File: /workspace/github_cpp_makefile_star2_O2/establishment[P]sandman/src/lib.hpp
// Function: Jailer::Run()
void Run() {
        Msg("Start running\n");

        if (!Base::DirExists("box")) {
            Die("Box directory not found, did you run 'isolate --init'?");
        }

        cg.prepare();  /// creates cgroup if it's not created

        /// This code will live here. Life is hard.
        /// setup pipes
        int errorPipes[2];
        if (pipe(errorPipes) < 0)
            Die("pipe: %m");

        /// close errorPipes when clone ends
        for (int i = 0; i < 2; i++)
            if (fcntl(errorPipes[i], F_SETFD, fcntl(errorPipes[i], F_GETFD) | FD_CLOEXEC) < 0 ||
                fcntl(errorPipes[i], F_SETFL, fcntl(errorPipes[i], F_GETFL) | O_NONBLOCK) < 0)
                Die("fcntl on pipe: %m");

        /// sanity check
        if (isolatedProcessStack == nullptr) {
            Die("Must provide a pointer to stack if the jailer is used as a library.");
        }

        int processPid =
            clone(ProcessInitialiser::ASyncStart,  /// Function to execute as the body of the new process
                  isolatedProcessStack,            /// stack for the new process (argv is the start of stack)
                  SIGCHLD | CLONE_NEWIPC | (config.shareNetwork ? 0 : CLONE_NEWNET) | CLONE_NEWNS | CLONE_NEWPID,
                  new ProcessInitialiser(config, uid, gid, errorPipes));  /// pass config for initialiser

        if (processPid < 0) {
            Die("clone: %m");
        }

        if (!processPid) {
            Die("clone returned 0");
        }

        Msg("Start waiting for process\n");

        ProcessKeeper keeper(config, processPid, errorPipes);
        RunStats finalStats = keeper.startKeeper();
        PrintStats(finalStats);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x588, %rsp            # imm = 0x588
movq %rdi, %rbx
leaq 0xf02e(%rip), %rdi      # 0x5c8b9
xorl %eax, %eax
callq 0x3b443
leaq 0xe96b(%rip), %rsi      # 0x5c204
leaq 0x200(%rsp), %r14
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x40b24
movq %r14, %rdi
callq 0x3b4ff
movl %eax, %ebp
movq %r14, %rdi
callq 0x37958
testl %ebp, %ebp
je 0x4da8e
movq %rbx, 0x8(%rsp)
leaq 0x271f4(%rip), %rdi     # 0x74ac8
callq 0x4dbee
movq %rsp, %rdi
callq 0x37640
testl %eax, %eax
js 0x4da9a
pushq $0x1
popq %rbp
pushq $0x2
popq %r14
pushq $0x3
popq %r15
pushq $0x4
popq %r12
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0x4d960
movl (%rsp,%rbx,4), %r13d
movl %r13d, %edi
movl %ebp, %esi
xorl %eax, %eax
callq 0x37280
orl $0x1, %eax
movl %r13d, %edi
movl %r14d, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x37280
testl %eax, %eax
js 0x4d952
movl (%rsp,%rbx,4), %r13d
movl %r13d, %edi
movl %r15d, %esi
xorl %eax, %eax
callq 0x37280
orl $0x800, %eax            # imm = 0x800
movl %r13d, %edi
movl %r12d, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x37280
incq %rbx
testl %eax, %eax
jns 0x4d8fa
leaq 0xefa6(%rip), %rdi      # 0x5c8ff
xorl %eax, %eax
callq 0x3b2a4
movq 0x8(%rsp), %r12
movq 0x168(%r12), %r15
testq %r15, %r15
je 0x4daa6
xorl %ebp, %ebp
cmpl $0x0, 0xe0(%r12)
sete %bl
movl $0x178, %edi            # imm = 0x178
callq 0x37460
movq %rax, %r14
leaq 0x98(%rsp), %rdi
movq %r12, %rsi
callq 0x4d2a2
movl 0x190(%r12), %edx
movl 0x194(%r12), %ecx
leaq 0x98(%rsp), %rsi
movq %rsp, %r8
movq %r14, %rdi
callq 0x4e31e
movb %bl, %bpl
shll $0x1e, %ebp
orl $0x28020011, %ebp       # imm = 0x28020011
leaq -0x116c9(%rip), %rdi    # 0x3c30e
movq %r15, %rsi
movl %ebp, %edx
movq %r14, %rcx
xorl %eax, %eax
callq 0x37870
movl %eax, %ebp
leaq 0x98(%rsp), %rdi
callq 0x42d14
testl %ebp, %ebp
js 0x4dab2
je 0x4dabe
leaq 0xef66(%rip), %rdi      # 0x5c970
xorl %eax, %eax
callq 0x3b443
leaq 0x420(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x4d2a2
leaq 0x200(%rsp), %rdi
movq %rsp, %rcx
movq %r14, %rsi
movl %ebp, %edx
callq 0x3c1b6
leaq 0x420(%rsp), %rdi
callq 0x42d14
leaq 0x10(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x4e380
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x4e582
leaq 0x78(%rsp), %rdi
callq 0x37958
leaq 0x200(%rsp), %rdi
callq 0x4e606
addq $0x588, %rsp            # imm = 0x588
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xee33(%rip), %rdi      # 0x5c8c8
jmp 0x4d959
leaq 0xee67(%rip), %rdi      # 0x5c908
jmp 0x4d959
leaq 0xee64(%rip), %rdi      # 0x5c911
jmp 0x4d959
leaq 0xee9c(%rip), %rdi      # 0x5c955
jmp 0x4d959
leaq 0xee9a(%rip), %rdi      # 0x5c95f
jmp 0x4d959
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x37958
jmp 0x4dadc
movq %rax, %rbx
leaq 0x200(%rsp), %rdi
callq 0x4e606
jmp 0x4db1f
movq %rax, %rbx
leaq 0x420(%rsp), %rdi
callq 0x42d14
jmp 0x4db1f
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x42d14
jmp 0x4db12
movq %rax, %rbx
movl $0x178, %esi            # imm = 0x178
movq %r14, %rdi
callq 0x37470
movq %rbx, %rdi
callq 0x377f0
nop