// File: kazzmir[P]xborder/src/main.cpp
// Function: run_xborder(bool)
void run_xborder(bool glow){
    Display * display;

    display = XOpenDisplay(NULL);
    if (display == NULL){
        std::cerr << "Cannot open display" << std::endl;
        return;
    }

    srand(time(NULL));

    XSetErrorHandler(x_error);

    /*
    std::cout << "Once a window has been selected you can press the following keys in the selected window" << std::endl;
    std::cout << "Press 'right alt + right shift' to bring up the options window" << std::endl;
    std::cout << "Press 'left shift + right shift' to close the border" << std::endl;
    */
    std::cout << "Select an existing window to wrap in xborder" << std::endl;
    std::cout << "kill the xborder program with ctrl-c, or press the X window button will also stop the xborder program" << std::endl;

    struct sigaction action;
    action.sa_handler = &handle_signal;
    action.sa_flags = SA_RESTART;
    sigfillset(&action.sa_mask);
    sigaction(SIGHUP, &action, NULL);
    sigaction(SIGINT, &action, NULL);

    int screen = DefaultScreen(display);

    Window child_window = find_terminal(display);
    if (child_window == RootWindow(display, screen) || child_window == 0){
        std::cout << "Invalid window chosen" << std::endl;
        return;
    }
    std::cout << "Child window " << child_window << std::endl;

    int child_x, child_y;
    XWindowAttributes child_attributes;
    XGetWindowAttributes(display, child_window, &child_attributes);
    Window child;
    XTranslateCoordinates(display, child_window, child_attributes.root, 0, 0, &child_x, &child_y, &child);
    // std::cout << "Window at " << child_x << ", " << child_y << std::endl;

    int border_size = 3;

    int use_width = child_attributes.width + border_size * 2;
    int use_height = child_attributes.height + border_size * 2;
    window = XCreateSimpleWindow(display, RootWindow(display, screen), child_x, child_y, use_width, use_height, 1, BlackPixel(display, screen), start_color(display).pixel);

    set_xborder_window(display, window);

    XSelectInput(display, window,
                 ExposureMask |
                 FocusChangeMask |
                 SubstructureNotifyMask |
                 StructureNotifyMask);
    std::cout << "Xborder window " << window << std::endl;
    XMapWindow(display, window);

    Atom wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", false);
    XSetWMProtocols(display, window, &wm_delete_window, 1);

    // delete_properties(display, child_window);
    set_override_redirect(display, child_window, true);

    XReparentWindow(display, child_window, window, border_size, border_size);
    /*
    std::cout << "Child root window " << get_root_window(display, child_window) << std::endl;
    std::cout << "Child parent window " << get_parent_window(display, child_window) << std::endl;
    // xdebug("XReparentWindow: %d\n", XReparentWindow(display, child_window, window, border_size, border_size));
    std::cout << "Child root window after reparent " << get_root_window(display, child_window) << std::endl;
    std::cout << "Child parent window after reparent " << get_parent_window(display, child_window) << std::endl;
    */
    // XSelectInput(display, child_window, KeyPressMask | KeyReleaseMask);
    XMoveWindow(display, window, child_x, child_y);

    Atom wm_protocols_atom = XInternAtom(display, "WM_PROTOCOLS", true);

    bool shift_pressed = false;
    bool alt_pressed = false;

    OptionWindow* optionWindow = NULL;
    // Window option_window = 0;
    // int palette_start = 20;
    std::string window_title = get_window_title(display, child_window);

    GC graphics = NULL;
    XStoreName(display, window, window_title.c_str());

    uint64_t glow_start = time_now();
    int glow_color = rand() % 360;
    int glow_speed = 0;
    if (glow){
        glow_speed = 50;
    }
    
    Atom xborder_atom = XInternAtom(display, "xborder", false);

    while (1){
        if (quit_now){
            std::cout << "Bye!" << std::endl;
            break;
        }

        /* TODO: move all the glow code into an object */
        if (glow_speed > 0){
            uint64_t check = time_now();
            int use_speed = glow_max_speed - glow_speed;
            if (use_speed < 1){
                use_speed = 1;
            }
            int move = (check - glow_start) / use_speed / 2;
            if (move > 0){
                glow_color = (glow_color + move) % 360;
                rgb next_color = get_rgb(glow_color, 1.0, 1.0);
                change_background_color(display, window, next_color);
                glow_start += move * use_speed;
            }
        }

        if (get_parent_window(display, child_window) != window){
            XReparentWindow(display, child_window, window, border_size, border_size);
        }

        if (XPending(display) == 0){
            usleep(1000);
            continue;
        }

        /*
        Window focus;
        int state;
        XGetInputFocus(display, &focus, &state);
        std::cout << "Focus state " << focus << std::endl;
        */

        XEvent event;
        XNextEvent(display, &event);

        if (optionWindow != NULL){
            optionWindow->handleEvent(&event, &glow_speed);
            if (optionWindow->isDead()){
                delete optionWindow;
                optionWindow = NULL;
            }
        }

        if (event.xany.window == window){
            if (event.type == Expose){
                /* anything to do here? the child already seems to get expose events */
            } else if (event.type == FocusIn){
                if (child_window != 0){
                    /* FIXME: somehow the child_window can be destroyed before we get here. check that the child is a valid window? */
                    XSetInputFocus(display, child_window, RevertToPointerRoot, CurrentTime);
                }
            } else if (event.type == ClientMessage){
                XClientMessageEvent * client = &event.xclient;

                // std::cout << "Got client message: " << XGetAtomName(display, client->message_type) << std::endl;

                if (client->message_type == xborder_atom &&
                    client->data.b[0] == XBorderConfigure){
                    std::cout << "Reconfigure xborder" << std::endl;

                    if (optionWindow != NULL){
                        optionWindow->raise();
                    } else {
                        optionWindow = OptionWindow::create(display, window);
                    }
                } else if (client->message_type == wm_protocols_atom &&
                           (Atom) client->data.l[0] == wm_delete_window){
                    break;
                }
            } else if (event.type == DestroyNotify){
                // std::cout << "Child window " << child_window << " event.event " << event.xdestroywindow.event << " event.window " << event.xdestroywindow.window << std::endl;
                /* there is no more child to deal with */
                if (event.xdestroywindow.window == child_window){
                    child_window = 0;
                    break;
                }
            } else if (event.type == ConfigureNotify){
                XWindowAttributes self;
                XGetWindowAttributes(display, window, &self);
                XResizeWindow(display, child_window, self.width - border_size * 2, self.height - border_size * 2);
            }
        }
    }

    if (optionWindow != NULL){
        delete optionWindow;
        optionWindow = NULL;
    }

    if (child_window != 0){
        set_override_redirect(display, child_window, false);
        Window child_root = child_attributes.root;
        /* Place the window wherever the container is now */
        XGetWindowAttributes(display, window, &child_attributes);
        XReparentWindow(display, child_window, child_root, child_attributes.x, child_attributes.y);
        XTranslateCoordinates(display, window, child_attributes.root, 0, 0, &child_x, &child_y, &child);
        XMoveWindow(display, child_window, child_x, child_y - border_size * 2);
    }

    XDestroyWindow(display, window);
    XCloseDisplay(display);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movb %dil, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x3480
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x4cde
movq 0x5332(%rip), %rdi      # 0x9ff0
leaq 0x25a2(%rip), %rsi      # 0x7267
callq 0x3310
movq %rax, %rdi
movq 0x52ec(%rip), %rsi      # 0x9fc0
callq 0x3370
jmp 0x5727
xorl %eax, %eax
movl %eax, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3300
leaq -0x735(%rip), %rdi      # 0x45c0
callq 0x30f0
movq 0x52cf(%rip), %rdi      # 0x9fd0
leaq 0x2573(%rip), %rsi      # 0x727b
callq 0x3310
movq %rax, %rdi
movq 0x52a9(%rip), %rsi      # 0x9fc0
callq 0x3370
movq 0x52ad(%rip), %rdi      # 0x9fd0
leaq 0x257e(%rip), %rsi      # 0x72a8
callq 0x3310
movq %rax, %rdi
movq 0x5287(%rip), %rsi      # 0x9fc0
callq 0x3370
leaq -0x825(%rip), %rax      # 0x4520
movq %rax, -0xa8(%rbp)
movl $0x10000000, -0x20(%rbp) # imm = 0x10000000
leaq -0xa8(%rbp), %rdi
addq $0x8, %rdi
callq 0x3100
movl $0x1, %edi
leaq -0xa8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x3420
movl $0x2, %edi
leaq -0xa8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x3420
movq -0x10(%rbp), %rax
movl 0xe0(%rax), %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3ad0
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0xe8(%rcx), %rcx
movslq -0xac(%rbp), %rdx
shlq $0x7, %rdx
addq %rdx, %rcx
cmpq 0x10(%rcx), %rax
je 0x4ddd
cmpq $0x0, -0xb8(%rbp)
jne 0x4e04
movq 0x51ec(%rip), %rdi      # 0x9fd0
leaq 0x2523(%rip), %rsi      # 0x730e
callq 0x3310
movq %rax, %rdi
movq 0x51c6(%rip), %rsi      # 0x9fc0
callq 0x3370
jmp 0x5727
movq 0x51c5(%rip), %rdi      # 0x9fd0
movq %rdi, -0x3a8(%rbp)
leaq 0x250b(%rip), %rsi      # 0x7324
callq 0x3310
movq %rax, %rdi
movq -0xb8(%rbp), %rsi
callq 0x3060
movq %rax, %rdi
movq 0x5189(%rip), %rsi      # 0x9fc0
movq %rsi, -0x3a0(%rbp)
callq 0x3370
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
leaq -0x148(%rbp), %rdx
callq 0x3640
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq -0x128(%rbp), %rdx
movq %rsp, %rax
leaq -0x150(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0xc0(%rbp), %rcx
movq %rcx, (%rax)
xorl %r8d, %r8d
movl %r8d, -0x398(%rbp)
leaq -0xbc(%rbp), %r9
movl %r8d, %ecx
callq 0x35e0
movl $0x3, -0x154(%rbp)
movl -0x140(%rbp), %edx
movl -0x154(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
movl %eax, -0x158(%rbp)
movl -0x13c(%rbp), %edx
movl -0x154(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,2), %eax
movl %eax, -0x15c(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x3c8(%rbp)
movq 0xe8(%rdi), %rax
movslq -0xac(%rbp), %rcx
shlq $0x7, %rcx
movl -0xbc(%rbp), %edx
movl %edx, -0x3ac(%rbp)
movl -0xc0(%rbp), %edx
movl %edx, -0x3b8(%rbp)
movl -0x158(%rbp), %edx
movl %edx, -0x3b4(%rbp)
movl -0x15c(%rbp), %edx
movl %edx, -0x3b0(%rbp)
movq 0x10(%rax,%rcx), %rdx
movq %rdx, -0x3c0(%rbp)
movq 0x60(%rax,%rcx), %rax
movq %rax, -0x3d0(%rbp)
callq 0x4530
movq -0x3d0(%rbp), %r10
movq -0x3c8(%rbp), %rdi
movq -0x3c0(%rbp), %rsi
movl -0x3b8(%rbp), %ecx
movl -0x3b4(%rbp), %r8d
movl -0x3b0(%rbp), %r9d
movq %rax, %r11
movq %rdx, %rax
movl -0x3ac(%rbp), %edx
movq %r11, -0x170(%rbp)
movq %rax, -0x168(%rbp)
movq -0x170(%rbp), %r11
movq %rsp, %rax
movq %r11, 0x10(%rax)
movq %r10, 0x8(%rax)
movl $0x1, (%rax)
callq 0x30e0
movq %rax, 0x53d6(%rip)      # 0xa380
movq -0x10(%rbp), %rdi
movq 0x53cb(%rip), %rsi      # 0xa380
callq 0x4c20
movq -0x10(%rbp), %rdi
movq 0x53bb(%rip), %rsi      # 0xa380
movl $0x2a8000, %edx         # imm = 0x2A8000
callq 0x31e0
movq -0x3a8(%rbp), %rdi
leaq 0x2355(%rip), %rsi      # 0x7332
callq 0x3310
movq %rax, %rdi
movq 0x5394(%rip), %rsi      # 0xa380
callq 0x3060
movq -0x3a0(%rbp), %rsi
movq %rax, %rdi
callq 0x3370
movq -0x10(%rbp), %rdi
movq 0x5375(%rip), %rsi      # 0xa380
callq 0x33d0
movl -0x398(%rbp), %edx
movq -0x10(%rbp), %rdi
leaq 0x2321(%rip), %rsi      # 0x7342
callq 0x3230
movq %rax, -0x178(%rbp)
movq -0x10(%rbp), %rdi
movq 0x5348(%rip), %rsi      # 0xa380
leaq -0x178(%rbp), %rdx
movl $0x1, %ecx
movl %ecx, -0x394(%rbp)
callq 0x31a0
movl -0x394(%rbp), %edx
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x4b60
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq 0x5309(%rip), %rdx      # 0xa380
movl -0x154(%rbp), %r8d
movl %r8d, %ecx
callq 0x3030
movq -0x10(%rbp), %rdi
movq 0x52ef(%rip), %rsi      # 0xa380
movl -0xbc(%rbp), %edx
movl -0xc0(%rbp), %ecx
callq 0x3270
movl -0x394(%rbp), %edx
movq -0x10(%rbp), %rdi
leaq 0x22a0(%rip), %rsi      # 0x7353
callq 0x3230
movq %rax, -0x180(%rbp)
movb $0x0, -0x181(%rbp)
movb $0x0, -0x182(%rbp)
movq $0x0, -0x190(%rbp)
movq -0x10(%rbp), %rsi
movq -0xb8(%rbp), %rdx
leaq -0x1b0(%rbp), %rdi
movq %rdi, -0x390(%rbp)
callq 0x4790
movq -0x390(%rbp), %rdi
movq $0x0, -0x1b8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x388(%rbp)
movq 0x5266(%rip), %rax      # 0xa380
movq %rax, -0x380(%rbp)
callq 0x3140
movq -0x388(%rbp), %rdi
movq -0x380(%rbp), %rsi
movq %rax, %rdx
callq 0x3070
jmp 0x513e
callq 0x42c0
movq %rax, -0x1d0(%rbp)
callq 0x30a0
movl $0x168, %ecx            # imm = 0x168
cltd
idivl %ecx
movl %edx, -0x1d4(%rbp)
movl $0x0, -0x1d8(%rbp)
testb $0x1, -0x1(%rbp)
je 0x519c
movl $0x32, -0x1d8(%rbp)
jmp 0x519c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x31d0
jmp 0x5730
movq -0x10(%rbp), %rdi
leaq 0x21ca(%rip), %rsi      # 0x7371
xorl %edx, %edx
callq 0x3230
movq %rax, -0x3d8(%rbp)
jmp 0x51b7
movq -0x3d8(%rbp), %rax
movq %rax, -0x1e0(%rbp)
jmp 0x51c7
movb 0x51ac(%rip), %al       # 0xa379
testb $0x1, %al
je 0x5207
movq 0x4df8(%rip), %rdi      # 0x9fd0
leaq 0x2181(%rip), %rsi      # 0x7360
callq 0x3310
movq %rax, -0x3e0(%rbp)
jmp 0x51ed
movq -0x3e0(%rbp), %rdi
movq 0x4dc5(%rip), %rsi      # 0x9fc0
callq 0x3370
jmp 0x5202
jmp 0x55f1
cmpl $0x0, -0x1d8(%rbp)
jle 0x532c
callq 0x42c0
movq %rax, -0x1e8(%rbp)
movl $0x64, %eax
subl -0x1d8(%rbp), %eax
movl %eax, -0x1ec(%rbp)
cmpl $0x1, -0x1ec(%rbp)
jge 0x5244
movl $0x1, -0x1ec(%rbp)
movq -0x1e8(%rbp), %rax
subq -0x1d0(%rbp), %rax
movslq -0x1ec(%rbp), %rcx
xorl %edx, %edx
divq %rcx
shrq %rax
movl %eax, -0x1f0(%rbp)
cmpl $0x0, -0x1f0(%rbp)
jle 0x532a
movl -0x1d4(%rbp), %eax
movl -0x1f0(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
imulq $-0x49f49f49, %rcx, %rcx # imm = 0xB60B60B7
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x8, %ecx
addl %edx, %ecx
imull $0x168, %ecx, %ecx      # imm = 0x168
subl %ecx, %eax
movl %eax, -0x1d4(%rbp)
movl -0x1d4(%rbp), %esi
leaq -0x208(%rbp), %rdi
movss 0x1da1(%rip), %xmm1     # 0x7060
movaps %xmm1, %xmm0
callq 0x4120
movq -0x10(%rbp), %rdi
movq 0x50ae(%rip), %rsi      # 0xa380
movq -0x1f8(%rbp), %rax
movq %rax, -0x210(%rbp)
movups -0x208(%rbp), %xmm0
movaps %xmm0, -0x220(%rbp)
movq -0x210(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movaps -0x220(%rbp), %xmm0
movups %xmm0, (%rax)
callq 0x4470
jmp 0x530d
movl -0x1f0(%rbp), %eax
imull -0x1ec(%rbp), %eax
cltq
addq -0x1d0(%rbp), %rax
movq %rax, -0x1d0(%rbp)
jmp 0x532c
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x4bb0
movq %rax, -0x3e8(%rbp)
jmp 0x5345
movq -0x3e8(%rbp), %rax
cmpq 0x502d(%rip), %rax      # 0xa380
je 0x537a
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq 0x5019(%rip), %rdx      # 0xa380
movl -0x154(%rbp), %r8d
movl %r8d, %ecx
callq 0x3030
jmp 0x5378
jmp 0x537a
movq -0x10(%rbp), %rdi
callq 0x32b0
movl %eax, -0x3ec(%rbp)
jmp 0x538b
movl -0x3ec(%rbp), %eax
cmpl $0x0, %eax
jne 0x53a7
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x34a0
jmp 0x53a2
jmp 0x51c5
movq -0x10(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x34b0
jmp 0x53b9
cmpq $0x0, -0x190(%rbp)
je 0x542d
movq -0x190(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
leaq -0x1d8(%rbp), %rdx
callq 0x5ca0
jmp 0x53df
movq -0x190(%rbp), %rdi
callq 0x6220
movb %al, -0x3ed(%rbp)
jmp 0x53f3
movb -0x3ed(%rbp), %al
testb $0x1, %al
jne 0x53ff
jmp 0x542b
movq -0x190(%rbp), %rax
movq %rax, -0x3f8(%rbp)
cmpq $0x0, %rax
je 0x5420
movq -0x3f8(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, -0x190(%rbp)
jmp 0x542d
movq -0x2c0(%rbp), %rax
cmpq 0x4f45(%rip), %rax      # 0xa380
jne 0x55ec
cmpl $0xc, -0x2e0(%rbp)
jne 0x544f
jmp 0x55ea
cmpl $0x9, -0x2e0(%rbp)
jne 0x5484
cmpq $0x0, -0xb8(%rbp)
je 0x547f
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movl $0x1, %edx
callq 0x3240
jmp 0x547d
jmp 0x547f
jmp 0x55e8
cmpl $0x21, -0x2e0(%rbp)
jne 0x556c
leaq -0x2e0(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movq -0x2e8(%rbp), %rax
movq 0x28(%rax), %rax
cmpq -0x1e0(%rbp), %rax
jne 0x553b
movq -0x2e8(%rbp), %rax
movsbl 0x38(%rax), %eax
cmpl $0x0, %eax
jne 0x553b
movq 0x4b02(%rip), %rdi      # 0x9fd0
leaq 0x1e90(%rip), %rsi      # 0x7365
callq 0x3310
movq %rax, -0x400(%rbp)
jmp 0x54e3
movq -0x400(%rbp), %rdi
movq 0x4acf(%rip), %rsi      # 0x9fc0
callq 0x3370
jmp 0x54f8
cmpq $0x0, -0x190(%rbp)
je 0x5512
movq -0x190(%rbp), %rdi
callq 0x6240
jmp 0x5510
jmp 0x5539
movq -0x10(%rbp), %rdi
movq 0x4e63(%rip), %rsi      # 0xa380
callq 0x6270
movq %rax, -0x408(%rbp)
jmp 0x552b
movq -0x408(%rbp), %rax
movq %rax, -0x190(%rbp)
jmp 0x556a
movq -0x2e8(%rbp), %rax
movq 0x28(%rax), %rax
cmpq -0x180(%rbp), %rax
jne 0x5568
movq -0x2e8(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x178(%rbp), %rax
jne 0x5568
jmp 0x55f1
jmp 0x556a
jmp 0x55e6
cmpl $0x11, -0x2e0(%rbp)
jne 0x5594
movq -0x2b8(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jne 0x5592
movq $0x0, -0xb8(%rbp)
jmp 0x55f1
jmp 0x55e4
cmpl $0x16, -0x2e0(%rbp)
jne 0x55e2
movq -0x10(%rbp), %rdi
movq 0x4dd8(%rip), %rsi      # 0xa380
leaq -0x370(%rbp), %rdx
callq 0x3640
jmp 0x55b6
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movl -0x154(%rbp), %eax
addl %eax, %eax
movl -0x368(%rbp), %edx
movl -0x364(%rbp), %ecx
subl %eax, %edx
subl %eax, %ecx
callq 0x3520
jmp 0x55e0
jmp 0x55e2
jmp 0x55e4
jmp 0x55e6
jmp 0x55e8
jmp 0x55ea
jmp 0x55ec
jmp 0x51c5
cmpq $0x0, -0x190(%rbp)
je 0x5627
movq -0x190(%rbp), %rax
movq %rax, -0x410(%rbp)
cmpq $0x0, %rax
je 0x561c
movq -0x410(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, -0x190(%rbp)
cmpq $0x0, -0xb8(%rbp)
je 0x56fe
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
xorl %edx, %edx
callq 0x4b60
jmp 0x5649
movq -0x128(%rbp), %rax
movq %rax, -0x378(%rbp)
movq -0x10(%rbp), %rdi
movq 0x4d1e(%rip), %rsi      # 0xa380
leaq -0x148(%rbp), %rdx
callq 0x3640
jmp 0x5670
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq -0x378(%rbp), %rdx
movl -0x148(%rbp), %ecx
movl -0x144(%rbp), %r8d
callq 0x3030
jmp 0x5696
movq -0x10(%rbp), %rdi
movq 0x4cdf(%rip), %rsi      # 0xa380
movq -0x128(%rbp), %rdx
movq %rsp, %rax
leaq -0x150(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0xc0(%rbp), %rcx
movq %rcx, (%rax)
xorl %r8d, %r8d
leaq -0xbc(%rbp), %r9
movl %r8d, %ecx
callq 0x35e0
jmp 0x56d4
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movl -0xbc(%rbp), %edx
movl -0xc0(%rbp), %ecx
movl -0x154(%rbp), %eax
addl %eax, %eax
subl %eax, %ecx
callq 0x3270
jmp 0x56fc
jmp 0x56fe
movq -0x10(%rbp), %rdi
movq 0x4c77(%rip), %rsi      # 0xa380
callq 0x3580
jmp 0x5710
movq -0x10(%rbp), %rdi
callq 0x3680
jmp 0x571b
leaq -0x1b0(%rbp), %rdi
callq 0x31d0
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
movq -0x1c0(%rbp), %rdi
callq 0x3620
nopl (%rax)