// File: /workspace/github_c_makefile_star2_O1/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 $0xb8, %rsp
movl $0x4, %edi
movl $0xf, %esi
callq 0x29259
testb %al, %al
je 0x34c8
movl 0x4c8ea(%rip), %eax     # 0x4fd88
movq 0x4c8eb(%rip), %rcx     # 0x4fd90
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq (%rcx,%rax), %rdx
addq $0x20, %rdx
leaq 0x2ccde(%rip), %rdi     # 0x3019a
xorl %esi, %esi
movl $0x10, %ecx
callq 0x27db
movq 0x4c8c9(%rip), %rax     # 0x4fd98
subq 0x4c8ba(%rip), %rax     # 0x4fd90
shrq $0x4, %rax
imull $0xaaaaaaab, %eax, %ebx # imm = 0xAAAAAAAB
movl $0x6, %edi
movl $0xf, %esi
callq 0x29259
testb %al, %al
je 0x350b
testl %ebx, %ebx
je 0x350b
movl 0x4c88b(%rip), %eax     # 0x4fd88
addl %ebx, %eax
decl %eax
xorl %edx, %edx
divl %ebx
movl %edx, 0x4c87d(%rip)     # 0x4fd88
movl $0x5, %edi
movl $0xf, %esi
callq 0x29259
testl %ebx, %ebx
je 0x3536
testb %al, %al
je 0x3536
movl 0x4c860(%rip), %eax     # 0x4fd88
addl %ebx, %eax
incl %eax
xorl %edx, %edx
divl %ebx
movl %edx, 0x4c852(%rip)     # 0x4fd88
callq 0x28809
cvtss2sd %xmm0, %xmm0
movsd 0x2cb09(%rip), %xmm1    # 0x30050
ucomisd %xmm0, %xmm1
jbe 0x3554
callq 0x28809
jmp 0x355c
movss 0x2cab0(%rip), %xmm0    # 0x3000c
movss %xmm0, -0x40(%rbp)
movl $0xd, %edi
movl $0xf, %esi
callq 0x29277
movaps %xmm0, -0xa0(%rbp)
movl $0xe, %edi
movl $0xf, %esi
callq 0x29277
movaps %xmm0, -0x90(%rbp)
callq 0x291ec
testb %al, %al
je 0x35a7
movl $0xf, %edi
movl $0xf, %esi
callq 0x29277
jmp 0x35b8
callq 0x29368
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
mulss 0x2ca58(%rip), %xmm0    # 0x30010
mulss -0x40(%rbp), %xmm0
addss 0x2ca3f(%rip), %xmm0    # 0x30004
movaps %xmm0, -0x60(%rbp)
xorl %edi, %edi
callq 0x2958a
movaps -0x60(%rbp), %xmm0
mulss 0x10(%rax), %xmm0
movss %xmm0, 0x10(%rax)
xorl %edi, %edi
callq 0x2958a
movss 0x10(%rax), %xmm0
movss %xmm0, -0x70(%rbp)
callq 0x291ec
testb %al, %al
je 0x3602
movsd 0x4c7a8(%rip), %xmm0    # 0x4fda8
jmp 0x3609
xorl %edi, %edi
callq 0x292cc
movaps %xmm0, -0x60(%rbp)
movss 0x4c79b(%rip), %xmm0    # 0x4fdb0
divss -0x70(%rbp), %xmm0
movss %xmm0, 0x4c792(%rip)    # 0x4fdb4
movl $0x9, %edi
movl $0xf, %esi
callq 0x29259
testb %al, %al
je 0x364d
movss 0x4c77f(%rip), %xmm0    # 0x4fdbc
mulss 0x4c773(%rip), %xmm0    # 0x4fdb8
movss %xmm0, 0x4c76b(%rip)    # 0x4fdb8
movl $0xa, %edi
movl $0xf, %esi
callq 0x29259
testb %al, %al
je 0x3678
movss 0x4c750(%rip), %xmm0    # 0x4fdb8
divss 0x4c74c(%rip), %xmm0    # 0x4fdbc
movss %xmm0, 0x4c740(%rip)    # 0x4fdb8
xorps %xmm0, %xmm0
cvtss2sd 0x4c735(%rip), %xmm0    # 0x4fdb8
movsd 0x2c9cd(%rip), %xmm1    # 0x30058
minsd %xmm0, %xmm1
movsd 0x2c9c9(%rip), %xmm0    # 0x30060
maxsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x4c711(%rip)    # 0x4fdb8
movl $0x10, %edi
movl $0xf, %esi
callq 0x2926d
testb %al, %al
je 0x371b
movss 0x4c6f6(%rip), %xmm3    # 0x4fdb8
movss -0x40(%rbp), %xmm0
addss 0x4c6f9(%rip), %xmm0    # 0x4fdc8
movss %xmm0, 0x4c6f1(%rip)    # 0x4fdc8
cvtss2sd %xmm0, %xmm0
ucomisd 0x2c985(%rip), %xmm0    # 0x30068
movss %xmm3, -0x70(%rbp)
jbe 0x3828
movaps 0x2c94b(%rip), %xmm0    # 0x30040
movaps -0xa0(%rbp), %xmm1
xorps %xmm1, %xmm0
ucomiss %xmm0, %xmm1
ja 0x3769
cvtss2sd %xmm0, %xmm0
ucomisd 0x2c960(%rip), %xmm0    # 0x30070
ja 0x3769
movaps -0x60(%rbp), %xmm2
jmp 0x37ab
movss -0x40(%rbp), %xmm0
divss -0x70(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
movaps -0xa0(%rbp), %xmm0
movaps -0x90(%rbp), %xmm1
callq 0x2899d
movss -0x40(%rbp), %xmm1
movaps %xmm1, %xmm5
mulss %xmm0, %xmm5
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
mulss %xmm1, %xmm0
movaps -0x60(%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 0x38a1
xorps %xmm0, %xmm0
movaps -0xa0(%rbp), %xmm1
ucomiss %xmm0, %xmm1
movaps -0x60(%rbp), %xmm2
ja 0x378d
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
mulsd 0x2c8ed(%rip), %xmm0    # 0x30078
jmp 0x3795
movsd 0x2c8eb(%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 0x2c88e(%rip), %xmm0    # 0x30040
movaps -0x90(%rbp), %xmm1
xorps %xmm1, %xmm0
ucomiss %xmm0, %xmm1
ja 0x37d5
cvtss2sd %xmm0, %xmm0
ucomisd 0x2c8a3(%rip), %xmm0    # 0x30070
ja 0x37d5
movaps %xmm2, -0x60(%rbp)
jmp 0x381e
xorps %xmm0, %xmm0
movaps -0x90(%rbp), %xmm1
ucomiss %xmm0, %xmm1
ja 0x37f5
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
mulsd 0x2c885(%rip), %xmm0    # 0x30078
jmp 0x37fd
movsd 0x2c883(%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, -0x60(%rbp)
movl $0x0, 0x4c5a0(%rip)     # 0x4fdc8
movl $0x11, %edi
movl $0xf, %esi
callq 0x2926d
movaps -0x60(%rbp), %xmm0
movss -0x70(%rbp), %xmm1
divss %xmm1, %xmm0
addss 0x2c7bc(%rip), %xmm0    # 0x30008
cvttss2si %xmm0, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
mulss %xmm1, %xmm0
movaps %xmm0, -0x40(%rbp)
movl $0x11, %edi
movl $0xf, %esi
callq 0x2926d
movaps -0x40(%rbp), %xmm5
movaps -0x60(%rbp), %xmm0
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movss -0x70(%rbp), %xmm1
divss %xmm1, %xmm0
addss 0x2c77b(%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 0x2c7c8(%rip), %xmm2    # 0x30078
movapd %xmm2, %xmm4
minsd %xmm0, %xmm4
movsd 0x2c7c8(%rip), %xmm3    # 0x30088
ucomisd %xmm4, %xmm3
movss 0x2c748(%rip), %xmm1    # 0x30014
movaps %xmm1, %xmm0
ja 0x38d8
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 0x38f4
xorps %xmm1, %xmm1
cvtsd2ss %xmm2, %xmm1
callq 0x2899d
movlps %xmm0, 0x4c4a8(%rip)    # 0x4fda8
movlps %xmm0, -0x48(%rbp)
movl $0xc, %edi
movl $0xf, %esi
callq 0x29259
testb %al, %al
je 0x391c
callq 0x2b17
xorl %edi, %edi
callq 0x2958a
movss 0x4c48d(%rip), %xmm0    # 0x4fdb8
movss %xmm0, -0x74(%rbp)
xorps %xmm0, %xmm0
cvtss2sd 0x10(%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
movss 0x2c6bc(%rip), %xmm0    # 0x30004
movss 0x2c6c8(%rip), %xmm3    # 0x30018
xorps %xmm1, %xmm1
movaps %xmm0, %xmm2
callq 0x289b2
movaps %xmm0, -0x60(%rbp)
movaps %xmm1, -0x70(%rbp)
movss 0x2c6a1(%rip), %xmm3    # 0x3000c
xorps %xmm1, %xmm1
movss 0x2c68e(%rip), %xmm0    # 0x30004
movaps %xmm0, %xmm2
callq 0x289b2
movaps %xmm0, -0x40(%rbp)
movaps %xmm1, -0x90(%rbp)
movl $0x10, %edi
movl $0xf, %esi
callq 0x2926d
testb %al, %al
je 0x39af
movaps -0x40(%rbp), %xmm0
movaps %xmm0, -0x60(%rbp)
movaps -0x90(%rbp), %xmm0
movaps %xmm0, -0x70(%rbp)
movss -0x74(%rbp), %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd 0x2c695(%rip), %xmm1    # 0x30058
divsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jb 0x3abf
movsd 0x2c6b3(%rip), %xmm0    # 0x30090
divsd -0xa8(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x90(%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 0x2899d
movaps %xmm0, -0xa0(%rbp)
movss -0x40(%rbp), %xmm0
movss 0x2c5d9(%rip), %xmm1    # 0x30004
callq 0x2899d
movaps %xmm0, %xmm1
movl $0x5, %edi
movaps -0xa0(%rbp), %xmm0
movaps -0x60(%rbp), %xmm2
movaps -0x70(%rbp), %xmm3
movss -0x90(%rbp), %xmm4
callq 0x29889
xorps %xmm0, %xmm0
movss -0x40(%rbp), %xmm1
callq 0x2899d
movaps %xmm0, -0xa0(%rbp)
movss 0x2c594(%rip), %xmm0    # 0x30004
movss -0x40(%rbp), %xmm1
callq 0x2899d
movaps %xmm0, %xmm1
movl $0x5, %edi
movaps -0xa0(%rbp), %xmm0
movaps -0x60(%rbp), %xmm2
movaps -0x70(%rbp), %xmm3
movss -0x90(%rbp), %xmm4
callq 0x29889
movss -0x74(%rbp), %xmm2
movsd -0xb0(%rbp), %xmm1
incl %ebx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
ucomisd %xmm0, %xmm1
jae 0x39fb
movss 0x2c53d(%rip), %xmm1    # 0x30004
xorps %xmm0, %xmm0
xorps %xmm2, %xmm2
movaps %xmm1, %xmm3
callq 0x289b2
movaps %xmm0, %xmm2
movaps %xmm1, %xmm4
movsd -0x48(%rbp), %xmm0
movsd 0x2c5b0(%rip), %xmm1    # 0x30098
divsd -0xa8(%rbp), %xmm1
xorps %xmm3, %xmm3
cvtsd2ss %xmm1, %xmm3
movl $0xa, %edi
movaps %xmm2, %xmm1
movaps %xmm4, %xmm2
callq 0x2989c
xorl %edi, %edi
callq 0x2958a
movq %rax, %rbx
movsd (%rax), %xmm0
movsd -0x48(%rbp), %xmm1
callq 0x28a2a
movss 0x10(%rbx), %xmm2
movss 0x2c4dc(%rip), %xmm1    # 0x30008
divss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x3b88
subss %xmm1, %xmm0
mulss 0x2c4db(%rip), %xmm0    # 0x3001c
mulss %xmm0, %xmm2
movss %xmm2, -0x40(%rbp)
callq 0x28809
mulss -0x40(%rbp), %xmm0
movsd (%rbx), %xmm1
movss -0x48(%rbp), %xmm2
movss -0x44(%rbp), %xmm3
subss %xmm1, %xmm2
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
subss %xmm1, %xmm3
mulss %xmm0, %xmm2
mulss %xmm0, %xmm3
addss (%rbx), %xmm2
movss %xmm2, (%rbx)
addss 0x4(%rbx), %xmm3
movss %xmm3, 0x4(%rbx)
movl 0x4c1fa(%rip), %eax     # 0x4fd88
movq 0x4c1fb(%rip), %rbx     # 0x4fd90
leaq (%rax,%rax,2), %r15
shlq $0x4, %r15
movq 0x18(%rbx,%r15), %r14
movl $0x7, %edi
movl $0xf, %esi
callq 0x29259
testb %al, %al
je 0x3bc5
movq %r14, %rdi
movl $0x1, %esi
callq 0x2a2c
movq %rax, %r14
movl $0x8, %edi
movl $0xf, %esi
callq 0x29259
testb %al, %al
je 0x3be8
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2a2c
movq %rax, %r14
addq %r15, %rbx
cmpq $-0x1, %r14
je 0x3bf5
movq %r14, 0x18(%rbx)
movabsq $0x7fffffff8, %r15      # imm = 0x7FFFFFFF8
movl $0x2, %edi
movl $0xf, %esi
callq 0x2926d
testb %al, %al
jne 0x3c21
xorl %edi, %edi
callq 0x293cb
testb %al, %al
je 0x3ca4
movq 0x8(%rbx), %rax
subq (%rbx), %rax
testq %r15, %rax
je 0x3c8b
shrq $0x3, %rax
movss 0x4c17b(%rip), %xmm0    # 0x4fdb4
movl %eax, %r12d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movss %xmm0, -0x40(%rbp)
movq (%rbx), %rax
movsd (%rax,%r13,8), %xmm1
movss -0x48(%rbp), %xmm0
movss -0x44(%rbp), %xmm2
subss %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
subss %xmm1, %xmm2
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
callq 0x28a00
movss -0x40(%rbp), %xmm1
ucomiss %xmm0, %xmm1
cmoval %r13d, %r14d
minss %xmm1, %xmm0
incq %r13
cmpq %r13, %r12
jne 0x3c45
jmp 0x3c91
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testl %r14d, %r14d
js 0x3ca4
movl %r14d, %eax
movq (%rbx), %rcx
movq -0x48(%rbp), %rdx
movq %rdx, (%rcx,%rax,8)
movl $0x3, %edi
movl $0xf, %esi
callq 0x29259
testb %al, %al
jne 0x3cc9
movl $0x3, %edi
callq 0x2939d
testb %al, %al
je 0x3d66
movq 0x8(%rbx), %rax
subq (%rbx), %rax
testq %r15, %rax
je 0x3d33
shrq $0x3, %rax
movss 0x4c0d3(%rip), %xmm0    # 0x4fdb4
movl %eax, %r12d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movss %xmm0, -0x40(%rbp)
movq (%rbx), %rax
movsd (%rax,%r13,8), %xmm1
movss -0x48(%rbp), %xmm0
movss -0x44(%rbp), %xmm2
subss %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
subss %xmm1, %xmm2
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
callq 0x28a00
movss -0x40(%rbp), %xmm1
ucomiss %xmm0, %xmm1
cmoval %r13d, %r14d
minss %xmm1, %xmm0
incq %r13
cmpq %r13, %r12
jne 0x3ced
jmp 0x3d39
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testl %r14d, %r14d
js 0x3d66
movl %r14d, %eax
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
leaq (%rcx,%rax,8), %rsi
addq $0x8, %rsi
cmpq %rdx, %rsi
je 0x3d61
leaq (%rcx,%rax,8), %rdi
subq %rsi, %rdx
callq 0x2120
addq $-0x8, 0x8(%rbx)
movl $0x1, %edi
movl $0xf, %esi
callq 0x29259
testb %al, %al
jne 0x3d8b
movl $0x2, %edi
callq 0x2939d
testb %al, %al
je 0x3e7c
movq 0x8(%rbx), %rax
subq (%rbx), %rax
xorl %esi, %esi
testq %r15, %rax
je 0x3e69
shrq $0x3, %rax
movl %eax, %r15d
negq %r15
movss 0x2c271(%rip), %xmm0    # 0x30020
movl $0x1, %r12d
xorl %r13d, %r13d
movss %xmm0, -0x40(%rbp)
movq (%rbx), %rax
movss -0x8(%rax,%r12,8), %xmm0
movq %r15, %rcx
addq %r12, %rcx
movq %rbx, %r14
movl %r12d, %ebx
cmovel %esi, %ebx
movss -0x4(%rax,%r12,8), %xmm1
movss (%rax,%rbx,8), %xmm2
movaps %xmm2, -0x70(%rbp)
movss 0x4(%rax,%rbx,8), %xmm2
movaps %xmm2, -0x60(%rbp)
movsd -0x48(%rbp), %xmm2
subss %xmm2, %xmm0
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
subss %xmm2, %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
callq 0x28a00
movss %xmm0, -0x90(%rbp)
movsd -0x48(%rbp), %xmm0
movaps -0x70(%rbp), %xmm1
subss %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps -0x60(%rbp), %xmm2
subss %xmm0, %xmm2
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movaps %xmm1, %xmm0
callq 0x28a00
xorl %esi, %esi
addss -0x90(%rbp), %xmm0
movss -0x40(%rbp), %xmm1
ucomiss %xmm0, %xmm1
minss %xmm1, %xmm0
cmoval %ebx, %r13d
movq %r14, %rbx
leaq (%r15,%r12), %rax
incq %rax
incq %r12
cmpq $0x1, %rax
jne 0x3db8
movslq %r13d, %rsi
shlq $0x3, %rsi
addq (%rbx), %rsi
leaq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x45d2
movl $0xb, %edi
movl $0xf, %esi
callq 0x29259
testb %al, %al
je 0x3f5b
movq 0x4bf26(%rip), %rdi     # 0x4fdc0
leaq 0x38338(%rip), %rsi     # 0x3c1d9
callq 0x2530
movq %rax, -0x40(%rbp)
movq 0x4bedf(%rip), %r13     # 0x4fd90
cmpq %r13, 0x4bee0(%rip)     # 0x4fd98
je 0x3f52
movl $0x1, %r15d
leaq -0xc8(%rbp), %r12
xorl %eax, %eax
leaq -0xe0(%rbp), %r14
leaq (%rax,%rax,2), %rbx
shlq $0x4, %rbx
leaq (%rbx,%r13), %rsi
movq %r14, %rdi
callq 0x4552
movq 0x28(%r13,%rbx), %rax
movq %rax, 0x10(%r12)
movups 0x18(%r13,%rbx), %xmm0
movups %xmm0, (%r12)
movq %r14, %rdi
movq -0x40(%rbp), %rsi
callq 0x28dd
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x3f24
movq -0xd0(%rbp), %rsi
subq %rdi, %rsi
callq 0x20e0
movl %r15d, %eax
movq 0x4be6a(%rip), %rcx     # 0x4fd98
movq 0x4be5b(%rip), %r13     # 0x4fd90
subq %r13, %rcx
sarq $0x4, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
incl %r15d
cmpq %rax, %rcx
ja 0x3ed4
movq -0x40(%rbp), %rdi
callq 0x2270
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x3f8b
movq -0xd0(%rbp), %rsi
subq %rdi, %rsi
callq 0x20e0
movq %rbx, %rdi
callq 0x2310