// File: /workspace/github_c_makefile_star2_O1/mesbahamin[P]star-sim/src/platform_sdl.c
// Function: handle_event
bool handle_event(SDL_Event *event)
{
    bool should_quit = false;

    switch(event->type)
    {
        case SDL_QUIT:
        {
            printf("SDL_QUIT\n");
            should_quit = true;
        } break;

        case SDL_KEYDOWN:
        case SDL_KEYUP:
        {
            SDL_Keycode key_code = event->key.keysym.sym;
            bool is_down = (event->key.state == SDL_PRESSED);
            if (is_down)
            {
                if (key_code == SDLK_b)
                {
                    RENDER_BOUNDING_BOX = !RENDER_BOUNDING_BOX;
                }
                if (key_code == SDLK_f)
                {
                    BRUTE_FORCE = !BRUTE_FORCE;
                }
                if (key_code == SDLK_g)
                {
                    RENDER_GRID = !RENDER_GRID;
                }
                if (key_code == SDLK_p)
                {
                    PAUSED = !PAUSED;
                }
                if (key_code == SDLK_t)
                {
                    RENDER_TRAILS = !RENDER_TRAILS;
                    clear_screen(&global_back_buffer, COLOR_BACKGROUND);
                }
            }
        } break;
        case SDL_WINDOWEVENT:
        {
            switch(event->window.event)
            {
                case SDL_WINDOWEVENT_SIZE_CHANGED:
                {
                    SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
                    SDL_Renderer *renderer = SDL_GetRenderer(window);
                    printf("SDL_WINDOWEVENT_SIZE_CHANGED (%d, %d)\n", event->window.data1, event->window.data2);
                    sdl_resize_texture(&global_back_buffer, renderer, event->window.data1, event->window.data2);
                } break;

                case SDL_WINDOWEVENT_FOCUS_GAINED:
                {
                    printf("SDL_WINDOWEVENT_FOCUS_GAINED\n");
                } break;

                case SDL_WINDOWEVENT_EXPOSED:
                {
                    SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
                    SDL_Renderer *renderer = SDL_GetRenderer(window);
                    sdl_update_window(renderer, &global_back_buffer);
                } break;
            }
        } break;
    }
    return(should_quit);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %r14
movl (%rdi), %eax
leal -0x300(%rax), %ecx
cmpl $0x2, %ecx
jb 0x143b
cmpl $0x200, %eax            # imm = 0x200
je 0x149f
cmpl $0x100, %eax            # imm = 0x100
jne 0x155b
leaq 0x2c53(%rip), %rdi      # 0x4082
callq 0x11e0
movb $0x1, %bl
jmp 0x155d
cmpb $0x1, 0xc(%r14)
jne 0x155b
movl 0x14(%r14), %eax
xorl %ebx, %ebx
cmpl $0x66, %eax
jle 0x14fc
cmpl $0x67, %eax
je 0x153f
cmpl $0x70, %eax
je 0x1548
cmpl $0x74, %eax
jne 0x155d
leaq 0x4cd5(%rip), %rax      # 0x614c
xorb $0x1, (%rax)
movq 0x4caf(%rip), %rdi      # 0x6130
movl 0x4cb5(%rip), %edx      # 0x613c
imull 0x4caa(%rip), %edx      # 0x6138
shll $0x2, %edx
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x10b0
jmp 0x155d
movzbl 0xc(%r14), %eax
cmpl $0x3, %eax
je 0x151d
cmpl $0xc, %eax
je 0x150f
cmpl $0x6, %eax
jne 0x155b
movl 0x8(%r14), %edi
callq 0x1110
movq %rax, %rdi
callq 0x1120
movq %rax, %r15
movl 0x10(%r14), %esi
movl 0x14(%r14), %edx
leaq 0x2b5e(%rip), %rdi      # 0x4038
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1040
movl 0x10(%r14), %edx
movl 0x14(%r14), %ecx
leaq 0x4c36(%rip), %rdi      # 0x6128
movq %r15, %rsi
callq 0x133c
jmp 0x155d
cmpl $0x62, %eax
je 0x1551
cmpl $0x66, %eax
jne 0x155d
leaq 0x4c3c(%rip), %rax      # 0x6149
jmp 0x1558
leaq 0x2b4f(%rip), %rdi      # 0x4065
callq 0x11e0
jmp 0x155b
movl 0x8(%r14), %edi
callq 0x1110
movq %rax, %rdi
callq 0x1120
leaq 0x4bf3(%rip), %rsi      # 0x6128
movq %rax, %rdi
callq 0x13ae
jmp 0x155b
leaq 0x4c04(%rip), %rax      # 0x614a
jmp 0x1558
leaq 0x4bf9(%rip), %rax      # 0x6148
jmp 0x1558
leaq 0x4bf3(%rip), %rax      # 0x614b
xorb $0x1, (%rax)
xorl %ebx, %ebx
movl %ebx, %eax
popq %rbx
popq %r14
popq %r15
retq