// File: /workspace/github_cpp_makefile_star2_O3/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 0x48(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2100
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x2c3b
movq 0x33a1(%rip), %rax      # 0x5fc8
cmpb $0x0, (%rax)
je 0x2c4b
incl 0x8(%rdi)
movq %rcx, 0x20(%rsp)
movq %rdi, 0x28(%rsp)
jmp 0x2c66
movq %rcx, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
jmp 0x2c79
lock
incl 0x8(%rdi)
movq %rcx, 0x20(%rsp)
movq %rdi, 0x28(%rsp)
movq 0x50(%rsp), %rcx
movq %rcx, %rdi
testq %rcx, %rcx
je 0x2c79
cmpb $0x0, (%rax)
je 0x2c70
incl 0x8(%rdi)
jmp 0x2c74
lock
incl 0x8(%rdi)
callq 0x32e6
leaq 0x20(%rsp), %r14
movq %rsp, %r15
cmpq $0x0, 0x28(%rsp)
je 0x2ca6
movq %r14, %rdi
callq 0x2280
movq %r15, %rdi
movq %rax, %rsi
callq 0x3096
movq %r14, %rdi
callq 0x2090
jmp 0x2c81
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x2cb5
callq 0x32e6
movq (%rsp), %r14
movq 0x8(%rsp), %r15
cmpq %r15, %r14
je 0x2d26
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 0x36ce
movq %r14, %rdi
movq %r15, %rsi
callq 0x37ab
movq (%rsp), %r14
movq 0x8(%rsp), %r15
cmpq %r15, %r14
je 0x2d26
movq %r14, %rdi
callq 0x20b0
cmpb $0x2, %al
jne 0x2d20
movq %r14, %rdi
callq 0x2bdc
addq $0x28, %r14
jmp 0x2d07
leaq 0x48(%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 0x2e52
movq $-0x28, %r15
xorl %r12d, %r12d
leaq 0x20(%rsp), %rbx
leaq 0x70(%rsp), %r14
xorl %r13d, %r13d
addq %r12, %rsi
movq %rbx, %rdi
callq 0x30c2
movq 0x8(%rsp), %rsi
addq %r15, %rsi
movq %r14, %rdi
callq 0x30c2
movq 0x323c(%rip), %rdi      # 0x5fd0
movq %rbx, %rsi
callq 0x3117
movq %rax, %rbp
movl $0x5, %edx
movq %rax, %rdi
leaq 0x1278(%rip), %rsi      # 0x4026
callq 0x21e0
movq %rbp, %rdi
movq %r14, %rsi
callq 0x3117
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 0x48(%rsp), %rsi
callq 0x2110
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2110
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x2110
movq %r14, %rdi
callq 0x305e
movq %rbx, %rdi
callq 0x305e
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 0x2d72
leaq 0x48(%rsp), %rdi
callq 0x305e
movq %rsp, %rdi
callq 0x319e
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2e86
jmp 0x2e86
jmp 0x2e86
movq %rax, %rbx
jmp 0x2ec7
movq %rax, %rbx
jmp 0x2ebd
movq %rax, %rbx
jmp 0x2ed1
jmp 0x2e8d
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2e9f
callq 0x32e6
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x2ed1
callq 0x32e6
jmp 0x2ed1
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x305e
leaq 0x20(%rsp), %rdi
callq 0x305e
leaq 0x48(%rsp), %rdi
callq 0x305e
movq %rsp, %rdi
callq 0x319e
movq %rbx, %rdi
callq 0x2260