// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
movq 0x58(%rdi), %rdi
testq %rdi, %rdi
je 0x9461
cmpb $0x0, 0x50(%rbx)
jne 0x945c
movq 0x1bba6(%rip), %r14     # 0x24fa0
leaq 0x111a3(%rip), %rsi     # 0x1a5a4
movl $0x8, %edx
movq %r14, %rdi
callq 0x6460
movq 0x58(%rbx), %rsi
movq %r14, %rdi
callq 0x6340
movq %rax, %r14
leaq 0x11189(%rip), %rsi     # 0x1a5ad
movl $0xb, %edx
movq %rax, %rdi
callq 0x6460
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6350
movsbl %al, %esi
movq %r14, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x6270
movq 0x58(%rbx), %rdi
callq 0x62d0
leaq 0x1b4c0(%rip), %rax     # 0x24928
addq $0x10, %rax
movq %rax, 0xa0(%rsp)
leaq 0x111b7(%rip), %rdi     # 0x1a632
callq 0x7224
movb %al, 0xa8(%rsp)
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
callq 0x9fcc
cmpq %r14, (%r14)
je 0x99cd
cmpb $0x1, 0x50(%rbx)
jne 0x94b1
movb 0x10(%rbx), %al
cmpb $0x1, %al
jne 0x956f
leaq 0x38(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x8191
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x1bacc(%rip), %rdi     # 0x24fa0
callq 0x6460
leaq 0x110ea(%rip), %rsi     # 0x1a5ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x6460
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9508
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x63a0
movq 0x1ba91(%rip), %rdi     # 0x24fa0
leaq 0x110b7(%rip), %rsi     # 0x1a5cd
movl $0xb, %edx
callq 0x6460
leaq 0x10cf1(%rip), %rax     # 0x1a218
leaq 0x110ab(%rip), %rsi     # 0x1a5d9
cmpb $0x0, 0xa8(%rsp)
cmovneq %rax, %rsi
movl $0x6, %eax
movl $0x13, %edx
cmovneq %rax, %rdx
movq 0x1ba51(%rip), %rdi     # 0x24fa0
callq 0x6460
movq 0x1ba45(%rip), %rdi     # 0x24fa0
leaq 0x11069(%rip), %rsi     # 0x1a5cb
movl $0x1, %edx
callq 0x6460
movb 0x10(%rbx), %al
xorl %ebp, %ebp
testb $0x1, %al
jne 0x99a2
leaq 0x18(%rbx), %rdx
leaq 0x68(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x7bbc
leaq 0x30(%rbx), %rdx
leaq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0xa0(%rsp), %rcx
callq 0x7cf8
cmpb $0x1, 0x12(%rbx)
jne 0x95bc
leaq 0x68(%rsp), %rdi
callq 0x7efc
jmp 0x95c6
leaq 0x68(%rsp), %rdi
callq 0x7e49
leaq 0x48(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
leaq 0x58(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x8575
movq %rax, 0x28(%rsp)
cmpb $0x0, 0x50(%rbx)
jne 0x9638
movq 0x1b9a3(%rip), %rdi     # 0x24fa0
leaq 0x10fc7(%rip), %rsi     # 0x1a5cb
movl $0x1, %edx
callq 0x6460
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x1b981(%rip), %rdi     # 0x24fa0
callq 0x6460
leaq 0x10fa0(%rip), %rsi     # 0x1a5cb
movl $0x1, %edx
movq %rax, %rdi
callq 0x6460
movq (%rbx), %rax
testq %rax, %rax
je 0x9744
movq %rax, 0x28(%rsp)
movq 0x1b950(%rip), %rdi     # 0x24fa0
leaq 0x10f96(%rip), %rsi     # 0x1a5ed
movl $0x1d, %edx
callq 0x6460
movq 0x28(%rsp), %r15
movq %r15, %r14
negq %r14
cmovsq %r15, %r14
movl $0x1, %r12d
cmpq $0xa, %r14
jb 0x96d0
movl $0x4, %r12d
movabsq $0x346dc5d63886594b, %rsi # imm = 0x346DC5D63886594B
movq %r14, %rcx
cmpq $0x63, %rcx
jbe 0x96c7
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x96cd
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x96d0
movq %rcx, %rax
mulq %rsi
shrq $0xb, %rdx
addl $0x4, %r12d
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x968f
addl $-0x3, %r12d
jmp 0x96d0
addl $-0x2, %r12d
jmp 0x96d0
decl %r12d
shrq $0x3f, %r15
leal (%r15,%r12), %esi
leaq 0x18(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x8(%rsp), %rdi
movl $0x2d, %edx
callq 0x6480
addq 0x8(%rsp), %r15
movq %r15, %rdi
movl %r12d, %esi
movq %r14, %rdx
callq 0x7089
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x1b88c(%rip), %rdi     # 0x24fa0
callq 0x6460
leaq 0x10eab(%rip), %rsi     # 0x1a5cb
movl $0x1, %edx
movq %rax, %rdi
callq 0x6460
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x9744
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x63a0
movq $0x0, 0x30(%rsp)
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x985a
movq %rax, 0x30(%rsp)
movq 0x1b83a(%rip), %rdi     # 0x24fa0
leaq 0x10e9e(%rip), %rsi     # 0x1a60b
movl $0x26, %edx
callq 0x6460
movq 0x30(%rsp), %r15
movq %r15, %r14
negq %r14
cmovsq %r15, %r14
movl $0x1, %r12d
cmpq $0xa, %r14
jb 0x97e6
movl $0x4, %r12d
movabsq $0x346dc5d63886594b, %rsi # imm = 0x346DC5D63886594B
movq %r14, %rcx
cmpq $0x63, %rcx
jbe 0x97dd
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x97e3
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x97e6
movq %rcx, %rax
mulq %rsi
shrq $0xb, %rdx
addl $0x4, %r12d
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x97a5
addl $-0x3, %r12d
jmp 0x97e6
addl $-0x2, %r12d
jmp 0x97e6
decl %r12d
shrq $0x3f, %r15
leal (%r15,%r12), %esi
leaq 0x18(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x8(%rsp), %rdi
movl $0x2d, %edx
callq 0x6480
addq 0x8(%rsp), %r15
movq %r15, %rdi
movl %r12d, %esi
movq %r14, %rdx
callq 0x7089
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x1b776(%rip), %rdi     # 0x24fa0
callq 0x6460
leaq 0x10d95(%rip), %rsi     # 0x1a5cb
movl $0x1, %edx
movq %rax, %rdi
callq 0x6460
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x985a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x63a0
leaq 0x8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x58(%rsp), %rdx
leaq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0x9b78
leaq 0x80(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xac88
cmpb $0x1, 0x50(%rbx)
jne 0x9897
movb 0x11(%rbx), %al
cmpb $0x1, %al
jne 0x990b
movq 0x1b702(%rip), %rdi     # 0x24fa0
leaq 0x10d26(%rip), %rsi     # 0x1a5cb
movl $0x1, %edx
callq 0x6460
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x1b6e0(%rip), %rdi     # 0x24fa0
callq 0x6460
movq %rax, %r14
leaq 0x10cfb(%rip), %rsi     # 0x1a5ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x6460
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %r14, %rdi
callq 0x6460
leaq 0x10cd0(%rip), %rsi     # 0x1a5cb
movl $0x1, %edx
movq %rax, %rdi
callq 0x6460
movb 0x11(%rbx), %al
xorl %ebp, %ebp
testb $0x1, %al
jne 0x9936
movq 0x8(%rsp), %rdi
callq 0x6300
testl %eax, %eax
jne 0x9934
movq 0x80(%rsp), %rdi
callq 0x6300
testl %eax, %eax
je 0x99c3
movl %eax, %ebp
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9957
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x63a0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9972
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x63a0
movq 0x38(%rsp), %rdi
cmpq %r13, %rdi
je 0x9989
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x63a0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x9998
callq 0x7a04
leaq 0x68(%rsp), %rdi
callq 0x8adc
leaq 0xb0(%rsp), %rdi
callq 0x8adc
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xad40
jmp 0x9936
movl $0x10, %edi
callq 0x61c0
movq %rax, %r14
leaq 0x10bd8(%rip), %rsi     # 0x1a5b9
movq %rax, %rdi
callq 0x6150
movq 0x1b600(%rip), %rsi     # 0x24ff0
movq 0x1b591(%rip), %rdx     # 0x24f88
movq %r14, %rdi
callq 0x66c0
jmp 0x9a70
jmp 0x9a70
jmp 0x9a70
jmp 0x9a75
movq %rax, %rbx
jmp 0x9a99
jmp 0x9a70
movq %rax, %rbx
jmp 0x9acb
movq %rax, %rbx
jmp 0x9ada
jmp 0x9ae6
movq %rax, %rbx
movq %r14, %rdi
callq 0x62b0
jmp 0x9ae9
jmp 0x9a38
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x9aa7
jmp 0x9ab4
jmp 0x9ae6
movq %rax, %rbx
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9ae9
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x63a0
jmp 0x9ae9
movq %rax, %rbx
jmp 0x9ab4
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9a99
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x63a0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9ab4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x63a0
movq 0x38(%rsp), %rdi
cmpq %r13, %rdi
je 0x9acb
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x63a0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x9ada
callq 0x7a04
leaq 0x68(%rsp), %rdi
callq 0x8adc
jmp 0x9ae9
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x8adc
movq %rbx, %rdi
callq 0x6700
nop