// File: /workspace/github_cpp_makefile_star2_O2/alex-courtis[P]xlayoutdisplay/src/layout.cpp
// Function: layout(Settings const&)
int layout(const Settings& settings) {
    // optional wait
    if (settings.wait) {
        if (!settings.quiet) {
            cout << "Waiting " << settings.wait << " seconds..." << endl;
        }
        sleep(settings.wait);
    }

    // discover monitors
    const Monitors monitors = Monitors();

    // discover outputs
    const list<shared_ptr<Output>> currentOutputs = discoverOutputs();
    if (currentOutputs.empty()) {
        throw runtime_error("no outputs found");
    }

    // output verbose information
    if (!settings.quiet || settings.info) {
        cout << renderUserInfo(currentOutputs) << "\n\n";
        cout << "laptop lid ";
        if (monitors.laptopLidClosed) {
            cout << "closed";
        }
        else {
            cout << "open or not present";
        }
        cout << "\n";
    }

    // current info is all output, we're done
    if (settings.info) {
        return EXIT_SUCCESS;
    }

    // order the outputs if the user wishes
    const list<shared_ptr<Output>> outputs = orderOutputs(currentOutputs, settings.order);

    // activate ouputs and determine primary
    const shared_ptr<Output> primary = activateOutputs(outputs, settings.primary, monitors);

    // arrange mirrored or left to right
    if (settings.mirror) {
        mirrorOutputs(outputs);
    }
    else {
        ltrOutputs(outputs);
    }

    // determine DPI from the primary
    string dpiExplaination;
    long dpi = calculateDpi(primary, &dpiExplaination);
    if (!settings.quiet) {
        cout << "\n" << dpiExplaination << "\n";
    }

    // user overrides DPI
    if (settings.dpi) {
        dpi = settings.dpi;
        cout << "overriding with provided DPI " << to_string(dpi) << "\n";
    }

    // user overrides refresh rate
    long rate = 0;
    if (settings.rate) {
        rate = settings.rate;
        cout << "overriding with provided refresh rate " << to_string(rate) << "\n";
    }

    // render desired commands
    const string xrandrCmd = renderXrandrCmd(outputs, primary, dpi, rate);
    const string xrdbCmd = renderXrdbCmd(dpi);
    if (!settings.quiet || settings.noop) {
        cout << "\n" << xrandrCmd << "\n\n" << xrdbCmd << "\n";
    }

    // execute
    if (!settings.noop) {
        // xrandr
        int rc = system(xrandrCmd.c_str());
        if (rc != 0) {
            return rc;
        }

        // xrdb
        rc = system(xrdbCmd.c_str());
        if (rc != 0) {
            return rc;
        }

        // update root window's cursor
        resetRootCursor();
    }
    return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
movq 0x58(%rdi), %rdi
testq %rdi, %rdi
je 0x9032
cmpb $0x0, 0x50(%rbx)
jne 0x902d
movq 0x1cf96(%rip), %rdi     # 0x25f90
leaq 0xf593(%rip), %rsi      # 0x18594
callq 0x6370
movq 0x58(%rbx), %rsi
movq %rax, %rdi
callq 0x6360
leaq 0xf584(%rip), %rsi      # 0x1859d
movq %rax, %rdi
callq 0x6370
movq %rax, %rdi
callq 0x61d0
movq 0x58(%rbx), %rdi
callq 0x62e0
leaq 0x98(%rsp), %rdi
callq 0x942a
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x988d
cmpq %r14, (%r14)
je 0x9366
cmpb $0x1, 0x50(%rbx)
jne 0x9069
movb 0x10(%rbx), %al
cmpb $0x1, %al
jne 0x90f4
leaq 0x60(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x7bd9
movq 0x1cf0e(%rip), %rdi     # 0x25f90
leaq 0x60(%rsp), %rsi
callq 0x6340
leaq 0xf527(%rip), %rsi      # 0x185ba
movq %rax, %rdi
callq 0x6370
leaq 0x60(%rsp), %rdi
callq 0x61b0
movq 0x1cee4(%rip), %rdi     # 0x25f90
leaq 0xf50a(%rip), %rsi      # 0x185bd
callq 0x6370
leaq 0xf159(%rip), %rax      # 0x18218
leaq 0xf503(%rip), %rsi      # 0x185c9
cmpb $0x0, 0xa0(%rsp)
cmovneq %rax, %rsi
movq 0x1ceb7(%rip), %rdi     # 0x25f90
callq 0x6370
movq 0x1ceab(%rip), %rdi     # 0x25f90
leaq 0xf4cf(%rip), %rsi      # 0x185bb
callq 0x6370
movb 0x10(%rbx), %al
xorl %ebp, %ebp
testb $0x1, %al
jne 0x9342
leaq 0x18(%rbx), %rdx
leaq 0x48(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x76f0
leaq 0x30(%rbx), %rdx
leaq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x98(%rsp), %rcx
callq 0x77ff
cmpb $0x1, 0x12(%rbx)
jne 0x9141
leaq 0x48(%rsp), %rdi
callq 0x79d5
jmp 0x914b
leaq 0x48(%rsp), %rdi
callq 0x7939
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x38(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x7ea0
movq %rax, 0x8(%rsp)
cmpb $0x0, 0x50(%rbx)
jne 0x91a5
movq 0x1ce13(%rip), %rdi     # 0x25f90
leaq 0xf437(%rip), %rsi      # 0x185bb
callq 0x6370
leaq 0x60(%rsp), %rsi
movq %rax, %rdi
callq 0x6340
leaq 0xf41e(%rip), %rsi      # 0x185bb
movq %rax, %rdi
callq 0x6370
movq (%rbx), %r14
testq %r14, %r14
je 0x91fb
movq %r14, 0x8(%rsp)
movq 0x1cdd7(%rip), %rdi     # 0x25f90
leaq 0xf41d(%rip), %rsi      # 0x185dd
callq 0x6370
movq %rax, %r15
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x944d
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x6340
leaq 0xf3d2(%rip), %rsi      # 0x185bb
movq %rax, %rdi
callq 0x6370
leaq 0x10(%rsp), %rdi
callq 0x61b0
andq $0x0, 0x30(%rsp)
movq 0x8(%rbx), %r14
testq %r14, %r14
je 0x9258
movq %r14, 0x30(%rsp)
movq 0x1cd7a(%rip), %rdi     # 0x25f90
leaq 0xf3de(%rip), %rsi      # 0x185fb
callq 0x6370
movq %rax, %r15
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x944d
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x6340
leaq 0xf375(%rip), %rsi      # 0x185bb
movq %rax, %rdi
callq 0x6370
leaq 0x10(%rsp), %rdi
callq 0x61b0
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x38(%rsp), %rdx
leaq 0x8(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0x9525
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xa5b0
cmpb $0x1, 0x50(%rbx)
jne 0x9295
movb 0x11(%rbx), %al
cmpb $0x1, %al
jne 0x92e6
movq 0x1ccf4(%rip), %rdi     # 0x25f90
leaq 0xf318(%rip), %rsi      # 0x185bb
callq 0x6370
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x6340
leaq 0xf2fe(%rip), %rsi      # 0x185ba
movq %rax, %rdi
callq 0x6370
leaq 0xa8(%rsp), %rsi
movq %rax, %rdi
callq 0x6340
leaq 0xf2e0(%rip), %rsi      # 0x185bb
movq %rax, %rdi
callq 0x6370
movb 0x11(%rbx), %al
xorl %ebp, %ebp
testb $0x1, %al
jne 0x930d
movq 0x10(%rsp), %rdi
callq 0x6310
testl %eax, %eax
jne 0x930b
movq 0xa8(%rsp), %rdi
callq 0x6310
testl %eax, %eax
je 0x935f
movl %eax, %ebp
leaq 0xa8(%rsp), %rdi
callq 0x61b0
leaq 0x10(%rsp), %rdi
callq 0x61b0
leaq 0x60(%rsp), %rdi
callq 0x61b0
leaq 0x40(%rsp), %rdi
callq 0x7518
leaq 0x48(%rsp), %rdi
callq 0x83a8
leaq 0x80(%rsp), %rdi
callq 0x83a8
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0xa62c
jmp 0x930d
pushq $0x10
popq %rdi
callq 0x61e0
movq %rax, %r14
leaq 0xf231(%rip), %rsi      # 0x185a9
movq %rax, %rdi
callq 0x6150
movq 0x1cc61(%rip), %rsi     # 0x25fe8
movq 0x1cbea(%rip), %rdx     # 0x25f78
movq %r14, %rdi
callq 0x66c0
jmp 0x93d3
jmp 0x93d3
jmp 0x93d3
jmp 0x93d8
jmp 0x93bd
jmp 0x93d3
movq %rax, %rbx
jmp 0x93fc
movq %rax, %rbx
jmp 0x9406
jmp 0x9412
movq %rax, %rbx
movq %r14, %rdi
callq 0x62c0
jmp 0x9415
jmp 0x93bd
movq %rax, %rbx
jmp 0x93e8
jmp 0x9412
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x61b0
jmp 0x9415
movq %rax, %rbx
jmp 0x93f2
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x61b0
leaq 0x10(%rsp), %rdi
callq 0x61b0
leaq 0x60(%rsp), %rdi
callq 0x61b0
leaq 0x40(%rsp), %rdi
callq 0x7518
leaq 0x48(%rsp), %rdi
callq 0x83a8
jmp 0x9415
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x83a8
movq %rbx, %rdi
callq 0x6710