// File: establishment[P]sandman/src/rules.hpp
// Function: Rules::DirRules::applyRules()
void applyRules() {
            for (DirRule rule : allDirRules) {
                if (rule.localPath.size() == 0) {
                    Msg("Not binding anything on %s\n", rule.boxPath.c_str());
                    continue;
                }

                if ((rule.flags & FLAG_MAYBE) && !Base::DirExists(rule.localPath.c_str())) {
                    Msg("Not binding %s on %s (does not exist)\n", rule.localPath.c_str(), rule.boxPath.c_str());
                    continue;
                }

                char rootInBox[1024];
                snprintf(rootInBox, sizeof(rootInBox), "root/%s", rule.boxPath.c_str());
                Base::MakeDir(rootInBox);

                // convert rules from DIR_FLAGS_XXX to mount rule
                unsigned long mount_flags = 0;

                if (!(rule.flags & FLAG_RW)) {
                    mount_flags |= MS_RDONLY;
                }

                if (rule.flags & FLAG_NOEXEC) {
                    mount_flags |= MS_NOEXEC;
                }

                if (!(rule.flags & FLAG_DEV)) {
                    mount_flags |= MS_NODEV;
                }

                if (rule.flags & FLAG_FS) {
                    Msg("Mounting %s on %s (flags %lx)\n", rule.localPath.c_str(), rule.boxPath.c_str(), mount_flags);
                    if (mount("none", rootInBox, rule.localPath.c_str(), mount_flags, "") < 0) {
                        Die("Cannot mount %s on %s: %m", rule.localPath.c_str(), rule.boxPath.c_str());
                    }
                } else {
                    mount_flags |= MS_BIND | MS_NOSUID;
                    Msg("Binding %s on %s (flags %lx)\n", rule.localPath.c_str(), rule.boxPath.c_str(), mount_flags);
                    // Most mount flags need remount to work
                    if (mount(rule.localPath.c_str(), rootInBox, "none", mount_flags, "") < 0 ||
                        mount(rule.localPath.c_str(), rootInBox, "none", MS_REMOUNT | mount_flags, "") < 0) {
                        Die("Cannot mount %s on %s: %m", rule.localPath.c_str(), rule.boxPath.c_str());
                    }
                }
            }
        }

// Assembly:
subq $0x538, %rsp            # imm = 0x538
movq %rdi, 0x530(%rsp)
movq 0x530(%rsp), %rax
movq %rax, 0x528(%rsp)
movq 0x528(%rsp), %rdi
callq 0xae2b0
movq %rax, 0x520(%rsp)
movq 0x528(%rsp), %rdi
callq 0xae2e0
movq %rax, 0x518(%rsp)
leaq 0x520(%rsp), %rdi
leaq 0x518(%rsp), %rsi
callq 0xae310
testb $0x1, %al
jne 0xad247
jmp 0xad742
leaq 0x520(%rsp), %rdi
callq 0xae350
movq %rax, %rsi
leaq 0x4d0(%rsp), %rdi
callq 0xaeee0
leaq 0x4d0(%rsp), %rdi
addq $0x20, %rdi
callq 0x8c3f0
cmpq $0x0, %rax
jne 0xad2c4
leaq 0x4d0(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rsi
leaq 0x4900e(%rip), %rdi     # 0xf62a0
xorl %eax, %eax
callq 0x94e30
jmp 0xad29b
movl $0x3, 0x4c0(%rsp)
jmp 0xad703
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c8(%rsp)
movl %eax, 0x4c4(%rsp)
jmp 0xad733
movl 0x510(%rsp), %ecx
andl $0x8, %ecx
movb $0x0, 0x49e(%rsp)
movb $0x0, 0x49d(%rsp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x5f(%rsp)
je 0xad34f
leaq 0x4f0(%rsp), %rdi
callq 0x8c1f0
movq %rax, 0x48(%rsp)
leaq 0x49f(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x8ca50
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movb $0x1, 0x49e(%rsp)
leaq 0x4a0(%rsp), %rdi
callq 0xa0a90
jmp 0xad32e
movb $0x1, 0x49d(%rsp)
leaq 0x4a0(%rsp), %rdi
callq 0x94f30
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, 0x5f(%rsp)
movb 0x5f(%rsp), %al
movb %al, 0x47(%rsp)
testb $0x1, 0x49d(%rsp)
jne 0xad363
jmp 0xad370
leaq 0x4a0(%rsp), %rdi
callq 0x8cbd8
testb $0x1, 0x49e(%rsp)
jne 0xad37c
jmp 0xad389
leaq 0x49f(%rsp), %rdi
callq 0x8c630
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0xad393
jmp 0xad40c
leaq 0x4f0(%rsp), %rdi
callq 0x8c1f0
movq %rax, 0x38(%rsp)
leaq 0x4d0(%rsp), %rdi
callq 0x8c1f0
movq 0x38(%rsp), %rsi
movq %rax, %rdx
leaq 0x48efb(%rip), %rdi     # 0xf62bc
xorl %eax, %eax
callq 0x94e30
jmp 0xad3ca
movl $0x3, 0x4c0(%rsp)
jmp 0xad703
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c8(%rsp)
movl %eax, 0x4c4(%rsp)
testb $0x1, 0x49e(%rsp)
jne 0xad3fa
jmp 0xad407
leaq 0x49f(%rsp), %rdi
callq 0x8c630
jmp 0xad733
leaq 0x4d0(%rsp), %rdi
callq 0x8c1f0
movq %rax, %rcx
leaq 0x48ec0(%rip), %rdx     # 0xf62e3
xorl %eax, %eax
leaq 0x90(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movl $0x400, %esi            # imm = 0x400
callq 0x8c940
leaq 0x6f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x8ca50
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x70(%rsp), %rdi
callq 0xa0a90
jmp 0xad461
leaq 0x70(%rsp), %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x95000
jmp 0xad472
leaq 0x70(%rsp), %rdi
callq 0x8cbd8
leaq 0x6f(%rsp), %rdi
callq 0x8c630
movq $0x0, 0x60(%rsp)
movl 0x510(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xad4f1
movq 0x60(%rsp), %rax
orq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0xad4f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c8(%rsp)
movl %eax, 0x4c4(%rsp)
jmp 0xad4e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c8(%rsp)
movl %eax, 0x4c4(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x8cbd8
leaq 0x6f(%rsp), %rdi
callq 0x8c630
jmp 0xad733
movl 0x510(%rsp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xad50e
movq 0x60(%rsp), %rax
orq $0x8, %rax
movq %rax, 0x60(%rsp)
movl 0x510(%rsp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0xad52b
movq 0x60(%rsp), %rax
orq $0x4, %rax
movq %rax, 0x60(%rsp)
movl 0x510(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xad5fd
leaq 0x4f0(%rsp), %rdi
callq 0x8c1f0
movq %rax, 0x20(%rsp)
leaq 0x4d0(%rsp), %rdi
callq 0x8c1f0
movq 0x20(%rsp), %rsi
movq %rax, %rdx
movq 0x60(%rsp), %rcx
leaq 0x48d7a(%rip), %rdi     # 0xf62eb
xorl %eax, %eax
callq 0x94e30
jmp 0xad57a
leaq 0x90(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x4d0(%rsp), %rdi
addq $0x20, %rdi
callq 0x8c1f0
movq 0x18(%rsp), %rsi
movq %rax, %rdx
movq 0x60(%rsp), %rcx
leaq 0x48c39(%rip), %rdi     # 0xf61e5
leaq 0x47bf9(%rip), %r8      # 0xf51ac
callq 0x8cb20
cmpl $0x0, %eax
jge 0xad5f8
leaq 0x4f0(%rsp), %rdi
callq 0x8c1f0
movq %rax, 0x10(%rsp)
leaq 0x4d0(%rsp), %rdi
callq 0x8c1f0
movq 0x10(%rsp), %rsi
testq %rax, %rax
setne %al
movzbl %al, %edx
leaq 0x48d19(%rip), %rdi     # 0xf630a
callq 0x94580
jmp 0xad5f8
jmp 0xad6f8
movw 0x60(%rsp), %ax
orw $0x1002, %ax            # imm = 0x1002
movw %ax, 0x60(%rsp)
leaq 0x4f0(%rsp), %rdi
callq 0x8c1f0
movq %rax, 0x8(%rsp)
leaq 0x4d0(%rsp), %rdi
callq 0x8c1f0
movq 0x8(%rsp), %rsi
movq %rax, %rdx
movq 0x60(%rsp), %rcx
leaq 0x48ce6(%rip), %rdi     # 0xf6324
xorl %eax, %eax
callq 0x94e30
jmp 0xad647
leaq 0x4d0(%rsp), %rdi
addq $0x20, %rdi
callq 0x8c1f0
movq %rax, %rdi
leaq 0x90(%rsp), %rsi
movq 0x60(%rsp), %rcx
leaq 0x48b76(%rip), %rdx     # 0xf61e5
leaq 0x47b36(%rip), %r8      # 0xf51ac
callq 0x8cb20
cmpl $0x0, %eax
jl 0xad6bd
leaq 0x4d0(%rsp), %rdi
addq $0x20, %rdi
callq 0x8c1f0
movq %rax, %rdi
leaq 0x90(%rsp), %rsi
movq 0x60(%rsp), %rcx
orq $0x20, %rcx
leaq 0x48b39(%rip), %rdx     # 0xf61e5
leaq 0x47af9(%rip), %r8      # 0xf51ac
callq 0x8cb20
cmpl $0x0, %eax
jge 0xad6f6
leaq 0x4f0(%rsp), %rdi
callq 0x8c1f0
movq %rax, (%rsp)
leaq 0x4d0(%rsp), %rdi
callq 0x8c1f0
movq (%rsp), %rsi
testq %rax, %rax
setne %al
movzbl %al, %edx
leaq 0x48c1b(%rip), %rdi     # 0xf630a
callq 0x94580
jmp 0xad6f6
jmp 0xad6f8
movl $0x0, 0x4c0(%rsp)
leaq 0x4d0(%rsp), %rdi
callq 0xae3b0
movl 0x4c0(%rsp), %eax
testl %eax, %eax
je 0xad71f
jmp 0xad71d
jmp 0xad721
jmp 0xad721
leaq 0x520(%rsp), %rdi
callq 0xae360
jmp 0xad229
leaq 0x4d0(%rsp), %rdi
callq 0xae3b0
jmp 0xad74a
addq $0x538, %rsp            # imm = 0x538
retq
movq 0x4c8(%rsp), %rdi
callq 0x8ca40
nopw (%rax,%rax)