// File: therealgymmy[P]HelicopterGame/src/x_handler.cpp
// Function: XHandler::XHandler(Resources*)
XHandler::XHandler (Resources *resources)
: resources_(resources),
  showCredit_(false),
  score_(0) {
    if (!(xinfo_.display_ = XOpenDisplay(""))) {
        error("Can't open display");
    }
    xinfo_.screen_ = DefaultScreen(xinfo_.display_);

    XSizeHints hints;
    hints.x = 100;
    hints.y = 100;
    hints.width = 800;
    hints.height = 600;
    hints.flags = PPosition | PSize;

    unsigned long white = XWhitePixel(xinfo_.display_, xinfo_.screen_);
    unsigned long black = XBlackPixel(xinfo_.display_, xinfo_.screen_);

    xinfo_.window_ = XCreateSimpleWindow(
            xinfo_.display_,                    // display where window appears
            DefaultRootWindow(xinfo_.display_), // window's parent
            hints.x, hints.y,                   // upper left corner location
            hints.width, hints.height,          // window size
            5,                                  // window border width
            black,                              // window foreground colour
            white);                             // window background colour

    XSetStandardProperties(
            xinfo_.display_,    // display
            xinfo_.window_,     // window
            "Project 1",        // window title
            "P1",               // icon title
            None,               // pixmap for the icon
            None, None,         // cmd arguments
            &hints);            // hints for the window

    // get window attributes
    XGetWindowAttributes(xinfo_.display_, xinfo_.window_, &xinfo_.attr_);

    int depth = DefaultDepth(xinfo_.display_, xinfo_.screen_);

    xinfo_.buffer_ = XCreatePixmap(
            xinfo_.display_, xinfo_.window_, hints.width, hints.height, depth);

    // init values for the GC
    XGCValues values;
    values.cap_style = CapButt;
    values.join_style = JoinBevel;
    // which values to check when creating the GC
    unsigned long valuemask = GCCapStyle | GCJoinStyle;

    // set up black_
    xinfo_.black_ = XCreateGC(xinfo_.display_, xinfo_.window_, valuemask, &values);

    XSetForeground(
            xinfo_.display_,
            xinfo_.black_,
            BlackPixel(xinfo_.display_, xinfo_.screen_));

    XSetBackground(
            xinfo_.display_,
            xinfo_.black_,
            BlackPixel(xinfo_.display_, xinfo_.screen_));

    XSetFillStyle(xinfo_.display_, xinfo_.black_, FillSolid);

    XSetLineAttributes(
            xinfo_.display_, xinfo_.black_,
            2,              // line width
            LineSolid,      // line drawing style
            CapRound,       // cap drawing style (line'end)
            JoinRound);     // lines join style

    // set up white_
    xinfo_.white_ = XCreateGC(xinfo_.display_, xinfo_.window_, valuemask, &values);

    XSetForeground(
            xinfo_.display_,
            xinfo_.white_,
            WhitePixel(xinfo_.display_, xinfo_.screen_));

    XSetBackground(
            xinfo_.display_,
            xinfo_.white_,
            BlackPixel(xinfo_.display_, xinfo_.screen_));

    XSetFillStyle(xinfo_.display_, xinfo_.white_, FillSolid);

    XSetLineAttributes(
            xinfo_.display_, xinfo_.white_,
            2,              // line width
            LineSolid,      // line drawing style
            CapRound,       // cap drawing style (line'end)
            JoinRound);     // lines join style

    setupGC(xinfo_, xinfo_.grey_,   "grey");
    setupGC(xinfo_, xinfo_.green_,  "green");
    setupGC(xinfo_, xinfo_.brown_,  "#7F0000");
    setupGC(xinfo_, xinfo_.red_,    "red");
    setupGC(xinfo_, xinfo_.blue_,   "#1E90FF");
    setupGC(xinfo_, xinfo_.navajo_, "#FFDEAD");

    XMapRaised(xinfo_.display_, xinfo_.window_);

    XFlush(xinfo_.display_);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x300, %rsp            # imm = 0x300
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, (%rax)
movb $0x0, 0xf0(%rax)
movl $0x0, 0xf4(%rax)
leaq 0x7512(%rip), %rdi      # 0xd2cf
callq 0x3320
movq -0x230(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x5e4c
leaq -0x31(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x3410
movq -0x238(%rbp), %rdx
leaq 0x72ef(%rip), %rsi      # 0xd0e0
leaq -0x30(%rbp), %rdi
callq 0x5430
jmp 0x5dfc
leaq -0x30(%rbp), %rdi
callq 0x53f0
jmp 0x5e07
leaq -0x30(%rbp), %rdi
callq 0x3120
leaq -0x31(%rbp), %rdi
callq 0x3290
jmp 0x5e4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5e3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3120
leaq -0x31(%rbp), %rdi
callq 0x3290
jmp 0x6627
movq -0x230(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x268(%rbp)
movq 0x8(%rax), %rcx
movl 0xe0(%rcx), %ecx
movl %ecx, 0x10(%rax)
movl $0x64, -0x90(%rbp)
movl $0x64, -0x8c(%rbp)
movl $0x320, -0x88(%rbp)     # imm = 0x320
movl $0x258, -0x84(%rbp)     # imm = 0x258
movq $0xc, -0x98(%rbp)
movq 0x8(%rax), %rdi
movl 0x10(%rax), %esi
callq 0x3310
movq %rax, %rcx
movq -0x230(%rbp), %rax
movq %rcx, -0xa0(%rbp)
movq 0x8(%rax), %rdi
movl 0x10(%rax), %esi
callq 0x33b0
movq %rax, %rcx
movq -0x230(%rbp), %rax
movq %rcx, -0xa8(%rbp)
movq 0x8(%rax), %rdi
movq 0xe8(%rdi), %rax
movslq 0xe0(%rdi), %rcx
shlq $0x7, %rcx
movq 0x10(%rax,%rcx), %rsi
movl -0x90(%rbp), %edx
movl -0x8c(%rbp), %ecx
movl -0x88(%rbp), %r8d
movl -0x84(%rbp), %r9d
movq -0xa8(%rbp), %r10
movq -0xa0(%rbp), %r11
movq %rsp, %rax
movq %r11, 0x10(%rax)
movq %r10, 0x8(%rax)
movl $0x5, (%rax)
callq 0x3090
movq %rax, %rcx
movq -0x230(%rbp), %rax
movq %rcx, 0x18(%rax)
movq 0x8(%rax), %rdi
movq 0x18(%rax), %rsi
movq %rsp, %rax
leaq -0x98(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, (%rax)
leaq 0x718e(%rip), %rdx      # 0xd0f3
leaq 0x7191(%rip), %rcx      # 0xd0fd
xorl %eax, %eax
movl %eax, -0x254(%rbp)
movl %eax, %r9d
movq %r9, %r8
callq 0x3100
movq -0x230(%rbp), %rdx
movq 0x8(%rdx), %rdi
movq 0x18(%rdx), %rsi
addq $0x20, %rdx
callq 0x3420
movq -0x230(%rbp), %rax
movq 0x8(%rax), %rcx
movq 0xe8(%rcx), %rcx
movslq 0x10(%rax), %rdx
shlq $0x7, %rdx
movl 0x38(%rcx,%rdx), %ecx
movl %ecx, -0xac(%rbp)
movq 0x8(%rax), %rdi
movq 0x18(%rax), %rsi
movl -0x88(%rbp), %edx
movl -0x84(%rbp), %ecx
movl -0xac(%rbp), %r8d
callq 0x3060
movq %rax, %rcx
movq -0x230(%rbp), %rax
movq %rcx, 0xa8(%rax)
movl $0x1, -0x108(%rbp)
movl $0x2, -0x104(%rbp)
movq $0xc0, -0x138(%rbp)
movq 0x8(%rax), %rdi
movq 0x18(%rax), %rsi
movq -0x138(%rbp), %rdx
leaq -0x130(%rbp), %rcx
movq %rcx, -0x260(%rbp)
callq 0x3110
movq -0x230(%rbp), %rcx
movq %rax, 0xb0(%rcx)
movq 0x8(%rcx), %rdi
movq 0xb0(%rcx), %rsi
movq 0xe8(%rdi), %rax
movslq 0x10(%rcx), %rcx
shlq $0x7, %rcx
movq 0x60(%rax,%rcx), %rdx
callq 0x30a0
movq -0x230(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq 0xb0(%rcx), %rsi
movq 0xe8(%rdi), %rax
movslq 0x10(%rcx), %rcx
shlq $0x7, %rcx
movq 0x60(%rax,%rcx), %rdx
callq 0x3300
movl -0x254(%rbp), %edx
movq -0x230(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0xb0(%rax), %rsi
callq 0x3030
movl -0x254(%rbp), %ecx
movq -0x230(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0xb0(%rax), %rsi
movl $0x2, %r8d
movl %r8d, -0x250(%rbp)
movl $0x1, %r9d
movl %r9d, -0x24c(%rbp)
movl %r8d, %edx
callq 0x33c0
movq -0x260(%rbp), %rcx
movq -0x230(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x18(%rax), %rsi
movq -0x138(%rbp), %rdx
callq 0x3110
movq -0x230(%rbp), %rcx
movq %rax, 0xb8(%rcx)
movq 0x8(%rcx), %rdi
movq 0xb8(%rcx), %rsi
movq 0xe8(%rdi), %rax
movslq 0x10(%rcx), %rcx
shlq $0x7, %rcx
movq 0x58(%rax,%rcx), %rdx
callq 0x30a0
movq -0x230(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq 0xb8(%rcx), %rsi
movq 0xe8(%rdi), %rax
movslq 0x10(%rcx), %rcx
shlq $0x7, %rcx
movq 0x60(%rax,%rcx), %rdx
callq 0x3300
movl -0x254(%rbp), %edx
movq -0x230(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0xb8(%rax), %rsi
callq 0x3030
movl -0x254(%rbp), %ecx
movl -0x250(%rbp), %r8d
movl -0x24c(%rbp), %r9d
movq -0x230(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0xb8(%rax), %rsi
movl %r8d, %edx
callq 0x33c0
movq -0x230(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x248(%rbp)
leaq -0x159(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x3410
movq -0x240(%rbp), %rdx
leaq 0x6f20(%rip), %rsi      # 0xd100
leaq -0x158(%rbp), %rdi
callq 0x5430
jmp 0x61ee
movq -0x248(%rbp), %rsi
movq -0x268(%rbp), %rdi
leaq -0x158(%rbp), %rdx
callq 0x7840
jmp 0x620a
leaq -0x158(%rbp), %rdi
callq 0x3120
leaq -0x159(%rbp), %rdi
callq 0x3290
movq -0x230(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x280(%rbp)
addq $0xc8, %rax
movq %rax, -0x278(%rbp)
leaq -0x181(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x3410
movq -0x270(%rbp), %rdx
leaq 0x6ea0(%rip), %rsi      # 0xd105
leaq -0x180(%rbp), %rdi
callq 0x5430
jmp 0x6273
movq -0x278(%rbp), %rsi
movq -0x280(%rbp), %rdi
leaq -0x180(%rbp), %rdx
callq 0x7840
jmp 0x628f
leaq -0x180(%rbp), %rdi
callq 0x3120
leaq -0x181(%rbp), %rdi
callq 0x3290
movq -0x230(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x298(%rbp)
addq $0xd0, %rax
movq %rax, -0x290(%rbp)
leaq -0x1a9(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x3410
movq -0x288(%rbp), %rdx
leaq 0x6e21(%rip), %rsi      # 0xd10b
leaq -0x1a8(%rbp), %rdi
callq 0x5430
jmp 0x62f8
movq -0x290(%rbp), %rsi
movq -0x298(%rbp), %rdi
leaq -0x1a8(%rbp), %rdx
callq 0x7840
jmp 0x6314
leaq -0x1a8(%rbp), %rdi
callq 0x3120
leaq -0x1a9(%rbp), %rdi
callq 0x3290
movq -0x230(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x2b0(%rbp)
addq $0xd8, %rax
movq %rax, -0x2a8(%rbp)
leaq -0x1d1(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x3410
movq -0x2a0(%rbp), %rdx
leaq 0x6da4(%rip), %rsi      # 0xd113
leaq -0x1d0(%rbp), %rdi
callq 0x5430
jmp 0x637d
movq -0x2a8(%rbp), %rsi
movq -0x2b0(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0x7840
jmp 0x6399
leaq -0x1d0(%rbp), %rdi
callq 0x3120
leaq -0x1d1(%rbp), %rdi
callq 0x3290
movq -0x230(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x2c8(%rbp)
addq $0xe0, %rax
movq %rax, -0x2c0(%rbp)
leaq -0x1f9(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x3410
movq -0x2b8(%rbp), %rdx
leaq 0x6d23(%rip), %rsi      # 0xd117
leaq -0x1f8(%rbp), %rdi
callq 0x5430
jmp 0x6402
movq -0x2c0(%rbp), %rsi
movq -0x2c8(%rbp), %rdi
leaq -0x1f8(%rbp), %rdx
callq 0x7840
jmp 0x641e
leaq -0x1f8(%rbp), %rdi
callq 0x3120
leaq -0x1f9(%rbp), %rdi
callq 0x3290
movq -0x230(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x2e0(%rbp)
addq $0xe8, %rax
movq %rax, -0x2d8(%rbp)
leaq -0x221(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x3410
movq -0x2d0(%rbp), %rdx
leaq 0x6ca6(%rip), %rsi      # 0xd11f
leaq -0x220(%rbp), %rdi
callq 0x5430
jmp 0x6487
movq -0x2d8(%rbp), %rsi
movq -0x2e0(%rbp), %rdi
leaq -0x220(%rbp), %rdx
callq 0x7840
jmp 0x64a3
leaq -0x220(%rbp), %rdi
callq 0x3120
leaq -0x221(%rbp), %rdi
callq 0x3290
movq -0x230(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x18(%rax), %rsi
callq 0x3470
movq -0x230(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x33a0
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x650e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x3120
leaq -0x159(%rbp), %rdi
callq 0x3290
jmp 0x6627
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x6545
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x3120
leaq -0x181(%rbp), %rdi
callq 0x3290
jmp 0x6627
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x657c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x3120
leaq -0x1a9(%rbp), %rdi
callq 0x3290
jmp 0x6627
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x65b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x3120
leaq -0x1d1(%rbp), %rdi
callq 0x3290
jmp 0x6627
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x65e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x3120
leaq -0x1f9(%rbp), %rdi
callq 0x3290
jmp 0x6627
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x661b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x3120
leaq -0x221(%rbp), %rdi
callq 0x3290
movq -0x40(%rbp), %rdi
callq 0x3400