// File: /workspace/github_cpp_makefile_star2_O1/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
cmpq $0x0, 0x58(%rdi)
je 0x9476
cmpb $0x0, 0x50(%rbx)
jne 0x946e
movq 0x1bb90(%rip), %r14     # 0x24fa0
leaq 0x1117d(%rip), %rsi     # 0x1a594
movl $0x8, %edx
movq %r14, %rdi
callq 0x6460
movq 0x58(%rbx), %rsi
movq %r14, %rdi
callq 0x6340
movq %rax, %r14
leaq 0x11163(%rip), %rsi     # 0x1a59d
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
movl 0x58(%rbx), %edi
callq 0x62d0
leaq 0x1b47b(%rip), %rax     # 0x248f8
addq $0x10, %rax
movq %rax, 0xa0(%rsp)
leaq 0x11192(%rip), %rdi     # 0x1a622
callq 0x720c
movb %al, 0xa8(%rsp)
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
callq 0x9fdf
cmpq %r14, (%r14)
je 0x99e8
cmpb $0x1, 0x50(%rbx)
jne 0x94c5
cmpb $0x1, 0x10(%rbx)
jne 0x9580
leaq 0x38(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x8183
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x1bab8(%rip), %rdi     # 0x24fa0
callq 0x6460
leaq 0x110c6(%rip), %rsi     # 0x1a5ba
movl $0x2, %edx
movq %rax, %rdi
callq 0x6460
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x951c
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x63a0
movq 0x1ba7d(%rip), %rdi     # 0x24fa0
leaq 0x11093(%rip), %rsi     # 0x1a5bd
movl $0xb, %edx
callq 0x6460
leaq 0x10cdd(%rip), %rax     # 0x1a218
leaq 0x11087(%rip), %rsi     # 0x1a5c9
cmpb $0x0, 0xa8(%rsp)
cmovneq %rax, %rsi
movl $0x6, %eax
movl $0x13, %edx
cmovneq %rax, %rdx
movq 0x1ba3d(%rip), %rdi     # 0x24fa0
callq 0x6460
movq 0x1ba31(%rip), %rdi     # 0x24fa0
leaq 0x11045(%rip), %rsi     # 0x1a5bb
movl $0x1, %edx
callq 0x6460
xorl %ebp, %ebp
cmpb $0x0, 0x10(%rbx)
jne 0x99bb
leaq 0x18(%rbx), %rdx
leaq 0x68(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x7bb0
leaq 0x30(%rbx), %rdx
leaq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0xa0(%rsp), %rcx
callq 0x7cec
cmpb $0x1, 0x12(%rbx)
jne 0x95cf
leaq 0x68(%rsp), %rdi
callq 0x7eec
jmp 0x95d9
leaq 0x68(%rsp), %rdi
callq 0x7e39
leaq 0x48(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
leaq 0x58(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x8567
movq %rax, 0x28(%rsp)
cmpb $0x0, 0x50(%rbx)
jne 0x964b
movq 0x1b990(%rip), %rdi     # 0x24fa0
leaq 0x10fa4(%rip), %rsi     # 0x1a5bb
movl $0x1, %edx
callq 0x6460
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x1b96e(%rip), %rdi     # 0x24fa0
callq 0x6460
leaq 0x10f7d(%rip), %rsi     # 0x1a5bb
movl $0x1, %edx
movq %rax, %rdi
callq 0x6460
movq (%rbx), %rax
testq %rax, %rax
je 0x9757
movq %rax, 0x28(%rsp)
movq 0x1b93d(%rip), %rdi     # 0x24fa0
leaq 0x10f73(%rip), %rsi     # 0x1a5dd
movl $0x1d, %edx
callq 0x6460
movq 0x28(%rsp), %r15
movq %r15, %r14
negq %r14
cmovsq %r15, %r14
movl $0x1, %r12d
cmpq $0xa, %r14
jb 0x96e3
movl $0x4, %r12d
movabsq $0x346dc5d63886594b, %rsi # imm = 0x346DC5D63886594B
movq %r14, %rcx
cmpq $0x63, %rcx
jbe 0x96da
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x96e0
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x96e3
movq %rcx, %rax
mulq %rsi
shrq $0xb, %rdx
addl $0x4, %r12d
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x96a2
addl $-0x3, %r12d
jmp 0x96e3
addl $-0x2, %r12d
jmp 0x96e3
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 0x7075
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x1b879(%rip), %rdi     # 0x24fa0
callq 0x6460
leaq 0x10e88(%rip), %rsi     # 0x1a5bb
movl $0x1, %edx
movq %rax, %rdi
callq 0x6460
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x9757
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x63a0
movq $0x0, 0x30(%rsp)
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x986d
movq %rax, 0x30(%rsp)
movq 0x1b827(%rip), %rdi     # 0x24fa0
leaq 0x10e7b(%rip), %rsi     # 0x1a5fb
movl $0x26, %edx
callq 0x6460
movq 0x30(%rsp), %r15
movq %r15, %r14
negq %r14
cmovsq %r15, %r14
movl $0x1, %r12d
cmpq $0xa, %r14
jb 0x97f9
movl $0x4, %r12d
movabsq $0x346dc5d63886594b, %rsi # imm = 0x346DC5D63886594B
movq %r14, %rcx
cmpq $0x63, %rcx
jbe 0x97f0
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x97f6
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x97f9
movq %rcx, %rax
mulq %rsi
shrq $0xb, %rdx
addl $0x4, %r12d
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x97b8
addl $-0x3, %r12d
jmp 0x97f9
addl $-0x2, %r12d
jmp 0x97f9
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 0x7075
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x1b763(%rip), %rdi     # 0x24fa0
callq 0x6460
leaq 0x10d72(%rip), %rsi     # 0x1a5bb
movl $0x1, %edx
movq %rax, %rdi
callq 0x6460
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x986d
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 0x9b94
leaq 0x80(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xac9c
cmpb $0x1, 0x50(%rbx)
jne 0x98a9
cmpb $0x1, 0x11(%rbx)
jne 0x991a
movq 0x1b6f0(%rip), %rdi     # 0x24fa0
leaq 0x10d04(%rip), %rsi     # 0x1a5bb
movl $0x1, %edx
callq 0x6460
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x1b6ce(%rip), %rdi     # 0x24fa0
callq 0x6460
movq %rax, %r14
leaq 0x10cd9(%rip), %rsi     # 0x1a5ba
movl $0x2, %edx
movq %rax, %rdi
callq 0x6460
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %r14, %rdi
callq 0x6460
leaq 0x10cae(%rip), %rsi     # 0x1a5bb
movl $0x1, %edx
movq %rax, %rdi
callq 0x6460
cmpb $0x0, 0x11(%rbx)
jne 0x994d
movq 0x8(%rsp), %rdi
callq 0x6300
movl %eax, %ebp
testl %eax, %eax
jne 0x9947
movq 0x80(%rsp), %rdi
callq 0x6300
movl %eax, %ebp
testl %eax, %eax
je 0x99dc
xorl %eax, %eax
testb %al, %al
je 0x994f
xorl %ebp, %ebp
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9970
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x63a0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x998b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x63a0
movq 0x38(%rsp), %rdi
cmpq %r13, %rdi
je 0x99a2
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x63a0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x99b1
callq 0x79fe
leaq 0x68(%rsp), %rdi
callq 0x8ace
leaq 0xb0(%rsp), %rdi
callq 0x8ace
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xad54
movb $0x1, %al
jmp 0x9949
movl $0x10, %edi
callq 0x61c0
movq %rax, %r14
leaq 0x10bad(%rip), %rsi     # 0x1a5a9
movq %rax, %rdi
callq 0x6150
movq 0x1b5e5(%rip), %rsi     # 0x24ff0
movq 0x1b576(%rip), %rdx     # 0x24f88
movq %r14, %rdi
callq 0x66c0
jmp 0x9a8b
jmp 0x9a8b
jmp 0x9a8b
jmp 0x9a90
movq %rax, %rbx
jmp 0x9ab4
jmp 0x9a8b
movq %rax, %rbx
jmp 0x9ae6
movq %rax, %rbx
jmp 0x9af5
jmp 0x9b01
movq %rax, %rbx
movq %r14, %rdi
callq 0x62b0
jmp 0x9b04
jmp 0x9a53
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x9ac2
jmp 0x9acf
jmp 0x9b01
movq %rax, %rbx
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9b04
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x63a0
jmp 0x9b04
movq %rax, %rbx
jmp 0x9acf
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9ab4
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x63a0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9acf
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x63a0
movq 0x38(%rsp), %rdi
cmpq %r13, %rdi
je 0x9ae6
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x63a0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x9af5
callq 0x79fe
leaq 0x68(%rsp), %rdi
callq 0x8ace
jmp 0x9b04
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x8ace
movq %rbx, %rdi
callq 0x6700
nopl (%rax)