// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rdi, %rsi
movq (%rsi), %rsi
cmpq %rbx, %rsi
je 0x7f2f
movq 0x10(%rsi), %rax
cmpb $0x1, 0x90(%rax)
jne 0x7f08
leaq 0x18(%rsp), %rdi
movq %rax, -0x8(%rdi)
addq $0x18, %rsi
callq 0x8b0a
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x80cc
addq $0x28, %rsi
leaq 0x28(%rsp), %rdi
callq 0x793a
leaq 0x13b6(%rip), %rsi      # 0x9308
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x9096
movq %r14, %rdi
callq 0x6430
leaq 0x40(%rsp), %r12
leaq 0x1395(%rip), %r13      # 0x9308
movq %r14, %rbp
movq (%rbp), %rbp
cmpq %r14, %rbp
je 0x80ea
movq (%rbx), %r14
cmpq %rbx, %r14
je 0x80c2
movb $0x1, %r15b
movq 0x10(%r14), %rax
cmpb $0x1, 0x90(%rax)
jne 0x80a7
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq 0x10(%r14), %rsi
addq $0x28, %rsi
movq %r12, %rdi
callq 0x793a
movq %r12, %rdi
movq %r13, %rsi
callq 0x9096
movq %r12, %rdi
callq 0x6430
movq 0x40(%rsp), %rsi
cmpq %r12, %rsi
je 0x800b
movq 0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movq 0x10(%rsi), %rdx
cmpl %ecx, 0x8(%rdx)
jne 0x7fef
movl 0xc(%rdx), %edi
cmpl 0xc(%rax), %edi
je 0x7ff9
movq (%rsi), %rsi
cmpq %r12, %rsi
jne 0x7fde
jmp 0x800b
movq %rdx, (%rsp)
addq $0x18, %rsi
leaq 0x8(%rsp), %rdi
callq 0x8b0a
movq %r12, %rdi
callq 0x7a6e
cmpq $0x0, (%rsp)
setne %al
andb %al, %r15b
cmpb $0x1, %r15b
jne 0x8098
movq 0x10(%r14), %rdi
movq (%rsp), %rax
movq %rax, 0x98(%rdi)
addq $0xa0, %rdi
leaq 0x8(%rsp), %rsi
callq 0x8b0a
movl $0x18, %edi
callq 0x6390
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x1c8cd(%rip), %rcx     # 0x24930
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
movq $0x0, 0x10(%rax)
movq 0x10(%r14), %rdx
movq %rcx, 0xa8(%rdx)
movq 0xb0(%rdx), %rdi
movq %rax, 0xb0(%rdx)
testq %rdi, %rdi
je 0x8098
callq 0x79fe
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x80a7
callq 0x79fe
movq (%r14), %r14
cmpq %rbx, %r14
jne 0x7f92
testb $0x1, %r15b
leaq 0x28(%rsp), %r14
je 0x7f76
leaq 0x28(%rsp), %rdi
callq 0x7a6e
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x80db
callq 0x79fe
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28(%rsp), %rdi
callq 0x7a6e
movl $0x10, %edi
callq 0x61c0
movq %rax, %r14
leaq 0x12214(%rip), %rsi     # 0x1a31c
movq %rax, %rdi
callq 0x6150
movq 0x1ced9(%rip), %rsi     # 0x24ff0
movq 0x1ce6a(%rip), %rdx     # 0x24f88
movq %r14, %rdi
callq 0x66c0
movq %rax, %rbx
jmp 0x8162
jmp 0x812d
movq %rax, %rbx
jmp 0x816c
movq %rax, %rbx
movq %r14, %rdi
callq 0x62b0
jmp 0x816c
jmp 0x8150
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x7a6e
jmp 0x8153
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x8162
callq 0x79fe
leaq 0x28(%rsp), %rdi
callq 0x7a6e
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x817b
callq 0x79fe
movq %rbx, %rdi
callq 0x6700