// File: /workspace/github_cpp_makefile_star2_O3/kazzmir[P]xborder/src/main.cpp
// Function: OptionWindow::handleEvent(_XEvent*, int*)
void handleEvent(XEvent * event, int * glow){
        if (event->xany.window == this->window){
            bool redraw = false;
            switch (event->type){
                case ClientMessage: {
                    Atom wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", false);
                    Atom wm_protocols_atom = XInternAtom(display, "WM_PROTOCOLS", true);

                    if (event->xclient.message_type == wm_protocols_atom &&
                        (Atom) event->xclient.data.l[0] == wm_delete_window){

                        destroy = true;
                        /*
                        XFreeGC(display, graphics);
                        graphics = NULL;
                        XUnmapWindow(display, option_window);
                        XDestroyWindow(display, option_window);
                        option_window = 0;
                        */
                    }
                    break;
                }
                case Expose: {
                    redraw = true;
                    break;
                }
                case MotionNotify: {
                    if (left_button_pressed){
                        int x = event->xmotion.x;
                        int use = (x - glow_line_x) / glow_line_step;
                        if (use < 0){
                            use = 0;
                        }
                        if (use > glow_max_speed){
                            use = glow_max_speed;
                        }
                        *glow = use;
                        glow_value = *glow;
                        redraw = true;
                    }
                    break;
                }
                case ButtonPress: {
                    int x = event->xbutton.x;
                    int y = event->xbutton.y;
                    if (y >= palette_start_y && y < palette_start_y + (palette_y + 1) * palette_size_block &&
                        x >= 0 && x < (palette_x + 1) * palette_size_block){

                        change_background_color(display, xborder_window, get_rgb(x / palette_size_block, (y - palette_start_y) / palette_size_block));
                    } else if (y >= glow_line_y - glow_line_height / 2 &&
                               y <= glow_line_y + glow_line_height / 2 &&
                               x >= glow_line_x &&
                               x <= glow_line_x + glow_line_width){
                        *glow = (x - glow_line_x) / glow_line_step;
                        if (*glow >= glow_max_speed){
                            *glow = glow_max_speed;
                        }
                        glow_value = *glow;
                        left_button_pressed = true;
                        redraw = true;
                    }
                    break;
                }
                case ButtonRelease: {
                    /* FIXME: check for left button */
                    left_button_pressed = false;
                    break;
                }
                case KeyPress: {
                    KeySym sym = XLookupKeysym(&event->xkey, 0);
                    if (sym == XK_BackSpace){
                        redraw = true;
                        if (window_title.length() > 0){
                            window_title = window_title.substr(0, window_title.size() - 1);
                        }
                    } else {
                        char * ascii = XKeysymToString(sym);
                        /* FIXME: handle shift, ctrl-w, ctrl-u */
                        if (ascii != NULL){
                            std::string add;
                            if (std::string(ascii) == "space"){
                                add = " ";
                            } else if (strlen(ascii) == 1){
                                add = ascii;
                            }

                            if (add != ""){
                                window_title += add;
                                redraw = true;
                            }
                        }
                    }
                    XStoreName(display, xborder_window, window_title.c_str());
                    break;
                }
            }

            if (redraw){
                draw(glow);
            }
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq 0x20(%rsi), %rax
cmpq 0x8(%rdi), %rax
jne 0x54e6
movq %rsi, %r15
movq %rdi, %rbx
movl (%rsi), %ecx
leal -0x2(%rcx), %eax
cmpl $0xa, %eax
ja 0x5269
movq %rdx, %r14
leaq 0xe5b(%rip), %rcx       # 0x606c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
xorl %esi, %esi
callq 0x33b0
cmpq $0xff08, %rax           # imm = 0xFF08
jne 0x53d1
movq 0x38(%rbx), %rcx
testq %rcx, %rcx
je 0x54ca
leaq 0x30(%rbx), %r15
decq %rcx
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x3310
movq %r15, %rdi
movq %r12, %rsi
callq 0x3370
movq (%r12), %rdi
jmp 0x54b5
cmpl $0x21, %ecx
jne 0x54e6
movq 0x20(%rbx), %rdi
leaq 0x1046(%rip), %rsi      # 0x62c3
xorl %edx, %edx
callq 0x3200
movq %rax, %r14
movq 0x20(%rbx), %rdi
leaq 0x1042(%rip), %rsi      # 0x62d4
movl $0x1, %edx
callq 0x3200
cmpq %rax, 0x28(%r15)
jne 0x54e6
cmpq %r14, 0x38(%r15)
jne 0x54e6
movb $0x1, 0x28(%rbx)
jmp 0x54e6
cmpb $0x1, 0x50(%rbx)
jne 0x54e6
movl 0x40(%r15), %eax
subl 0x5c(%rbx), %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovgl %ecx, %eax
cmpl $0x64, %eax
movl $0x64, %ecx
cmovll %eax, %ecx
movl %ecx, (%r14)
movl %ecx, 0x64(%rbx)
jmp 0x54db
movl 0x40(%r15), %eax
movl 0x44(%r15), %ecx
leal -0x28(%rcx), %edx
cmpl $0x69, %edx
setb %sil
cmpl $0x13b, %eax            # imm = 0x13B
setb %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0x536a
movq 0x10(%rbx), %r14
movq 0x20(%rbx), %rbx
movzwl %ax, %eax
imull $0x8889, %eax, %esi     # imm = 0x8889
shrl $0x13, %esi
movzbl %dl, %eax
imull $0x89, %eax, %edx
shrl $0xb, %edx
leaq -0x80(%rbp), %r15
movq %r15, %rdi
callq 0x3c79
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3ecd
jmp 0x54e6
movb $0x0, 0x50(%rbx)
jmp 0x54e6
movl 0x54(%rbx), %edx
movl 0x58(%rbx), %esi
movl %esi, %edi
shrl $0x1f, %edi
addl %esi, %edi
sarl %edi
movl %edx, %esi
subl %edi, %esi
cmpl %esi, %ecx
setl %sil
addl %edx, %edi
cmpl %edi, %ecx
setg %cl
orb %sil, %cl
jne 0x54e6
movl 0x5c(%rbx), %edx
movl %eax, %ecx
subl %edx, %ecx
jl 0x54e6
addl 0x60(%rbx), %edx
cmpl %edx, %eax
jg 0x54e6
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
cmpl $0xc8, %ecx
movl $0x64, %ecx
cmovll %eax, %ecx
movl %ecx, (%r14)
movl %ecx, 0x64(%rbx)
movb $0x1, 0x50(%rbx)
jmp 0x54db
movq %rax, %rdi
callq 0x3590
testq %rax, %rax
je 0x545a
movq %rax, %r15
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, %rdi
callq 0x3140
movq %r15, %rdx
addq %rax, %rdx
leaq -0x68(%rbp), %rdi
movq %r15, %rsi
callq 0x5922
leaq 0xf23(%rip), %rsi       # 0x6340
leaq -0x68(%rbp), %r13
movq %r13, %rdi
callq 0x30b0
movl %eax, %r12d
movq (%r13), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x5445
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x3300
testl %r12d, %r12d
je 0x5479
movq %r15, %rdi
callq 0x3140
cmpq $0x1, %rax
je 0x5480
jmp 0x548c
movq 0x10(%rbx), %rsi
movq 0x20(%rbx), %rdi
movq 0x30(%rbx), %rdx
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3060
leaq 0xef6(%rip), %r15       # 0x6376
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x33d0
leaq 0xc97(%rip), %rsi       # 0x612a
leaq -0x48(%rbp), %rdi
callq 0x30b0
testl %eax, %eax
je 0x54f5
leaq 0x30(%rbx), %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x30f0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x54ca
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x3300
movq 0x10(%rbx), %rsi
movq 0x20(%rbx), %rdi
movq 0x30(%rbx), %rdx
callq 0x3060
movq %rbx, %rdi
movq %r14, %rsi
callq 0x568a
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x550e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x3300
movq 0x10(%rbx), %rsi
movq 0x20(%rbx), %rdi
movq 0x30(%rbx), %rdx
callq 0x3060
jmp 0x54e6
jmp 0x5523
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x553f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x3300
movq %rbx, %rdi
callq 0x3550
nop