// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movb $0x0, 0x3f(%rsp)
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
subl $0x100, %eax            # imm = 0x100
je 0x14e6
jmp 0x14c2
movl 0xc(%rsp), %eax
subl $0x200, %eax            # imm = 0x200
je 0x15da
jmp 0x14d3
movl 0xc(%rsp), %eax
addl $0xfffffd00, %eax       # imm = 0xFFFFFD00
subl $0x2, %eax
jb 0x14fe
jmp 0x16b1
leaq 0x2b43(%rip), %rdi      # 0x4030
movb $0x0, %al
callq 0x1040
movb $0x1, 0x3f(%rsp)
jmp 0x16b1
movq 0x40(%rsp), %rax
movl 0x14(%rax), %eax
movl %eax, 0x38(%rsp)
movq 0x40(%rsp), %rax
movzbl 0xc(%rax), %eax
cmpl $0x1, %eax
sete %al
andb $0x1, %al
movb %al, 0x37(%rsp)
testb $0x1, 0x37(%rsp)
je 0x15d5
cmpl $0x62, 0x38(%rsp)
jne 0x1549
leaq 0x4c0b(%rip), %rax      # 0x6143
movb (%rax), %cl
xorb $-0x1, %cl
andb $0x1, %cl
leaq 0x4bfc(%rip), %rax      # 0x6143
movb %cl, (%rax)
cmpl $0x66, 0x38(%rsp)
jne 0x1568
leaq 0x4bea(%rip), %rax      # 0x6141
movb (%rax), %cl
xorb $-0x1, %cl
andb $0x1, %cl
leaq 0x4bdb(%rip), %rax      # 0x6141
movb %cl, (%rax)
cmpl $0x67, 0x38(%rsp)
jne 0x1587
leaq 0x4bcc(%rip), %rax      # 0x6142
movb (%rax), %cl
xorb $-0x1, %cl
andb $0x1, %cl
leaq 0x4bbd(%rip), %rax      # 0x6142
movb %cl, (%rax)
cmpl $0x70, 0x38(%rsp)
jne 0x15a6
leaq 0x4bab(%rip), %rax      # 0x6140
movb (%rax), %cl
xorb $-0x1, %cl
andb $0x1, %cl
leaq 0x4b9c(%rip), %rax      # 0x6140
movb %cl, (%rax)
cmpl $0x74, 0x38(%rsp)
jne 0x15d3
leaq 0x4b90(%rip), %rax      # 0x6144
movb (%rax), %cl
xorb $-0x1, %cl
andb $0x1, %cl
leaq 0x4b81(%rip), %rax      # 0x6144
movb %cl, (%rax)
leaq 0x4b54(%rip), %rdi      # 0x6120
xorl %esi, %esi
callq 0x1460
jmp 0x15d5
jmp 0x16b1
movq 0x40(%rsp), %rax
movzbl 0xc(%rax), %eax
movl %eax, 0x8(%rsp)
subl $0x3, %eax
je 0x167d
jmp 0x15f2
movl 0x8(%rsp), %eax
subl $0x6, %eax
je 0x160b
jmp 0x15fd
movl 0x8(%rsp), %eax
subl $0xc, %eax
je 0x166d
jmp 0x16af
movq 0x40(%rsp), %rax
movl 0x8(%rax), %edi
callq 0x1110
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
callq 0x1120
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rax
movl 0x10(%rax), %esi
movq 0x40(%rsp), %rax
movl 0x14(%rax), %edx
leaq 0x29f7(%rip), %rdi      # 0x403a
movb $0x0, %al
callq 0x1040
movq 0x20(%rsp), %rsi
movq 0x40(%rsp), %rax
movl 0x10(%rax), %edx
movq 0x40(%rsp), %rax
movl 0x14(%rax), %ecx
leaq 0x4aba(%rip), %rdi      # 0x6120
callq 0x1340
jmp 0x16af
leaq 0x29ed(%rip), %rdi      # 0x4061
movb $0x0, %al
callq 0x1040
jmp 0x16af
movq 0x40(%rsp), %rax
movl 0x8(%rax), %edi
callq 0x1110
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
callq 0x1120
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x4a76(%rip), %rsi      # 0x6120
callq 0x1400
jmp 0x16b1
movb 0x3f(%rsp), %al
andb $0x1, %al
addq $0x48, %rsp
retq
nopl (%rax)