// File: alex-courtis[P]xlayoutdisplay/src/calculations.cpp
// Function: calculateDpi(std::shared_ptr<Output> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*)
long calculateDpi(const shared_ptr<Output> &output, string *explaination) {
    if (!output) throw invalid_argument("calculateDpi received empty output");

    long dpi = DEFAULT_DPI;
    stringstream verbose;
    if (!output->edid) {
        verbose << "DPI defaulting to "
                << dpi
                << "; EDID information not available for output "
                << output->name;
    } else if (!output->desiredMode) {
        verbose << "DPI defaulting to "
                << dpi
                << "; no desired mode for output "
                << output->name;
    } else {
        const long caldulatedDpi = output->edid->dpiForMode(output->desiredMode);
        if (caldulatedDpi == 0) {
            verbose << "DPI defaulting to "
                    << dpi
                    << " as no EDID horiz/vert cm information available for "
                    << output->name
                    << "; this is normal for projectors and some TVs";
        } else {
            dpi = caldulatedDpi;
            verbose << "calculated DPI "
                    << dpi
                    << " for output "
                    << output->name;
        }
    }

    *explaination = verbose.str();
    return dpi;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0xc2e0
testb $0x1, %al
jne 0xb93c
movl $0x10, %edi
callq 0x7260
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1e0(%rbp)
leaq 0x34a75(%rip), %rsi     # 0x40373
callq 0x79d0
jmp 0xb905
movq -0x1e0(%rbp), %rdi
movq 0x526b5(%rip), %rsi     # 0x5dfc8
movq 0x52696(%rip), %rdx     # 0x5dfb0
callq 0x78c0
movq -0x1e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x73c0
jmp 0xbc4a
movq $0x60, -0x28(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x73a0
movq -0x8(%rbp), %rdi
callq 0xc040
movq %rax, %rdi
addq $0x80, %rdi
callq 0xc560
testb $0x1, %al
jne 0xb9fd
leaq -0x1a0(%rbp), %rdi
leaq 0x34a18(%rip), %rsi     # 0x40396
callq 0x74a0
movq %rax, -0x1e8(%rbp)
jmp 0xb98c
movq -0x1e8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x7980
movq %rax, -0x1f0(%rbp)
jmp 0xb9a5
movq -0x1f0(%rbp), %rdi
leaq 0x349f6(%rip), %rsi     # 0x403a9
callq 0x74a0
movq %rax, -0x1f8(%rbp)
jmp 0xb9c1
movq -0x8(%rbp), %rdi
callq 0xc040
movq -0x1f8(%rbp), %rdi
movq %rax, %rsi
callq 0x7460
jmp 0xb9db
jmp 0xbbf2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x73d0
jmp 0xbc4a
movq -0x8(%rbp), %rdi
callq 0xc040
movq %rax, %rdi
addq $0x98, %rdi
callq 0x95b0
testb $0x1, %al
jne 0xba89
leaq -0x1a0(%rbp), %rdi
leaq 0x3496f(%rip), %rsi     # 0x40396
callq 0x74a0
movq %rax, -0x200(%rbp)
jmp 0xba35
movq -0x200(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x7980
movq %rax, -0x208(%rbp)
jmp 0xba4e
movq -0x208(%rbp), %rdi
leaq 0x3497a(%rip), %rsi     # 0x403d6
callq 0x74a0
movq %rax, -0x210(%rbp)
jmp 0xba6a
movq -0x8(%rbp), %rdi
callq 0xc040
movq -0x210(%rbp), %rdi
movq %rax, %rsi
callq 0x7460
jmp 0xba84
jmp 0xbbf0
movq -0x8(%rbp), %rdi
callq 0xc040
movq %rax, %rdi
subq $-0x80, %rdi
callq 0xc580
movq %rax, -0x220(%rbp)
movq -0x8(%rbp), %rdi
callq 0xc040
movq -0x220(%rbp), %rdi
movq %rax, %rsi
addq $0x98, %rsi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq %rax, -0x218(%rbp)
jmp 0xbad1
movq -0x218(%rbp), %rax
movq %rax, -0x1b8(%rbp)
cmpq $0x0, -0x1b8(%rbp)
jne 0xbb76
leaq -0x1a0(%rbp), %rdi
leaq 0x3489b(%rip), %rsi     # 0x40396
callq 0x74a0
movq %rax, -0x228(%rbp)
jmp 0xbb09
movq -0x228(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x7980
movq %rax, -0x230(%rbp)
jmp 0xbb22
movq -0x230(%rbp), %rdi
leaq 0x348c4(%rip), %rsi     # 0x403f4
callq 0x74a0
movq %rax, -0x238(%rbp)
jmp 0xbb3e
movq -0x8(%rbp), %rdi
callq 0xc040
movq -0x238(%rbp), %rdi
movq %rax, %rsi
callq 0x7460
movq %rax, -0x240(%rbp)
jmp 0xbb5f
movq -0x240(%rbp), %rdi
leaq 0x348bc(%rip), %rsi     # 0x40429
callq 0x74a0
jmp 0xbb74
jmp 0xbbee
movq -0x1b8(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq 0x348c7(%rip), %rsi     # 0x40456
callq 0x74a0
movq %rax, -0x248(%rbp)
jmp 0xbb9d
movq -0x248(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x7980
movq %rax, -0x250(%rbp)
jmp 0xbbb6
movq -0x250(%rbp), %rdi
leaq 0x34823(%rip), %rsi     # 0x403e7
callq 0x74a0
movq %rax, -0x258(%rbp)
jmp 0xbbd2
movq -0x8(%rbp), %rdi
callq 0xc040
movq -0x258(%rbp), %rdi
movq %rax, %rsi
callq 0x7460
jmp 0xbbec
jmp 0xbbee
jmp 0xbbf0
jmp 0xbbf2
leaq -0x1d8(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x7490
jmp 0xbc07
movq -0x10(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x7660
leaq -0x1d8(%rbp), %rdi
callq 0x7320
movq -0x28(%rbp), %rax
movq %rax, -0x260(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x73d0
movq -0x260(%rbp), %rax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x7930
nopw %cs:(%rax,%rax)