// File: /workspace/github_cpp_makefile_star2_O2/RegulusImpact[P]sadboy/src/Graphics/XGPU.cpp
// Function: XGPU::init_x()
void XGPU::init_x() {
    // setup up the display variables
    display = XOpenDisplay((char*)0);

    if (display == NULL) {
        std::cerr << "X could not open display. Make sure the DISPLAY environment variable is configured." << std::endl;
        std::cerr << "E.g. DISPLAY:0" << std::endl;
        exit(1);
    }

    screen = XDefaultScreen(display);

    black = BlackPixel(display, screen);
    white = WhitePixel(display, screen);

    // create the window
    window = XCreateSimpleWindow(
        display,
        DefaultRootWindow(display),
        0,
        0,
        (windowScalar * MAX_X), // 200 wide
        (windowScalar * MAX_Y), // 300 down
        5,
        white, // foreground white
        black // background black
    );

    // set window properties
    XSetStandardProperties(
        display,
        window,
        "Sadboy", // Title maximized
        "Emulator", // Title minimized
        None,
        NULL,
        0,
        NULL
    );

    // set inputs
    XSelectInput(display, window, ExposureMask|ButtonPressMask|KeyPressMask);

    // create graphics context
    gc = XCreateGC(display, window, 0, 0);

    // set the fore/back ground colors currently in use in the window
    XSetForeground(display, gc, white);
    XSetBackground(display, gc, white);

    // clear the window and bring to foreground
    XClearWindow(display, window);
    XMapRaised(display, window);

    XDrawString(display, window, gc, 5, 5,"Sadboy world!", strlen("Sadboy world!"));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %edi, %edi
callq 0x44a0
movq %rax, 0x5a20(%rbx)
testq %rax, %rax
je 0x173f2
movq %rax, %rdi
callq 0x4210
movl %eax, 0x5a28(%rbx)
movq 0x5a20(%rbx), %rdi
movq 0xe8(%rdi), %rcx
cltq
shlq $0x7, %rax
movq 0x60(%rcx,%rax), %rdx
movl %edx, %r10d
movl %edx, 0x5a48(%rbx)
movq 0x58(%rcx,%rax), %rax
movl %eax, %r11d
movl %eax, 0x5a4c(%rbx)
movslq 0xe0(%rdi), %rax
shlq $0x7, %rax
movq 0x10(%rcx,%rax), %rsi
movzbl 0x5a90(%rbx), %eax
imull $0xa0, %eax, %r8d
imull $0x90, %eax, %r9d
subq $0x8, %rsp
xorl %edx, %edx
xorl %ecx, %ecx
pushq %r10
pushq %r11
pushq $0x5
callq 0x40f0
addq $0x20, %rsp
movq %rax, 0x5a30(%rbx)
movq 0x5a20(%rbx), %rdi
leaq 0x4330(%rip), %rdx      # 0x1b647
leaq 0x4330(%rip), %rcx      # 0x1b64e
movq %rax, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq $0x0
callq 0x41b0
popq %rcx
popq %rdx
movq 0x5a20(%rbx), %rdi
movq 0x5a30(%rbx), %rsi
movl $0x8005, %edx           # imm = 0x8005
callq 0x4240
movq 0x5a20(%rbx), %rdi
movq 0x5a30(%rbx), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x41e0
movq %rax, 0x5a38(%rbx)
movq 0x5a20(%rbx), %rdi
movl 0x5a4c(%rbx), %edx
movq %rax, %rsi
callq 0x4100
movq 0x5a20(%rbx), %rdi
movq 0x5a38(%rbx), %rsi
movl 0x5a4c(%rbx), %edx
callq 0x4470
movq 0x5a20(%rbx), %rdi
movq 0x5a30(%rbx), %rsi
callq 0x4320
movq 0x5a20(%rbx), %rdi
movq 0x5a30(%rbx), %rsi
callq 0x4620
movq 0x5a20(%rbx), %rdi
movq 0x5a30(%rbx), %rsi
movq 0x5a38(%rbx), %rdx
subq $0x8, %rsp
leaq 0x427b(%rip), %r9       # 0x1b657
pushq $0x5
popq %rcx
movl %ecx, %r8d
pushq $0xd
callq 0x4360
popq %rcx
popq %rdx
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movq 0xebf7(%rip), %rbx      # 0x25ff0
leaq 0x41e4(%rip), %rsi      # 0x1b5e4
movq %rbx, %rdi
callq 0x4340
movq %rax, %rdi
callq 0x4190
leaq 0x4221(%rip), %rsi      # 0x1b638
movq %rbx, %rdi
callq 0x4340
movq %rax, %rdi
callq 0x4190
pushq $0x1
popq %rdi
callq 0x4420
nop