// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x2a22
leaq 0x70(%rsp), %rdi
leaq 0x18(%rsp), %r15
movq %r15, %rsi
callq 0x2c48
leaq 0x48(%rsp), %r14
leaq 0x78(%rsp), %rdi
movaps -0x8(%rdi), %xmm0
movaps %xmm0, -0x8(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%rdi)
callq 0x2c7c
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x2c48
leaq 0x98(%rsp), %r15
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r15)
leaq 0x88(%rsp), %rdi
callq 0x2c7c
leaq 0x40(%rsp), %r12
movq %rsp, %r13
movq 0x48(%rsp), %rax
cmpq 0x98(%rsp), %rax
je 0x268c
movq %r12, %rdi
callq 0x22a0
movq %r13, %rdi
movq %rax, %rsi
callq 0x2a2c
movq %r12, %rdi
callq 0x2080
jmp 0x2660
movq %r15, %rdi
callq 0x2c7c
movq %r14, %rdi
callq 0x2c7c
leaq 0x20(%rsp), %rdi
callq 0x2c7c
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3033
movq (%rsp), %r14
movq 0x8(%rsp), %r15
cmpq %r15, %r14
je 0x26dc
movq %r14, %rdi
callq 0x2a58
testb %al, %al
je 0x26d6
movq %r14, %rdi
callq 0x25cc
addq $0x28, %r14
jmp 0x26bd
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x2402
pushq $-0x28
popq %rbp
xorl %r15d, %r15d
leaq 0x40(%rsp), %rbx
leaq 0x90(%rsp), %r14
leaq 0x18(%rsp), %r13
xorl %r12d, %r12d
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
subq %rsi, %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
shrq %rax
cmpq %rax, %r12
jae 0x27b1
addq %r15, %rsi
movq %rbx, %rdi
callq 0x2a66
movq 0x8(%rsp), %rsi
addq %rbp, %rsi
movq %r14, %rdi
callq 0x2a66
movq 0x488a(%rip), %rdi      # 0x6fd0
movq %rbx, %rsi
callq 0x2aa0
movq %rax, %rdi
leaq 0x18ea(%rip), %rsi      # 0x4042
callq 0x21a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x2aa0
movq %rax, %rdi
callq 0x20e0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2110
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2110
movq %r13, %rdi
movq %r14, %rsi
callq 0x2110
movq %r14, %rdi
callq 0x2a0c
movq %rbx, %rdi
callq 0x2a0c
incq %r12
addq $0x28, %r15
addq $-0x28, %rbp
jmp 0x2704
leaq 0x18(%rsp), %rdi
callq 0x2a0c
movq %rsp, %rdi
callq 0x2afc
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2806
jmp 0x2806
jmp 0x2806
movq %rax, %rbx
jmp 0x2825
movq %rax, %rbx
jmp 0x281b
jmp 0x27e7
movq %rax, %rbx
movq %r15, %rdi
callq 0x2c7c
movq %r14, %rdi
callq 0x2c7c
leaq 0x20(%rsp), %rdi
callq 0x2c7c
jmp 0x282f
movq %rax, %rbx
jmp 0x282f
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x2a0c
leaq 0x40(%rsp), %rdi
callq 0x2a0c
leaq 0x18(%rsp), %rdi
callq 0x2a0c
movq %rsp, %rdi
callq 0x2afc
movq %rbx, %rdi
callq 0x2280