// File: tsoding[P]cxx-invert-file-tree/inverter.cpp
// Function: invert_folder(std::filesystem::__cxx11::path const&)
void invert_folder(const fs::path &root)
{
    std::vector<fs::path> children;
    for (auto &child : fs::directory_iterator(root)) {
        children.push_back(child);
    }
    std::sort(children.begin(), children.end());

    for (const auto &child: children) {
        if (fs::is_directory(child)) {
            invert_folder(child);
        }
    }

    const fs::path tmp = free_file_name(root);

    for (size_t i = 0; i < children.size() / 2; ++i) {
        const auto a = children[i];
        const auto b = children[children.size() - i - 1];
        std::cout << a << " <-> " << b << std::endl;
        fs::rename(a, tmp);
        fs::rename(b, a);
        fs::rename(tmp, b);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x40c0
movq -0x8(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x40e0
jmp 0x3897
leaq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x4140
leaq -0x58(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x4110
leaq -0x68(%rbp), %rdi
callq 0x4170
movq -0x28(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x4140
leaq -0x78(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x4190
leaq -0x88(%rbp), %rdi
callq 0x4170
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x41d0
testb $0x1, %al
jne 0x392d
leaq -0x78(%rbp), %rdi
callq 0x4170
leaq -0x58(%rbp), %rdi
callq 0x4170
leaq -0x38(%rbp), %rdi
callq 0x4170
jmp 0x3992
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3c56
leaq -0x58(%rbp), %rdi
callq 0x33e0
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
callq 0x4270
movq %rax, %rsi
leaq -0x20(%rbp), %rdi
callq 0x4200
jmp 0x3957
jmp 0x3959
leaq -0x58(%rbp), %rdi
callq 0x30a0
jmp 0x3964
jmp 0x38ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x4170
leaq -0x58(%rbp), %rdi
callq 0x4170
leaq -0x38(%rbp), %rdi
callq 0x4170
jmp 0x3c56
leaq -0x20(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x42c0
movq -0x148(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x42f0
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x4280
jmp 0x39d1
leaq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x42c0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x42f0
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x4320
testb $0x1, %al
jne 0x3a1b
jmp 0x3a6e
leaq -0xb0(%rbp), %rdi
callq 0x4360
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x4380
movb %al, -0x149(%rbp)
jmp 0x3a42
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x3a4e
jmp 0x3a5e
movq -0xc0(%rbp), %rdi
callq 0x3870
jmp 0x3a5c
jmp 0x3a5e
jmp 0x3a60
leaq -0xb0(%rbp), %rdi
callq 0x43b0
jmp 0x3a02
movq -0x8(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x35b0
jmp 0x3a80
movq $0x0, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x43d0
movq %rax, %rcx
movq -0x158(%rbp), %rax
shrq %rcx
cmpq %rcx, %rax
jae 0x3c2c
movq -0xf0(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x4400
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x4420
jmp 0x3ad9
leaq -0x20(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x43d0
movq -0x160(%rbp), %rdi
movq -0xf0(%rbp), %rsi
notq %rsi
addq %rax, %rsi
callq 0x4400
movq %rax, %rsi
leaq -0x140(%rbp), %rdi
callq 0x4420
jmp 0x3b13
movq 0x84b6(%rip), %rdi      # 0xbfd0
leaq -0x118(%rbp), %rsi
callq 0x4480
movq %rax, -0x168(%rbp)
jmp 0x3b2f
movq -0x168(%rbp), %rdi
leaq 0x44e9(%rip), %rsi      # 0x8026
callq 0x3250
movq %rax, -0x170(%rbp)
jmp 0x3b4b
movq -0x170(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x4480
movq %rax, -0x178(%rbp)
jmp 0x3b67
movq -0x178(%rbp), %rdi
movq 0x8443(%rip), %rsi      # 0xbfb8
callq 0x3290
jmp 0x3b7c
leaq -0x118(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x3190
jmp 0x3b91
leaq -0x140(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x3190
jmp 0x3ba6
leaq -0xe8(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x3190
jmp 0x3bbb
leaq -0x140(%rbp), %rdi
callq 0x4090
leaq -0x118(%rbp), %rdi
callq 0x4090
movq -0xf0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xf0(%rbp)
jmp 0x3a8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3c4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3c1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x4090
leaq -0x118(%rbp), %rdi
callq 0x4090
jmp 0x3c4a
leaq -0xe8(%rbp), %rdi
callq 0x4090
leaq -0x20(%rbp), %rdi
callq 0x4570
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0xe8(%rbp), %rdi
callq 0x4090
leaq -0x20(%rbp), %rdi
callq 0x4570
movq -0x40(%rbp), %rdi
callq 0x33b0
nopl (%rax,%rax)