// File: /workspace/github_cpp_makefile_star2_O1/IsseW[P]bytepusher/src/main.cpp
// Function: main
int main(){
    Renderer renderer{"some title", GRID_WIDTH, GRID_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT};

    Grid grid = Grid(GRID_WIDTH, GRID_HEIGHT);
    grid.set_tile(4, 4, Tile::Alive);
    grid.set_tile(4, 5, Tile::Alive);
    grid.set_tile(4, 6, Tile::Alive);
    grid.set_tile(4, 7, Tile::Alive);
    grid.set_tile(4, 8, Tile::Alive);
    grid.set_tile(4, 9, Tile::Alive);
    grid.set_tile(4, 10, Tile::Alive);

    uint64_t now, last;
    double delta_time = 0;

    double next_tick = TICK_TIME;

    auto callback = [&](const SDL_Event& e) {
        switch (e.type) {
            case SDL_MOUSEBUTTONDOWN: {
                uint32_t x = e.button.x * GRID_WIDTH / WINDOW_WIDTH;
                uint32_t y = e.button.y * GRID_HEIGHT / WINDOW_HEIGHT;
                switch (e.button.button) {
                    case SDL_BUTTON_LEFT:
                        grid.set_tile(x, y, Tile::Alive);
                        break;
                    
                }
                break;
            }
        }
    };
    renderer.set_manual_event_handler(callback);

    while(renderer.poll_events()) {
        last = now;
        now = SDL_GetPerformanceCounter();
        delta_time = (now - last) / (double)SDL_GetPerformanceFrequency();

        next_tick -= delta_time;
        if (next_tick < 0.0) {
            next_tick = TICK_TIME;
            grid.update_with_rule(game_of_life_rule);
        }

        renderer.bulk_send_data(grid.get_texture());
        renderer.finalize();
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb0, %rsp
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xcc4(%rip), %rsi       # 0x3040
leaq 0xcc7(%rip), %rdx       # 0x304a
leaq 0x8(%rsp), %rdi
callq 0x2712
leaq 0x58(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x20, %edx
movl $0x20, %ecx
movl $0x140, %r8d            # imm = 0x140
movl $0x140, %r9d            # imm = 0x140
callq 0x2bb6
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x23c9
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2170
leaq 0x8(%rsp), %rdi
movl $0x20, %esi
movl $0x20, %edx
callq 0x27a4
leaq 0x8(%rsp), %rdi
movl $0x4, %esi
movl $0x4, %edx
movl $0xff, %ecx
callq 0x28bc
leaq 0x8(%rsp), %rdi
movl $0x4, %esi
movl $0x5, %edx
movl $0xff, %ecx
callq 0x28bc
leaq 0x8(%rsp), %rdi
movl $0x4, %esi
movl $0x6, %edx
movl $0xff, %ecx
callq 0x28bc
leaq 0x8(%rsp), %rdi
movl $0x4, %esi
movl $0x7, %edx
movl $0xff, %ecx
callq 0x28bc
leaq 0x8(%rsp), %rdi
movl $0x4, %esi
movl $0x8, %edx
movl $0xff, %ecx
callq 0x28bc
leaq 0x8(%rsp), %rdi
movl $0x4, %esi
movl $0x9, %edx
movl $0xff, %ecx
callq 0x28bc
leaq 0x8(%rsp), %rbx
movl $0x4, %esi
movl $0xa, %edx
movq %rbx, %rdi
movl $0xff, %ecx
callq 0x28bc
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rsi
movapd %xmm0, (%rsi)
movapd %xmm0, 0x10(%rsi)
movq %rbx, (%rsi)
leaq 0x1c3(%rip), %rax       # 0x266e
movq %rax, 0x18(%rsi)
leaq 0x1f8(%rip), %rax       # 0x26ae
movq %rax, 0x10(%rsi)
leaq 0x58(%rsp), %rdi
callq 0x2bac
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x24dd
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movsd 0xb23(%rip), %xmm0      # 0x3008
leaq 0x58(%rsp), %rbx
leaq 0x56f(%rip), %r14       # 0x2a60
leaq 0x8(%rsp), %r15
movsd %xmm0, 0x28(%rsp)
movq %rbx, %rdi
callq 0x2d3e
testb %al, %al
je 0x25bb
callq 0x21c0
movq %rax, %r12
callq 0x2130
movq %r12, %rcx
subq %r13, %rcx
movq %rcx, %xmm0
movq 0xaf4(%rip), %xmm2      # 0x3020
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0xaf8(%rip), %xmm3      # 0x3030
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movq %rax, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm3, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
divsd %xmm2, %xmm1
movsd 0x28(%rsp), %xmm2
subsd %xmm1, %xmm2
xorpd %xmm0, %xmm0
movsd %xmm2, 0x28(%rsp)
ucomisd %xmm2, %xmm0
jbe 0x2598
movq %r15, %rdi
movq %r14, %rsi
callq 0x2858
movsd 0xa76(%rip), %xmm0      # 0x3008
movsd %xmm0, 0x28(%rsp)
movq %r15, %rdi
callq 0x2a5a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2cc6
movq %rbx, %rdi
callq 0x2cfa
movq %r12, %r13
jmp 0x24fc
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x25ca
callq 0x21b0
movq $0x0, 0x18(%rsp)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x25e2
callq 0x21b0
leaq 0x58(%rsp), %rdi
callq 0x2c76
xorl %eax, %eax
addq $0xb0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x261f
movq %rax, %rbx
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x2652
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x2652
movq %rax, %rdi
callq 0x2706
movq %rax, %rbx
jmp 0x265c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x2666
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2170
jmp 0x2666
movq %rax, %rbx
jmp 0x2666
jmp 0x264f
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x26d4
leaq 0x58(%rsp), %rdi
callq 0x2c76
movq %rbx, %rdi
callq 0x2200