// File: /workspace/github_cpp_makefile_star2_O2/alex-courtis[P]xlayoutdisplay/src/calculations.cpp
// Function: mirrorOutputs(std::__cxx11::list<std::shared_ptr<Output>, std::allocator<std::shared_ptr<Output>>> const&)
void mirrorOutputs(const list<shared_ptr<Output>> &outputs) {

    // find the first active output
    shared_ptr<Output> firstOutput;
    for (const auto &output : outputs) {
        if (output->desiredActive) {
            firstOutput = output;
            break;
        }
    }
    if (!firstOutput)
        return;

    // iterate through first active output's modes
    for (const auto &possibleMode : reverseSort(firstOutput->modes)) {
        bool matched = true;

        // attempt to match mode to each active output
        for (const auto &output : outputs) {
            if (!output->desiredActive)
                continue;

            // reset failed matches
            shared_ptr<const Mode> desiredMode;

            // match height and width
            for (const auto &mode : reverseSort(output->modes)) {
                if (mode->width == possibleMode->width && mode->height == possibleMode->height) {

                    // select best refresh
                    desiredMode = mode;
                    break;
                }
            }

            // match a mode for every output; root it at 0, 0
            matched = matched && desiredMode;
            if (matched) {
                output->desiredMode = desiredMode;
                output->desiredPos = make_shared<Pos>(0, 0);
                continue;
            }
        }

        // we've set desiredMode and desiredPos (zero) for all outputs, all done
        if (matched)
            return;
    }

    // couldn't find a common mode, exit
    throw runtime_error("unable to find common width/height for mirror");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %rdi, %rsi
movq (%rsi), %rsi
cmpq %rbp, %rsi
je 0x7b47
movq 0x10(%rsi), %rax
cmpb $0x1, 0x90(%rax)
jne 0x79f1
addq $0x10, %rsi
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x83e8
movq (%r14), %rsi
testq %rsi, %rsi
je 0x7b47
addq $0x28, %rsi
leaq 0x38(%rsp), %r12
movq %r12, %rdi
callq 0x81e8
leaq 0x50(%rsp), %r13
movq %r12, %r15
movq (%r15), %r15
cmpq %r12, %r15
je 0x7b60
movb $0x1, %r14b
movq %rbp, %rbx
movq (%rbx), %rbx
cmpq %rbp, %rbx
je 0x7b33
movq 0x10(%rbx), %rsi
cmpb $0x1, 0x90(%rsi)
jne 0x7a52
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
addq $0x28, %rsi
movq %r13, %rdi
callq 0x81e8
movq %r13, %rsi
movq (%rsi), %rsi
cmpq %r13, %rsi
je 0x7ab0
movq 0x10(%rsi), %rax
movl 0x8(%rax), %edx
movq 0x10(%r15), %rcx
cmpl 0x8(%rcx), %edx
jne 0x7a82
movl 0xc(%rax), %eax
cmpl 0xc(%rcx), %eax
jne 0x7a82
addq $0x10, %rsi
leaq 0x10(%rsp), %rdi
callq 0x844e
movq %r13, %rdi
callq 0x7594
xorl %r12d, %r12d
testb $0x1, %r14b
je 0x7b1c
cmpq $0x0, 0x10(%rsp)
je 0x7b1c
movq 0x10(%rbx), %rdi
movl $0x98, %eax
addq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x844e
andl $0x0, 0xc(%rsp)
andl $0x0, 0x8(%rsp)
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x8229
movq 0x10(%rbx), %rdi
movl $0xa8, %eax
addq %rax, %rdi
movq %r13, %rsi
callq 0x8bb8
leaq 0x58(%rsp), %rdi
callq 0x7518
movb $0x1, %r12b
leaq 0x18(%rsp), %rdi
callq 0x7518
movl %r12d, %r14d
leaq 0x38(%rsp), %r12
jmp 0x7a52
testb $0x1, %r14b
je 0x7a40
leaq 0x38(%rsp), %rdi
callq 0x7594
leaq 0x28(%rsp), %rdi
callq 0x7518
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38(%rsp), %rdi
callq 0x7594
pushq $0x10
popq %rdi
callq 0x61e0
movq %rax, %r14
leaq 0x107a0(%rip), %rsi     # 0x1831c
movq %rax, %rdi
callq 0x6150
movq 0x1e45d(%rip), %rsi     # 0x25fe8
movq 0x1e3e6(%rip), %rdx     # 0x25f78
movq %r14, %rdi
callq 0x66c0
jmp 0x7b9e
jmp 0x7bb0
movq %rax, %rbx
jmp 0x7bc7
movq %rax, %rbx
movq %r14, %rdi
callq 0x62c0
jmp 0x7bc7
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x7518
leaq 0x38(%rsp), %rdi
callq 0x7594
leaq 0x28(%rsp), %rdi
callq 0x7518
movq %rbx, %rdi
callq 0x6710