// File: alex-courtis[P]xlayoutdisplay/main.cpp
// Function: parseArgs(int, char**, Settings&)
void parseArgs(int argc, char **argv, Settings &settings) {
    static struct option long_options[] = {
        { "help",          no_argument,       0, 'h' },
        { "info",          no_argument,       0, 'i' },
        { "noop",          no_argument,       0, 'n' },
        { "version",       no_argument,       0, 'v' },
        { "dpi",           required_argument, 0, 'd' },
        { "rate",          required_argument, 0, 'r' },
        { "mirror",        no_argument,       0, 'm' },
        { "order",         required_argument, 0, 'o' },
        { "primary",       required_argument, 0, 'p' },
        { "quiet",         no_argument,       0, 'q' },
        { "wait",          required_argument, 0, 'w' },
        { 0,               0,                 0,  0  }
    };
    static const char *short_options = "hinvd:r:mo:p:qw:";

    bool orderFromFile = !settings.order.empty();

    int c;
    while (1) {
        int long_index = 0;
        c = getopt_long(argc, argv, short_options, long_options, &long_index);
        if (c == -1)
            break;
        switch (c) {
            case 'h':
                usage(cout);
                exit(EXIT_SUCCESS);
            case 'i':
                settings.info = true;
                break;
            case 'n':
                settings.noop = true;
                break;
            case 'v':
                cout << argv[0] << " " << VERSION << endl;
                exit(EXIT_SUCCESS);
            case 'd':
                settings.dpi = parseLong("dpi", optarg);
                break;
            case 'r':
                settings.rate = parseLong("rate", optarg);
                break;
            case 'm':
                settings.mirror = true;
                break;
            case 'o':
                if (orderFromFile) {
                    settings.order.clear();
                    orderFromFile = false;
                }
                settings.order.push_back(optarg);
                break;
            case 'p':
                settings.primary = optarg;
                break;
            case 'q':
                settings.quiet = true;
                break;
            case 'w':
                settings.wait = parseLong("wait", optarg);;
                break;
            case '?':
            default:
                usage(cerr);
                exit(EXIT_FAILURE);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
callq 0x16730
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x19(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
movq 0x48eb1(%rip), %rdx     # 0x5e6d0
leaq 0x48d2a(%rip), %rcx     # 0x5e550
leaq -0x24(%rbp), %r8
callq 0x7880
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x1583d
jmp 0x15d5e
movl -0x20(%rbp), %eax
addl $-0x3f, %eax
movl %eax, %ecx
movq %rcx, -0x158(%rbp)
subl $0x38, %eax
ja 0x15d43
movq -0x158(%rbp), %rax
leaq 0x2af99(%rip), %rcx     # 0x407fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x48725(%rip), %rdi     # 0x5df98
callq 0x14d80
xorl %edi, %edi
callq 0x7640
movq -0x18(%rbp), %rax
movb $0x1, 0x10(%rax)
jmp 0x15d59
movq -0x18(%rbp), %rax
movb $0x1, 0x11(%rax)
jmp 0x15d59
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq 0x486f1(%rip), %rdi     # 0x5df98
callq 0x74a0
movq %rax, %rdi
leaq 0x2af29(%rip), %rsi     # 0x407df
callq 0x74a0
movq %rax, %rdi
leaq 0x2b5e2(%rip), %rsi     # 0x40ea7
callq 0x74a0
movq %rax, %rdi
movq 0x4867c(%rip), %rsi     # 0x5df50
callq 0x7510
xorl %edi, %edi
callq 0x7640
leaq -0x49(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x7940
movq -0x160(%rbp), %rdx
leaq 0x2b54c(%rip), %rsi     # 0x40e4a
leaq -0x48(%rbp), %rdi
callq 0x8150
jmp 0x15909
movq 0x48650(%rip), %rax     # 0x5df60
movq (%rax), %rax
movq %rax, -0x170(%rbp)
leaq -0x81(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x7940
movq -0x170(%rbp), %rsi
movq -0x168(%rbp), %rdx
leaq -0x80(%rbp), %rdi
callq 0x8150
jmp 0x15946
leaq -0x48(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x14bf0
movq %rax, -0x178(%rbp)
jmp 0x1595c
movq -0x178(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
leaq -0x80(%rbp), %rdi
callq 0x7320
leaq -0x81(%rbp), %rdi
callq 0x7550
leaq -0x48(%rbp), %rdi
callq 0x7320
leaq -0x49(%rbp), %rdi
callq 0x7550
jmp 0x15d59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x159dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x159c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x7320
leaq -0x81(%rbp), %rdi
callq 0x7550
leaq -0x48(%rbp), %rdi
callq 0x7320
leaq -0x49(%rbp), %rdi
callq 0x7550
jmp 0x15d67
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x7940
movq -0x180(%rbp), %rdx
leaq 0x2b443(%rip), %rsi     # 0x40e4e
leaq -0xa8(%rbp), %rdi
callq 0x8150
jmp 0x15a19
movq 0x48540(%rip), %rax     # 0x5df60
movq (%rax), %rax
movq %rax, -0x190(%rbp)
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x7940
movq -0x190(%rbp), %rsi
movq -0x188(%rbp), %rdx
leaq -0xd0(%rbp), %rdi
callq 0x8150
jmp 0x15a59
leaq -0xa8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x14bf0
movq %rax, -0x198(%rbp)
jmp 0x15a75
movq -0x198(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
leaq -0xd0(%rbp), %rdi
callq 0x7320
leaq -0xd1(%rbp), %rdi
callq 0x7550
leaq -0xa8(%rbp), %rdi
callq 0x7320
leaq -0xa9(%rbp), %rdi
callq 0x7550
jmp 0x15d59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x15b05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x15aed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x7320
leaq -0xd1(%rbp), %rdi
callq 0x7550
leaq -0xa8(%rbp), %rdi
callq 0x7320
leaq -0xa9(%rbp), %rdi
callq 0x7550
jmp 0x15d67
movq -0x18(%rbp), %rax
movb $0x1, 0x12(%rax)
jmp 0x15d59
testb $0x1, -0x19(%rbp)
je 0x15b3a
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
callq 0x16770
movb $0x0, -0x19(%rbp)
movq -0x18(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x1b0(%rbp)
movq 0x48410(%rip), %rax     # 0x5df60
movq (%rax), %rax
movq %rax, -0x1a8(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x7940
movq -0x1a8(%rbp), %rsi
movq -0x1a0(%rbp), %rdx
leaq -0xf8(%rbp), %rdi
callq 0x8150
jmp 0x15b89
movq -0x1b0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x16620
jmp 0x15b9e
leaq -0xf8(%rbp), %rdi
callq 0x7320
leaq -0xf9(%rbp), %rdi
callq 0x7550
jmp 0x15d59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x15be1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x7320
leaq -0xf9(%rbp), %rdi
callq 0x7550
jmp 0x15d67
movq 0x48367(%rip), %rax     # 0x5df60
movq (%rax), %rsi
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
callq 0x7720
jmp 0x15d59
movq -0x18(%rbp), %rax
movb $0x1, 0x50(%rax)
jmp 0x15d59
leaq -0x121(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x7940
movq -0x1b8(%rbp), %rdx
leaq 0x2b223(%rip), %rsi     # 0x40e5f
leaq -0x120(%rbp), %rdi
callq 0x8150
jmp 0x15c4a
movq 0x4830f(%rip), %rax     # 0x5df60
movq (%rax), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x149(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x7940
movq -0x1c8(%rbp), %rsi
movq -0x1c0(%rbp), %rdx
leaq -0x148(%rbp), %rdi
callq 0x8150
jmp 0x15c8a
leaq -0x120(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x14bf0
movq %rax, -0x1d0(%rbp)
jmp 0x15ca6
movq -0x1d0(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
leaq -0x148(%rbp), %rdi
callq 0x7320
leaq -0x149(%rbp), %rdi
callq 0x7550
leaq -0x120(%rbp), %rdi
callq 0x7320
leaq -0x121(%rbp), %rdi
callq 0x7550
jmp 0x15d59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x15d33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x15d1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x7320
leaq -0x149(%rbp), %rdi
callq 0x7550
leaq -0x120(%rbp), %rdi
callq 0x7320
leaq -0x121(%rbp), %rdi
callq 0x7550
jmp 0x15d67
jmp 0x15d43
movq 0x4829e(%rip), %rdi     # 0x5dfe8
callq 0x14d80
movl $0x1, %edi
callq 0x7640
jmp 0x1580a
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x7930