// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, %rbx
movq %rsi, (%rdi)
movb $0x0, 0xf0(%rdi)
andl $0x0, 0xf4(%rdi)
leaq 0x3555(%rip), %rdi      # 0x635f
callq 0x2260
leaq 0x8(%rbx), %r14
movq %rax, 0x8(%rbx)
testq %rax, %rax
jne 0x2e55
leaq 0x3275(%rip), %rsi      # 0x6098
leaq 0xe0(%rsp), %rdi
leaq 0x100(%rsp), %rdx
callq 0x3a9c
leaq 0xe0(%rsp), %rdi
callq 0x3a7c
leaq 0xe0(%rsp), %rdi
callq 0x20b0
movq (%r14), %rax
movl 0xe0(%rax), %esi
movl %esi, 0x10(%rbx)
movaps 0x31ab(%rip), %xmm0     # 0x6010
leaq 0x180(%rsp), %r12
movups %xmm0, 0x8(%r12)
movq $0xc, (%r12)
movq %rax, %rdi
callq 0x2250
movq %rax, %r15
movq 0x8(%rbx), %rdi
movl 0x10(%rbx), %esi
callq 0x22d0
movq 0x8(%rbx), %rdi
movq 0xe8(%rdi), %rcx
movslq 0xe0(%rdi), %rdx
shlq $0x7, %rdx
movq 0x10(%rcx,%rdx), %rsi
movl 0x8(%r12), %edx
movl 0xc(%r12), %ecx
movl 0x10(%r12), %r8d
movl 0x14(%r12), %r9d
movq %r15, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movl $0x5, (%rsp)
callq 0x2070
movq %rax, 0x18(%rbx)
movq 0x8(%rbx), %rdi
movq %r12, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0x31bc(%rip), %rdx      # 0x60ab
leaq 0x31bf(%rip), %rcx      # 0x60b5
movq %rax, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x20e0
movq 0x8(%rbx), %rdi
movq 0x18(%rbx), %rsi
leaq 0x20(%rbx), %rdx
callq 0x2340
movq 0x8(%rbx), %rdi
movq 0x18(%rbx), %rsi
movq 0xe8(%rdi), %rax
movslq 0x10(%rbx), %rcx
shlq $0x7, %rcx
movl 0x38(%rax,%rcx), %r8d
movl 0x10(%r12), %edx
movl 0x14(%r12), %ecx
callq 0x2050
movq %rax, 0xa8(%rbx)
movabsq $0x200000001, %rax      # imm = 0x200000001
leaq 0x100(%rsp), %r15
movq %rax, 0x28(%r15)
movq 0x8(%rbx), %rdi
movq 0x18(%rbx), %rsi
movl $0xc0, %edx
movq %r15, %rcx
callq 0x20f0
movq %rax, 0xb0(%rbx)
movq 0x8(%rbx), %rdi
movq 0xe8(%rdi), %rcx
movslq 0x10(%rbx), %rdx
shlq $0x7, %rdx
movq 0x60(%rcx,%rdx), %rdx
movq %rax, %rsi
callq 0x2080
movq 0x8(%rbx), %rdi
movq 0xb0(%rbx), %rsi
movq 0xe8(%rdi), %rax
movslq 0x10(%rbx), %rcx
shlq $0x7, %rcx
movq 0x60(%rax,%rcx), %rdx
callq 0x2240
movq 0x8(%rbx), %rdi
movq 0xb0(%rbx), %rsi
xorl %edx, %edx
callq 0x2030
movq 0x8(%rbx), %rdi
movq 0xb0(%rbx), %rsi
pushq $0x2
popq %rbp
pushq $0x1
popq %r12
movl %ebp, %edx
xorl %ecx, %ecx
movl %ebp, %r8d
movl %r12d, %r9d
callq 0x22f0
movq 0x8(%rbx), %rdi
movq 0x18(%rbx), %rsi
movl $0xc0, %edx
movq %r15, %rcx
callq 0x20f0
movq %rax, 0xb8(%rbx)
movq 0x8(%rbx), %rdi
movq 0xe8(%rdi), %rcx
movslq 0x10(%rbx), %rdx
shlq $0x7, %rdx
movq 0x58(%rcx,%rdx), %rdx
movq %rax, %rsi
callq 0x2080
movq 0x8(%rbx), %rdi
movq 0xb8(%rbx), %rsi
movq 0xe8(%rdi), %rax
movslq 0x10(%rbx), %rcx
shlq $0x7, %rcx
movq 0x60(%rax,%rcx), %rdx
callq 0x2240
movq 0x8(%rbx), %rdi
movq 0xb8(%rbx), %rsi
xorl %edx, %edx
callq 0x2030
movq 0x8(%rbx), %rdi
movq 0xb8(%rbx), %rsi
movl %ebp, %edx
xorl %ecx, %ecx
movl %ebp, %r8d
movl %r12d, %r9d
callq 0x22f0
leaq 0x3035(%rip), %rsi      # 0x60b8
leaq 0xc0(%rsp), %rdi
leaq 0x1f(%rsp), %rdx
callq 0x3a9c
leaq 0xc0(%rbx), %rsi
leaq 0xc0(%rsp), %rdx
movq %r14, %rdi
callq 0x3ad7
leaq 0xc0(%rsp), %rdi
callq 0x20b0
leaq 0x2ffd(%rip), %rsi      # 0x60bd
leaq 0xa0(%rsp), %rdi
leaq 0x1f(%rsp), %rdx
callq 0x3a9c
leaq 0xc8(%rbx), %rsi
leaq 0xa0(%rsp), %rdx
movq %r14, %rdi
callq 0x3ad7
leaq 0xa0(%rsp), %rdi
callq 0x20b0
leaq 0x2fc6(%rip), %rsi      # 0x60c3
leaq 0x80(%rsp), %rdi
leaq 0x1f(%rsp), %rdx
callq 0x3a9c
leaq 0xd0(%rbx), %rsi
leaq 0x80(%rsp), %rdx
movq %r14, %rdi
callq 0x3ad7
leaq 0x80(%rsp), %rdi
callq 0x20b0
leaq 0x2f91(%rip), %rsi      # 0x60cb
leaq 0x60(%rsp), %rdi
leaq 0x1f(%rsp), %rdx
callq 0x3a9c
leaq 0xd8(%rbx), %rsi
leaq 0x60(%rsp), %rdx
movq %r14, %rdi
callq 0x3ad7
leaq 0x60(%rsp), %rdi
callq 0x20b0
leaq 0x2f61(%rip), %rsi      # 0x60cf
leaq 0x40(%rsp), %rdi
leaq 0x1f(%rsp), %rdx
callq 0x3a9c
leaq 0xe0(%rbx), %rsi
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
callq 0x3ad7
leaq 0x40(%rsp), %rdi
callq 0x20b0
leaq 0x2f35(%rip), %rsi      # 0x60d7
leaq 0x20(%rsp), %rdi
leaq 0x1f(%rsp), %rdx
callq 0x3a9c
leaq 0xe8(%rbx), %rsi
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x3ad7
leaq 0x20(%rsp), %rdi
callq 0x20b0
movq 0x8(%rbx), %rdi
movq 0x18(%rbx), %rsi
callq 0x2380
movq 0x8(%rbx), %rdi
callq 0x22c0
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
jmp 0x3251
jmp 0x3258
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x3251
jmp 0x3258
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0x3251
jmp 0x3258
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x3251
jmp 0x3258
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x3251
jmp 0x3258
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
jmp 0x3251
jmp 0x3258
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x20b0
jmp 0x325b
movq %rax, %rbx
movq %rbx, %rdi
callq 0x2330
nop