// File: alex-courtis[P]xlayoutdisplay/src/xrandrrutil.cpp
// Function: modeFromXRR(unsigned long, _XRRScreenResources const*)
Mode *modeFromXRR(RRMode id, const XRRScreenResources *resources) {
    if (resources == nullptr)
        throw invalid_argument("cannot construct Mode: NULL XRRScreenResources");

    XRRModeInfo *modeInfo = nullptr;
    for (int i = 0; i < resources->nmode; i++) {
        if (id == resources->modes[i].id) {
            modeInfo = &(resources->modes[i]);
            break;
        }
    }

    if (modeInfo == nullptr)
        throw invalid_argument("cannot construct Mode: cannot retrieve RRMode '" + to_string(id) + "'");

    return new Mode(id, modeInfo->width, modeInfo->height, refreshFromModeInfo(*modeInfo));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x11846
movl $0x10, %edi
callq 0x7260
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa0(%rbp)
leaq 0x2ee83(%rip), %rsi     # 0x4068b
callq 0x79d0
jmp 0x1180f
movq -0xa0(%rbp), %rdi
movq 0x4c7ab(%rip), %rsi     # 0x5dfc8
movq 0x4c78c(%rip), %rdx     # 0x5dfb0
callq 0x78c0
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x73c0
jmp 0x11a46
movq $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jge 0x118a3
movq -0x8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jne 0x11896
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x118a3
jmp 0x11898
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x11855
cmpq $0x0, -0x28(%rbp)
jne 0x119af
movb $0x1, -0x91(%rbp)
movl $0x10, %edi
callq 0x7260
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x8200
jmp 0x118d8
leaq 0x2eddb(%rip), %rsi     # 0x406ba
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x12260
jmp 0x118f1
leaq 0x2edf0(%rip), %rdx     # 0x406e8
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x8100
jmp 0x11907
movq -0xa8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x7910
jmp 0x11919
movq -0xa8(%rbp), %rdi
movb $0x0, -0x91(%rbp)
movq 0x4c69a(%rip), %rsi     # 0x5dfc8
movq 0x4c67b(%rip), %rdx     # 0x5dfb0
callq 0x78c0
jmp 0x11a4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x11993
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x11987
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x1197e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x7320
leaq -0x70(%rbp), %rdi
callq 0x7320
leaq -0x90(%rbp), %rdi
callq 0x7320
testb $0x1, -0x91(%rbp)
jne 0x1199e
jmp 0x119aa
movq -0xa8(%rbp), %rdi
callq 0x73c0
jmp 0x11a46
movl $0x18, %edi
callq 0x74d0
movq %rax, -0xc0(%rbp)
movq %rax, -0xc8(%rbp)
movq -0x28(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0xb8(%rbp)
movq %rdi, %rax
addq $0xc, %rax
movq %rax, -0xb0(%rbp)
callq 0x11300
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rdx
movq -0xb0(%rbp), %rcx
movl %eax, -0x98(%rbp)
leaq -0x8(%rbp), %rsi
leaq -0x98(%rbp), %r8
callq 0x122b0
jmp 0x11a19
movq -0xc8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x18, %esi
callq 0x74e0
movq -0x18(%rbp), %rdi
callq 0x7930
nop