// File: /workspace/github_c_makefile_star2_O3/FredTheDino[P]Fog/src/rain/editor_main.cpp
// Function: sprite_editor_update()
void sprite_editor_update() {
    Vec2 point;
    // Input
    {
        // Rename?
        if (fog_input_pressed((u32) In::EDIT_RENAME, Player::ANY)) {
            read_with_default("sprite rename", nullptr,
                    global_editor.sprites[global_editor.current_sprite].name,
                    MAX_TEXT_LENGTH);
        }

        const u32 num_sprites = global_editor.sprites.size();
        if (fog_input_pressed((u32) In::EDIT_PREV_SPRITE, Player::ANY) && num_sprites) {
            global_editor.current_sprite -= 1;
            global_editor.current_sprite += num_sprites;
            global_editor.current_sprite %= num_sprites;
        }
        if (fog_input_pressed((u32) In::EDIT_NEXT_SPRITE, Player::ANY) && num_sprites) {
            global_editor.current_sprite += 1;
            global_editor.current_sprite += num_sprites;
            global_editor.current_sprite %= num_sprites;
        }

        f32 delta = MIN(fog_logic_delta(), 0.2);
        f32 move_x = fog_input_value((u32) In::EDIT_MOVE_RIGHT_LEFT, Player::ANY);
        f32 move_y = fog_input_value((u32) In::EDIT_MOVE_UP_DOWN, Player::ANY);

        f32 zoom;
        if (fog_input_using_controller())
            zoom = (1.0 + fog_input_value((u32) In::EDIT_ZOOM_IN_OUT, Player::ANY) * delta);
        else
            zoom = (1.0 + (fog_input_mouse_scroll().y * 5) * delta);
        fog_renderer_fetch_camera(0)->zoom *= zoom;
        f32 current_zoom = fog_renderer_fetch_camera(0)->zoom;
        const f32 speed = delta / current_zoom;
        Vec2 cursor;
        if (fog_input_using_controller())
            cursor = global_editor.cursor;
        else
            cursor = fog_input_world_mouse_position(0);
        global_editor.worst_best_distance = global_editor.orig_worst_best_distance / current_zoom;

        if (fog_input_pressed((u32) In::EDIT_SNAP_SMALLER, Player::ANY)) {
            global_editor.snapping_scale *= global_editor.snapping_scale_step;
        }
        if (fog_input_pressed((u32) In::EDIT_SNAP_LARGER, Player::ANY)) {
            global_editor.snapping_scale /= global_editor.snapping_scale_step;
        }
        global_editor.snapping_scale = CLAMP(1.0 / 512.0, 1.0, global_editor.snapping_scale);

        if (fog_input_down((u32) In::TWEAK_STEP, Player::ANY)) {
            const f32 snap = global_editor.snapping_scale;
            static float step_timer = 0.0;
            step_timer += delta;
            if (step_timer > 0.1) {
                if (ABS(move_x) > 0.3)
                    cursor.x += SIGN(move_x) * snap * 1.1;
                if (ABS(move_y) > 0.3)
                    cursor.y += SIGN(move_y) * snap * 1.1;
                step_timer = 0.0;
            }
            precise_snap(&cursor.x, snap, snap);
            precise_snap(&cursor.y, snap, snap);
        } else {
            cursor += fog_V2(move_x, move_y) * speed;
        }
        cursor = fog_V2(CLAMP(-0.1, 1.1, cursor.x), CLAMP(-0.1, 1.1, cursor.y));
        global_editor.cursor = cursor;
        // Like a return value... but not...
        point = cursor;
    }

    if (fog_input_pressed((u32) In::EDIT_ADD_SPRITE, Player::ANY)) {
        create_new_sprite();
    }

    // Drawing logic
    {
        f32 current_zoom = fog_renderer_fetch_camera(0)->zoom;
        const f32 snap = global_editor.snapping_scale;
        const f32 line_width = 0.03 / current_zoom;
        const Vec4 dim_color = fog_V4(1, 0, 1, 0.05);
        const Vec4 vis_color = fog_V4(1, 0, 1, 0.2);
        Vec4 color = fog_input_down((u32) In::TWEAK_STEP, Player::ANY) ? vis_color : dim_color;
        for (u32 i = 0; i <= 1.0 / snap; i++) {
            Vec2 start, end;
            start = fog_V2(i * snap, 0.0);
            end = fog_V2(i * snap, 1.0);
            fog_renderer_push_line(5, start, end, color, line_width);
            start = fog_V2(0.0, i * snap);
            end = fog_V2(1.0, i * snap);
            fog_renderer_push_line(5, start, end, color, line_width);
        }
        const Vec4 cursor_color = fog_V4(0.0, 1.0, 0.0, 1.0);
        fog_renderer_push_point(10, point, cursor_color, 0.05 / current_zoom);
    }

    // Camera Movement
    {
        Camera *camera = fog_renderer_fetch_camera(0);
        f32 dist = fog_distance_v2(camera->position, point);
        f32 threshold = 0.5 / camera->zoom;
        if (dist > threshold) {
            f32 speed = 10 * (dist - threshold) * camera->zoom * fog_logic_delta();
            camera->position += (point - camera->position) * speed;
        }
    }

    // TODO(ed): Select sprite
    // TODO(ed): Allow multiple sprites to be editable at once
    // TODO(ed): Tweak values for things like, hue of the overlay
    // and such, so any sprite can be rendered underneath

    // Sprite select
    EditableSprite *sprite = &global_editor.sprites[global_editor.current_sprite];
    {
        AssetID next = sprite->sheet;
        if (fog_input_pressed((u32) In::EDIT_NEXT_SPRITE_SHEET, Player::ANY)) {
            next = find_next_sheet(next, 1);
        }
        if (fog_input_pressed((u32) In::EDIT_PREV_SPRITE_SHEET, Player::ANY)) {
            next = find_next_sheet(next, -1);
        }
        if (next != -1)
            sprite->sheet = next;
    }

    // Logic
    if (fog_input_down((u32) In::EDIT_SELECT, Player::ANY) || fog_input_mouse_down(0)) {
        s32 best_index = -1;
        f32 best_dist = global_editor.worst_best_distance;
        std::vector<Vec2> *points = &sprite->points;
        u32 num_points = points->size();
        for (u32 i = 0; i < num_points; i++) {
            f32 dist = fog_length_v2(point - (*points)[i]);
            if (dist < best_dist) {
                best_index = i;
                best_dist = dist;
            }
        }
        if (best_index >= 0) {
            (*points)[best_index] = point;
        }
    }

    if (fog_input_pressed((u32) In::EDIT_REMOVE, Player::ANY) || fog_input_mouse_pressed(3)) {
        s32 best_index = -1;
        f32 best_dist = global_editor.worst_best_distance;
        std::vector<Vec2> *points = &sprite->points;
        u32 num_points = points->size();
        for (u32 i = 0; i < num_points; i++) {
            f32 dist = fog_length_v2(point - (*points)[i]);
            if (dist < best_dist) {
                best_index = i;
                best_dist = dist;
            }
        }
        if (best_index >= 0) {
            points->erase(points->begin() + best_index);
        }
    }

    if (fog_input_pressed((u32) In::EDIT_PLACE, Player::ANY) || fog_input_mouse_pressed(2)) {
        s32 best_index = 0;
        f32 best_dist = 1000;
        std::vector<Vec2> *points = &sprite->points;
        u32 num_points = points->size();
        for (u32 i = 0; i < num_points; i++) {
            Vec2 prev = (*points)[i];
            Vec2 next = (*points)[(i + 1) % num_points];
            f32 new_path = fog_length_v2(prev - point) + fog_length_v2(next - point);
            f32 change = new_path;
            if (change < best_dist) {
                best_index = (i + 1) % num_points;
                best_dist = change;
            }
        }
        points->insert(points->begin() + best_index, point);
    }

    if (fog_input_pressed((u32) In::EDIT_SAVE, Player::ANY)) {
        FILE *file = fopen(path, "w");
        for (u32 i = 0; i < global_editor.sprites.size(); i++) {
            write_sprite_to_file(global_editor.sprites[i], file);
        }
        fclose(file);
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl $0x4, %edi
movl $0xf, %esi
callq 0x28e14
testb %al, %al
je 0x3407
movl 0x4c99b(%rip), %eax     # 0x4fd78
movq 0x4c99c(%rip), %rcx     # 0x4fd80
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq (%rcx,%rax), %rdx
addq $0x20, %rdx
leaq 0x2cd9f(%rip), %rdi     # 0x3019a
xorl %esi, %esi
movl $0x10, %ecx
callq 0x27ab
movq 0x4c97a(%rip), %rax     # 0x4fd88
subq 0x4c96b(%rip), %rax     # 0x4fd80
shrq $0x4, %rax
imull $0xaaaaaaab, %eax, %ebx # imm = 0xAAAAAAAB
movl $0x6, %edi
movl $0xf, %esi
callq 0x28e14
testb %al, %al
je 0x344a
testl %ebx, %ebx
je 0x344a
movl 0x4c93c(%rip), %eax     # 0x4fd78
addl %ebx, %eax
decl %eax
xorl %edx, %edx
divl %ebx
movl %edx, 0x4c92e(%rip)     # 0x4fd78
movl $0x5, %edi
movl $0xf, %esi
callq 0x28e14
testl %ebx, %ebx
je 0x3475
testb %al, %al
je 0x3475
movl 0x4c911(%rip), %eax     # 0x4fd78
addl %ebx, %eax
incl %eax
xorl %edx, %edx
divl %ebx
movl %edx, 0x4c903(%rip)     # 0x4fd78
callq 0x2849d
cvtss2sd %xmm0, %xmm0
movsd 0x2cbca(%rip), %xmm1    # 0x30050
ucomisd %xmm0, %xmm1
jbe 0x3493
callq 0x2849d
jmp 0x349b
movss 0x2cb71(%rip), %xmm0    # 0x3000c
movss %xmm0, -0x50(%rbp)
movl $0xd, %edi
movl $0xf, %esi
callq 0x28e32
movaps %xmm0, -0x80(%rbp)
movl $0xe, %edi
movl $0xf, %esi
callq 0x28e32
movaps %xmm0, -0x90(%rbp)
callq 0x28da7
testb %al, %al
je 0x34e3
movl $0xf, %edi
movl $0xf, %esi
callq 0x28e32
jmp 0x34f4
callq 0x28f23
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
mulss 0x2cb1c(%rip), %xmm0    # 0x30010
mulss -0x50(%rbp), %xmm0
addss 0x2cb03(%rip), %xmm0    # 0x30004
movaps %xmm0, -0x40(%rbp)
xorl %edi, %edi
callq 0x29145
movaps -0x40(%rbp), %xmm0
mulss 0x10(%rax), %xmm0
movss %xmm0, 0x10(%rax)
xorl %edi, %edi
callq 0x29145
movss 0x10(%rax), %xmm0
movss %xmm0, -0x60(%rbp)
callq 0x28da7
testb %al, %al
je 0x353e
movsd 0x4c85c(%rip), %xmm0    # 0x4fd98
jmp 0x3545
xorl %edi, %edi
callq 0x28e87
movaps %xmm0, -0x40(%rbp)
movss 0x4c84f(%rip), %xmm0    # 0x4fda0
divss -0x60(%rbp), %xmm0
movss %xmm0, 0x4c846(%rip)    # 0x4fda4
movl $0x9, %edi
movl $0xf, %esi
callq 0x28e14
testb %al, %al
je 0x3589
movss 0x4c833(%rip), %xmm0    # 0x4fdac
mulss 0x4c827(%rip), %xmm0    # 0x4fda8
movss %xmm0, 0x4c81f(%rip)    # 0x4fda8
movl $0xa, %edi
movl $0xf, %esi
callq 0x28e14
movss 0x4c808(%rip), %xmm0    # 0x4fda8
testb %al, %al
je 0x35b4
divss 0x4c800(%rip), %xmm0    # 0x4fdac
movss %xmm0, 0x4c7f4(%rip)    # 0x4fda8
cvtss2sd %xmm0, %xmm0
movsd 0x2ca98(%rip), %xmm1    # 0x30058
minsd %xmm0, %xmm1
movsd 0x2ca94(%rip), %xmm0    # 0x30060
maxsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x4c7cc(%rip)    # 0x4fda8
movl $0x10, %edi
movl $0xf, %esi
callq 0x28e28
testb %al, %al
je 0x364d
movss 0x4c7b1(%rip), %xmm3    # 0x4fda8
movss -0x50(%rbp), %xmm0
addss 0x4c7b4(%rip), %xmm0    # 0x4fdb8
movss %xmm0, 0x4c7ac(%rip)    # 0x4fdb8
cvtss2sd %xmm0, %xmm0
ucomisd 0x2ca50(%rip), %xmm0    # 0x30068
movss %xmm3, -0x60(%rbp)
jbe 0x3754
movaps 0x2ca16(%rip), %xmm0    # 0x30040
movaps -0x80(%rbp), %xmm1
xorps %xmm1, %xmm0
ucomiss %xmm0, %xmm1
ja 0x3698
cvtss2sd %xmm0, %xmm0
ucomisd 0x2ca2e(%rip), %xmm0    # 0x30070
ja 0x3698
movaps -0x40(%rbp), %xmm2
jmp 0x36d7
movss -0x50(%rbp), %xmm0
divss -0x60(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movaps -0x80(%rbp), %xmm0
movaps -0x90(%rbp), %xmm1
callq 0x28631
movss -0x50(%rbp), %xmm1
movaps %xmm1, %xmm5
mulss %xmm0, %xmm5
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
mulss %xmm1, %xmm0
movaps -0x40(%rbp), %xmm1
addss %xmm1, %xmm5
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
addss %xmm0, %xmm1
unpcklps %xmm1, %xmm5            # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1]
jmp 0x37cd
xorps %xmm0, %xmm0
movaps -0x80(%rbp), %xmm1
ucomiss %xmm0, %xmm1
movaps -0x40(%rbp), %xmm2
ja 0x36b9
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
mulsd 0x2c9c1(%rip), %xmm0    # 0x30078
jmp 0x36c1
movsd 0x2c9bf(%rip), %xmm0    # 0x30080
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
subsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, %xmm2            # xmm2 = xmm0[0],xmm2[1,2,3]
movaps 0x2c962(%rip), %xmm0    # 0x30040
movaps -0x90(%rbp), %xmm1
xorps %xmm1, %xmm0
ucomiss %xmm0, %xmm1
ja 0x3701
cvtss2sd %xmm0, %xmm0
ucomisd 0x2c977(%rip), %xmm0    # 0x30070
ja 0x3701
movaps %xmm2, -0x40(%rbp)
jmp 0x374a
xorps %xmm0, %xmm0
movaps -0x90(%rbp), %xmm1
ucomiss %xmm0, %xmm1
ja 0x3721
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
mulsd 0x2c959(%rip), %xmm0    # 0x30078
jmp 0x3729
movsd 0x2c957(%rip), %xmm0    # 0x30080
movaps %xmm2, %xmm1
shufps $0x55, %xmm2, %xmm1     # xmm1 = xmm1[1,1],xmm2[1,1]
cvtss2sd %xmm1, %xmm1
subsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movlhps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
shufps $0xe2, %xmm2, %xmm0     # xmm0 = xmm0[2,0],xmm2[2,3]
movaps %xmm0, -0x40(%rbp)
movl $0x0, 0x4c664(%rip)     # 0x4fdb8
movl $0x11, %edi
movl $0xf, %esi
callq 0x28e28
movaps -0x40(%rbp), %xmm0
movss -0x60(%rbp), %xmm1
divss %xmm1, %xmm0
addss 0x2c890(%rip), %xmm0    # 0x30008
cvttss2si %xmm0, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
mulss %xmm1, %xmm0
movaps %xmm0, -0x50(%rbp)
movl $0x11, %edi
movl $0xf, %esi
callq 0x28e28
movaps -0x50(%rbp), %xmm5
movaps -0x40(%rbp), %xmm0
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movss -0x60(%rbp), %xmm1
divss %xmm1, %xmm0
addss 0x2c84f(%rip), %xmm0    # 0x30008
cvttss2si %xmm0, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
mulss %xmm1, %xmm0
unpcklps %xmm0, %xmm5            # xmm5 = xmm5[0],xmm0[0],xmm5[1],xmm0[1]
xorps %xmm0, %xmm0
cvtss2sd %xmm5, %xmm0
movsd 0x2c89c(%rip), %xmm2    # 0x30078
movapd %xmm2, %xmm4
minsd %xmm0, %xmm4
movsd 0x2c89c(%rip), %xmm3    # 0x30088
ucomisd %xmm4, %xmm3
movss 0x2c81c(%rip), %xmm1    # 0x30014
movaps %xmm1, %xmm0
ja 0x3804
xorps %xmm0, %xmm0
cvtsd2ss %xmm4, %xmm0
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
xorps %xmm4, %xmm4
cvtss2sd %xmm5, %xmm4
minsd %xmm4, %xmm2
ucomisd %xmm2, %xmm3
ja 0x3820
xorps %xmm1, %xmm1
cvtsd2ss %xmm2, %xmm1
callq 0x28631
movlps %xmm0, 0x4c56c(%rip)    # 0x4fd98
movaps %xmm0, -0x50(%rbp)
movlps %xmm0, -0xb8(%rbp)
movl $0xc, %edi
movl $0xf, %esi
callq 0x28e14
testb %al, %al
je 0x384f
callq 0x2ac0
xorl %edi, %edi
callq 0x29145
movss 0x4c54a(%rip), %xmm0    # 0x4fda8
movss %xmm0, -0x64(%rbp)
xorps %xmm0, %xmm0
cvtss2sd 0x10(%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
movss 0x2c789(%rip), %xmm0    # 0x30004
movss 0x2c795(%rip), %xmm3    # 0x30018
xorps %xmm1, %xmm1
movaps %xmm0, %xmm2
callq 0x28646
movaps %xmm0, -0x60(%rbp)
movaps %xmm1, -0x90(%rbp)
movss 0x2c76b(%rip), %xmm3    # 0x3000c
xorps %xmm1, %xmm1
movss 0x2c758(%rip), %xmm0    # 0x30004
movaps %xmm0, %xmm2
callq 0x28646
movaps %xmm0, -0x40(%rbp)
movaps %xmm1, -0x80(%rbp)
movl $0x10, %edi
movl $0xf, %esi
callq 0x28e28
testb %al, %al
je 0x38e2
movaps -0x40(%rbp), %xmm0
movaps %xmm0, -0x60(%rbp)
movaps -0x80(%rbp), %xmm0
movaps %xmm0, -0x90(%rbp)
movss -0x64(%rbp), %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd 0x2c762(%rip), %xmm1    # 0x30058
divsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jb 0x39ef
movsd 0x2c780(%rip), %xmm0    # 0x30090
divsd -0xa8(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x80(%rbp)
xorl %ebx, %ebx
movsd %xmm1, -0xb0(%rbp)
movl %ebx, %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
mulss %xmm2, %xmm0
movss %xmm0, -0x40(%rbp)
xorpd %xmm1, %xmm1
callq 0x28631
movaps %xmm0, -0xa0(%rbp)
movss -0x40(%rbp), %xmm0
movss 0x2c6a9(%rip), %xmm1    # 0x30004
callq 0x28631
movaps %xmm0, %xmm1
movl $0x5, %edi
movaps -0xa0(%rbp), %xmm0
movaps -0x60(%rbp), %xmm2
movaps -0x90(%rbp), %xmm3
movss -0x80(%rbp), %xmm4
callq 0x29444
xorps %xmm0, %xmm0
movss -0x40(%rbp), %xmm1
callq 0x28631
movaps %xmm0, -0xa0(%rbp)
movss 0x2c664(%rip), %xmm0    # 0x30004
movss -0x40(%rbp), %xmm1
callq 0x28631
movaps %xmm0, %xmm1
movl $0x5, %edi
movaps -0xa0(%rbp), %xmm0
movaps -0x60(%rbp), %xmm2
movaps -0x90(%rbp), %xmm3
movss -0x80(%rbp), %xmm4
callq 0x29444
movss -0x64(%rbp), %xmm2
movsd -0xb0(%rbp), %xmm1
incl %ebx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
ucomisd %xmm0, %xmm1
jae 0x392b
movss 0x2c60d(%rip), %xmm1    # 0x30004
xorps %xmm0, %xmm0
xorps %xmm2, %xmm2
movaps %xmm1, %xmm3
callq 0x28646
movaps %xmm0, %xmm2
movaps %xmm1, %xmm4
movsd 0x2c685(%rip), %xmm0    # 0x30098
divsd -0xa8(%rbp), %xmm0
xorps %xmm3, %xmm3
cvtsd2ss %xmm0, %xmm3
movl $0xa, %edi
movaps -0x50(%rbp), %xmm0
movaps %xmm2, %xmm1
movaps %xmm4, %xmm2
callq 0x29457
xorl %edi, %edi
callq 0x29145
movq %rax, %rbx
movsd (%rax), %xmm0
movaps -0x50(%rbp), %xmm1
callq 0x286b0
movss 0x10(%rbx), %xmm2
movss 0x2c5ae(%rip), %xmm1    # 0x30008
divss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x3ab1
subss %xmm1, %xmm0
mulss 0x2c5ad(%rip), %xmm0    # 0x3001c
mulss %xmm0, %xmm2
movss %xmm2, -0x40(%rbp)
callq 0x2849d
mulss -0x40(%rbp), %xmm0
movsd (%rbx), %xmm1
movaps -0x50(%rbp), %xmm2
subps %xmm1, %xmm2
movaps %xmm0, %xmm3
mulss %xmm2, %xmm3
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
mulss %xmm0, %xmm2
addss %xmm1, %xmm3
movss %xmm3, (%rbx)
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
addss %xmm2, %xmm1
movss %xmm1, 0x4(%rbx)
movl 0x4c2c1(%rip), %eax     # 0x4fd78
movq 0x4c2c2(%rip), %rbx     # 0x4fd80
leaq (%rax,%rax,2), %r15
shlq $0x4, %r15
movq 0x18(%rbx,%r15), %r14
movl $0x7, %edi
movl $0xf, %esi
callq 0x28e14
testb %al, %al
je 0x3aee
movq %r14, %rdi
movl $0x1, %esi
callq 0x29db
movq %rax, %r14
movl $0x8, %edi
movl $0xf, %esi
callq 0x28e14
testb %al, %al
je 0x3b11
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x29db
movq %rax, %r14
addq %r15, %rbx
cmpq $-0x1, %r14
je 0x3b1e
movq %r14, 0x18(%rbx)
movabsq $0x7fffffff8, %r14      # imm = 0x7FFFFFFF8
movl $0x2, %edi
movl $0xf, %esi
callq 0x28e28
testb %al, %al
jne 0x3b46
xorl %edi, %edi
callq 0x28f86
testb %al, %al
je 0x3baf
movq 0x8(%rbx), %rax
subq (%rbx), %rax
testq %r14, %rax
je 0x3baf
shrq $0x3, %rax
movss 0x4c246(%rip), %xmm0    # 0x4fda4
movl %eax, %r12d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movss %xmm0, -0x40(%rbp)
movq (%rbx), %rax
movsd (%rax,%r13,8), %xmm1
movaps -0x50(%rbp), %xmm0
subps %xmm1, %xmm0
callq 0x28694
movss -0x40(%rbp), %xmm1
ucomiss %xmm0, %xmm1
cmoval %r13d, %r15d
minss %xmm1, %xmm0
incq %r13
cmpq %r13, %r12
jne 0x3b6a
testl %r15d, %r15d
js 0x3baf
movl %r15d, %eax
movq (%rbx), %rcx
movaps -0x50(%rbp), %xmm0
movlps %xmm0, (%rcx,%rax,8)
movl $0x3, %edi
movl $0xf, %esi
callq 0x28e14
testb %al, %al
jne 0x3bd4
movl $0x3, %edi
callq 0x28f58
testb %al, %al
je 0x3c5e
movq 0x8(%rbx), %rax
subq (%rbx), %rax
testq %r14, %rax
je 0x3c5e
shrq $0x3, %rax
movss 0x4c1b8(%rip), %xmm0    # 0x4fda4
movl %eax, %r12d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movss %xmm0, -0x40(%rbp)
movq (%rbx), %rax
movsd (%rax,%r13,8), %xmm1
movaps -0x50(%rbp), %xmm0
subps %xmm1, %xmm0
callq 0x28694
movss -0x40(%rbp), %xmm1
ucomiss %xmm0, %xmm1
cmoval %r13d, %r15d
minss %xmm1, %xmm0
incq %r13
cmpq %r13, %r12
jne 0x3bf8
testl %r15d, %r15d
js 0x3c5e
movl %r15d, %eax
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
leaq (%rcx,%rax,8), %rsi
addq $0x8, %rsi
cmpq %rdx, %rsi
je 0x3c56
leaq (%rcx,%rax,8), %rdi
subq %rsi, %rdx
callq 0x2120
movq 0x8(%rbx), %rdx
addq $-0x8, %rdx
movq %rdx, 0x8(%rbx)
movl $0x1, %edi
movl $0xf, %esi
callq 0x28e14
testb %al, %al
jne 0x3c83
movl $0x2, %edi
callq 0x28f58
testb %al, %al
je 0x3d81
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
xorl %edx, %edx
testq %r14, %rcx
je 0x3d6e
shrq $0x3, %rcx
movaps -0x50(%rbp), %xmm2
movaps %xmm2, %xmm0
shufps $0x55, %xmm2, %xmm0     # xmm0 = xmm0[1,1],xmm2[1,1]
movaps %xmm0, -0x40(%rbp)
movl %ecx, %r14d
negq %r14
movss 0x2c367(%rip), %xmm0    # 0x30020
movl $0x1, %r13d
xorl %r12d, %r12d
movss %xmm0, -0x60(%rbp)
movq (%rbx), %rax
movss -0x8(%rax,%r13,8), %xmm0
movss -0x4(%rax,%r13,8), %xmm1
movq %r14, %rcx
addq %r13, %rcx
movq %rbx, %r15
movl %r13d, %ebx
cmovel %edx, %ebx
movss (%rax,%rbx,8), %xmm3
movaps %xmm3, -0x80(%rbp)
movss 0x4(%rax,%rbx,8), %xmm3
movaps %xmm3, -0x90(%rbp)
subss %xmm2, %xmm0
subss -0x40(%rbp), %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
callq 0x28694
movss %xmm0, -0xa0(%rbp)
movaps -0x80(%rbp), %xmm0
subss -0x50(%rbp), %xmm0
movaps -0x90(%rbp), %xmm1
subss -0x40(%rbp), %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
callq 0x28694
xorl %edx, %edx
movaps -0x50(%rbp), %xmm2
addss -0xa0(%rbp), %xmm0
movss -0x60(%rbp), %xmm1
ucomiss %xmm0, %xmm1
minss %xmm1, %xmm0
cmoval %ebx, %r12d
movq %r15, %rbx
leaq (%r14,%r13), %rax
incq %rax
incq %r13
cmpq $0x1, %rax
jne 0x3cc2
movq (%rbx), %rax
movslq %r12d, %rdx
leaq (%rax,%rdx,8), %rsi
leaq -0xb8(%rbp), %rdx
movq %rbx, %rdi
callq 0x44ee
movl $0xb, %edi
movl $0xf, %esi
callq 0x28e14
testb %al, %al
je 0x3e60
movq 0x4c011(%rip), %rdi     # 0x4fdb0
leaq 0x38423(%rip), %rsi     # 0x3c1c9
callq 0x2520
movq %rax, -0x50(%rbp)
movq 0x4bfca(%rip), %r13     # 0x4fd80
cmpq %r13, 0x4bfcb(%rip)     # 0x4fd88
je 0x3e57
movl $0x1, %r15d
leaq -0xd0(%rbp), %r12
xorl %eax, %eax
leaq -0xe8(%rbp), %r14
leaq (%rax,%rax,2), %rbx
shlq $0x4, %rbx
leaq (%rbx,%r13), %rsi
movq %r14, %rdi
callq 0x446e
movq 0x28(%r13,%rbx), %rax
movq %rax, 0x10(%r12)
movups 0x18(%r13,%rbx), %xmm0
movups %xmm0, (%r12)
movq %r14, %rdi
movq -0x50(%rbp), %rsi
callq 0x28ad
movq -0xe8(%rbp), %rdi
testq %rdi, %rdi
je 0x3e29
movq -0xd8(%rbp), %rsi
subq %rdi, %rsi
callq 0x20e0
movl %r15d, %eax
movq 0x4bf55(%rip), %rcx     # 0x4fd88
movq 0x4bf46(%rip), %r13     # 0x4fd80
subq %r13, %rcx
sarq $0x4, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
incl %r15d
cmpq %rax, %rcx
ja 0x3dd9
movq -0x50(%rbp), %rdi
callq 0x2270
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
testq %rdi, %rdi
je 0x3e90
movq -0xd8(%rbp), %rsi
subq %rdi, %rsi
callq 0x20e0
movq %rbx, %rdi
callq 0x2310