// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq %rdi, %rsi
movq (%rsi), %rsi
cmpq %rbx, %rsi
je 0x80da
movq 0x10(%rsi), %rax
cmpb $0x1, 0x90(%rax)
jne 0x7f18
leaq 0x38(%rsp), %r14
movq %rax, -0x8(%r14)
addq $0x18, %rsi
movq %r14, %rdi
callq 0x8b18
movq -0x8(%r14), %rsi
testq %rsi, %rsi
je 0x80da
addq $0x28, %rsi
leaq 0x18(%rsp), %rdi
callq 0x7940
leaq 0x138b(%rip), %rsi      # 0x92f3
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x90a0
movq %r15, %rdi
callq 0x6430
leaq 0x40(%rsp), %r12
leaq 0x136a(%rip), %r13      # 0x92f3
movq %r15, %r14
movq (%r14), %r14
cmpq %r15, %r14
je 0x80f8
movq (%rbx), %rbp
cmpq %rbx, %rbp
je 0x80d0
movb $0x1, %r15b
movq 0x10(%rbp), %rsi
cmpb $0x1, 0x90(%rsi)
jne 0x80b4
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
addq $0x28, %rsi
movq %r12, %rdi
callq 0x7940
movq %r12, %rdi
movq %r13, %rsi
callq 0x90a0
movq %r12, %rdi
callq 0x6430
movq 0x40(%rsp), %rsi
cmpq %r12, %rsi
je 0x801c
movq 0x10(%r14), %rax
movl 0x8(%rax), %ecx
movq 0x10(%rsi), %rdx
cmpl %ecx, 0x8(%rdx)
jne 0x8000
movl 0xc(%rdx), %edi
cmpl 0xc(%rax), %edi
je 0x800a
movq (%rsi), %rsi
cmpq %r12, %rsi
jne 0x7fef
jmp 0x801c
movq %rdx, (%rsp)
addq $0x18, %rsi
leaq 0x8(%rsp), %rdi
callq 0x8b18
movq %r12, %rdi
callq 0x7a74
movq (%rsp), %rax
testq %rax, %rax
setne %cl
andb %cl, %r15b
cmpb $0x1, %r15b
jne 0x80a2
movq 0x10(%rbp), %rdi
movq %rax, 0x98(%rdi)
addq $0xa0, %rdi
leaq 0x8(%rsp), %rsi
callq 0x8b18
movl $0x18, %edi
callq 0x6390
leaq 0x1c8fc(%rip), %rcx     # 0x24960
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
movsd 0x1224a(%rip), %xmm0    # 0x1a2c0
movups %xmm0, 0x8(%rax)
movq 0x10(%rbp), %rdx
movq %rcx, 0xa8(%rdx)
movq 0xb0(%rdx), %rdi
movq %rax, 0xb0(%rdx)
movb $0x1, %r15b
testq %rdi, %rdi
je 0x80a5
callq 0x7a04
jmp 0x80a5
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x80b4
callq 0x7a04
movq (%rbp), %rbp
cmpq %rbx, %rbp
jne 0x7fa7
testb $0x1, %r15b
leaq 0x18(%rsp), %r15
je 0x7f8c
leaq 0x18(%rsp), %rdi
callq 0x7a74
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x80e9
callq 0x7a04
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18(%rsp), %rdi
callq 0x7a74
movl $0x10, %edi
callq 0x61c0
movq %rax, %r14
leaq 0x12216(%rip), %rsi     # 0x1a32c
movq %rax, %rdi
callq 0x6150
movq 0x1cecb(%rip), %rsi     # 0x24ff0
movq 0x1ce5c(%rip), %rdx     # 0x24f88
movq %r14, %rdi
callq 0x66c0
movq %rax, %rbx
jmp 0x8170
jmp 0x813b
movq %rax, %rbx
jmp 0x817a
movq %rax, %rbx
movq %r14, %rdi
callq 0x62b0
jmp 0x817a
jmp 0x815e
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x7a74
jmp 0x8161
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x8170
callq 0x7a04
leaq 0x18(%rsp), %rdi
callq 0x7a74
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x8189
callq 0x7a04
movq %rbx, %rdi
callq 0x6700