// File: /workspace/github_cpp_makefile_star2_O1/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 $0x98, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2100
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
testq %rcx, %rcx
je 0x2c35
movq 0x33a1(%rip), %rdx      # 0x5fc8
cmpb $0x0, (%rdx)
je 0x2c31
incl 0x8(%rcx)
jmp 0x2c35
lock
incl 0x8(%rcx)
movq %rax, 0x48(%rsp)
movq %rcx, 0x50(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2c68
movq 0x3378(%rip), %rax      # 0x5fc8
cmpb $0x0, (%rax)
je 0x2c5a
incl 0x8(%rdi)
jmp 0x2c5e
lock
incl 0x8(%rdi)
testq %rdi, %rdi
je 0x2c68
callq 0x32de
leaq 0x48(%rsp), %r14
movq %rsp, %r15
cmpq $0x0, 0x50(%rsp)
je 0x2c95
movq %r14, %rdi
callq 0x2280
movq %r15, %rdi
movq %rax, %rsi
callq 0x3094
movq %r14, %rdi
callq 0x2090
jmp 0x2c70
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x2ca4
callq 0x32de
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2cb3
callq 0x32de
movq (%rsp), %r14
movq 0x8(%rsp), %r15
cmpq %r15, %r14
je 0x2cfc
movq %r15, %rax
subq %r14, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x36ba
movq %r14, %rdi
movq %r15, %rsi
callq 0x3797
movq (%rsp), %r14
movq 0x8(%rsp), %r15
cmpq %r15, %r14
je 0x2d24
movq %r14, %rdi
callq 0x20b0
cmpb $0x2, %al
jne 0x2d1e
movq %r14, %rdi
callq 0x2bdc
addq $0x28, %r14
jmp 0x2d05
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x27d9
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
subq %rsi, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
cmpq $0x2, %rax
jb 0x2e50
movq $-0x28, %r15
xorl %r12d, %r12d
leaq 0x48(%rsp), %rbx
leaq 0x70(%rsp), %r14
xorl %r13d, %r13d
addq %r12, %rsi
movq %rbx, %rdi
callq 0x30c0
movq 0x8(%rsp), %rsi
addq %r15, %rsi
movq %r14, %rdi
callq 0x30c0
movq 0x323e(%rip), %rdi      # 0x5fd0
movq %rbx, %rsi
callq 0x3115
movq %rax, %rbp
movl $0x5, %edx
movq %rax, %rdi
leaq 0x127a(%rip), %rsi      # 0x4026
callq 0x21e0
movq %rbp, %rdi
movq %r14, %rsi
callq 0x3115
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
callq 0x2110
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2110
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x2110
movq %r14, %rdi
callq 0x305c
movq %rbx, %rdi
callq 0x305c
incq %r13
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
subq %rsi, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
shrq %rax
addq $-0x28, %r15
addq $0x28, %r12
cmpq %rax, %r13
jb 0x2d70
leaq 0x20(%rsp), %rdi
callq 0x305c
movq %rsp, %rdi
callq 0x319c
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2e84
jmp 0x2e84
jmp 0x2e84
movq %rax, %rbx
jmp 0x2ec5
movq %rax, %rbx
jmp 0x2ebb
movq %rax, %rbx
jmp 0x2ecf
jmp 0x2e8b
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x2e9d
callq 0x32de
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2ecf
callq 0x32de
jmp 0x2ecf
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x305c
leaq 0x48(%rsp), %rdi
callq 0x305c
leaq 0x20(%rsp), %rdi
callq 0x305c
movq %rsp, %rdi
callq 0x319c
movq %rbx, %rdi
callq 0x2260