// File: /workspace/github_c_makefile_star2_O2/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 0x1440
cmpl $0x200, %eax            # imm = 0x200
je 0x1488
cmpl $0x100, %eax            # imm = 0x100
jne 0x1531
leaq 0x1c4e(%rip), %rdi      # 0x3082
callq 0x11f0
movb $0x1, %bl
jmp 0x1533
cmpb $0x1, 0xc(%r14)
jne 0x1531
movl 0x14(%r14), %eax
cmpl $0x74, %eax
je 0x153b
cmpl $0x66, %eax
je 0x1515
cmpl $0x67, %eax
je 0x1527
cmpl $0x70, %eax
je 0x151e
cmpl $0x62, %eax
jne 0x1531
leaq 0x3cd0(%rip), %rax      # 0x5153
jmp 0x152e
movzbl 0xc(%r14), %eax
cmpl $0x3, %eax
je 0x14f3
cmpl $0xc, %eax
je 0x14e5
cmpl $0x6, %eax
jne 0x1531
movl 0x8(%r14), %edi
callq 0x1110
movq %rax, %rdi
callq 0x1120
movq %rax, %r15
movl 0x10(%r14), %esi
movl 0x14(%r14), %edx
leaq 0x1b75(%rip), %rdi      # 0x3038
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1040
movl 0x10(%r14), %edx
movl 0x14(%r14), %ecx
leaq 0x3c55(%rip), %rdi      # 0x5130
movq %r15, %rsi
callq 0x134c
jmp 0x1533
leaq 0x1b79(%rip), %rdi      # 0x3065
callq 0x11f0
jmp 0x1531
movl 0x8(%r14), %edi
callq 0x1110
movq %rax, %rdi
callq 0x1120
leaq 0x3c25(%rip), %rsi      # 0x5130
movq %rax, %rdi
callq 0x13b7
jmp 0x1531
leaq 0x3c35(%rip), %rax      # 0x5151
jmp 0x152e
leaq 0x3c2b(%rip), %rax      # 0x5150
jmp 0x152e
leaq 0x3c24(%rip), %rax      # 0x5152
xorb $0x1, (%rax)
xorl %ebx, %ebx
movl %ebx, %eax
popq %rbx
popq %r14
popq %r15
retq
leaq 0x3c12(%rip), %rax      # 0x5154
xorb $0x1, (%rax)
movq 0x3bec(%rip), %rdi      # 0x5138
movl 0x3bf2(%rip), %edx      # 0x5144
imull 0x3be7(%rip), %edx      # 0x5140
shll $0x2, %edx
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x10b0
jmp 0x1533