// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x4
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
testb %al, %al
je 0x319d
movl 0x47c0f(%rip), %eax     # 0x4ad88
movq 0x47c10(%rip), %rcx     # 0x4ad90
imulq $0x30, %rax, %rax
leaq (%rcx,%rax), %rdx
addq $0x20, %rdx
leaq 0x28007(%rip), %rdi     # 0x2b19a
pushq $0x10
popq %rcx
xorl %esi, %esi
callq 0x2748
movq 0x47bf4(%rip), %rax     # 0x4ad98
subq 0x47be5(%rip), %rax     # 0x4ad90
pushq $0x30
popq %r12
cqto
idivq %r12
movq %rax, %rbx
pushq $0x6
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
testb %al, %al
je 0x31de
testl %ebx, %ebx
je 0x31de
movl 0x47bb8(%rip), %eax     # 0x4ad88
addl %ebx, %eax
decl %eax
xorl %edx, %edx
divl %ebx
movl %edx, 0x47baa(%rip)     # 0x4ad88
pushq $0x5
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
testl %ebx, %ebx
je 0x3205
testb %al, %al
je 0x3205
movl 0x47b91(%rip), %eax     # 0x4ad88
addl %ebx, %eax
incl %eax
xorl %edx, %edx
divl %ebx
movl %edx, 0x47b83(%rip)     # 0x4ad88
callq 0x252c3
cvtss2sd %xmm0, %xmm0
movsd 0x27e3a(%rip), %xmm1    # 0x2b050
ucomisd %xmm0, %xmm1
jbe 0x3223
callq 0x252c3
jmp 0x322b
movss 0x27de1(%rip), %xmm0    # 0x2b00c
movss %xmm0, -0x40(%rbp)
pushq $0xd
popq %rdi
pushq $0xf
popq %rbx
movl %ebx, %esi
callq 0x2573b
movaps %xmm0, -0x60(%rbp)
pushq $0xe
popq %rdi
movl %ebx, %esi
callq 0x2573b
movaps %xmm0, -0x80(%rbp)
callq 0x256ce
testb %al, %al
je 0x3264
pushq $0xf
popq %rdi
movl %edi, %esi
callq 0x2573b
jmp 0x3275
callq 0x257d4
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
mulss 0x27d9b(%rip), %xmm0    # 0x2b010
mulss -0x40(%rbp), %xmm0
addss 0x27d82(%rip), %xmm0    # 0x2b004
movaps %xmm0, -0x50(%rbp)
xorl %edi, %edi
callq 0x258d0
movaps -0x50(%rbp), %xmm0
mulss 0x10(%rax), %xmm0
movss %xmm0, 0x10(%rax)
xorl %edi, %edi
callq 0x258d0
movd 0x10(%rax), %xmm0
movd %xmm0, -0x50(%rbp)
callq 0x256ce
testb %al, %al
je 0x32be
movq 0x47aec(%rip), %rbx     # 0x4ada8
jmp 0x32ca
xorl %edi, %edi
callq 0x25790
movq %xmm0, %rbx
movq %rbx, -0x88(%rbp)
movss 0x47ad7(%rip), %xmm0    # 0x4adb0
divss -0x50(%rbp), %xmm0
movss %xmm0, 0x47ace(%rip)    # 0x4adb4
pushq $0x9
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
movq %rbx, %r14
shrq $0x20, %r14
testb %al, %al
je 0x3314
movss 0x47ab8(%rip), %xmm0    # 0x4adbc
mulss 0x47aac(%rip), %xmm0    # 0x4adb8
movss %xmm0, 0x47aa4(%rip)    # 0x4adb8
pushq $0xa
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
movss 0x47a91(%rip), %xmm0    # 0x4adb8
testb %al, %al
je 0x333b
divss 0x47a89(%rip), %xmm0    # 0x4adbc
movss %xmm0, 0x47a7d(%rip)    # 0x4adb8
movl %ebx, -0xa0(%rbp)
movl %r14d, -0xb0(%rbp)
cvtss2sd %xmm0, %xmm0
movsd 0x27d04(%rip), %xmm1    # 0x2b058
movsd %xmm1, -0x68(%rbp)
minsd %xmm0, %xmm1
movsd 0x27cfb(%rip), %xmm0    # 0x2b060
maxsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x47a43(%rip)    # 0x4adb8
pushq $0x10
popq %rdi
pushq $0xf
popq %rsi
callq 0x25731
testb %al, %al
je 0x33fe
movss -0xa0(%rbp), %xmm4
movss -0xb0(%rbp), %xmm2
movss 0x47a1c(%rip), %xmm3    # 0x4adb8
movss -0x40(%rbp), %xmm0
addss 0x47a1f(%rip), %xmm0    # 0x4adc8
movss %xmm0, 0x47a17(%rip)    # 0x4adc8
cvtss2sd %xmm0, %xmm0
ucomisd 0x27cab(%rip), %xmm0    # 0x2b068
jbe 0x34bd
movaps 0x27c76(%rip), %xmm0    # 0x2b040
movaps -0x60(%rbp), %xmm1
xorps %xmm1, %xmm0
ucomiss %xmm0, %xmm1
ja 0x33e4
cvtss2sd %xmm0, %xmm0
ucomisd 0x27c8e(%rip), %xmm0    # 0x2b070
jbe 0x345f
xorps %xmm0, %xmm0
movaps -0x60(%rbp), %xmm1
ucomiss %xmm0, %xmm1
ja 0x3443
cvtss2sd %xmm3, %xmm0
mulsd 0x27c7c(%rip), %xmm0    # 0x2b078
jmp 0x344b
movss -0x40(%rbp), %xmm0
divss -0x50(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
movaps -0x60(%rbp), %xmm0
movaps -0x80(%rbp), %xmm1
callq 0x2530a
movss -0x40(%rbp), %xmm2
movaps %xmm2, %xmm1
mulss %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
mulss %xmm2, %xmm0
addss -0xa0(%rbp), %xmm1
addss -0xb0(%rbp), %xmm0
jmp 0x34f4
movsd 0x27c35(%rip), %xmm0    # 0x2b080
cvtss2sd %xmm4, %xmm1
subsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, -0x88(%rbp)
movaps 0x27bda(%rip), %xmm0    # 0x2b040
movaps -0x80(%rbp), %xmm1
xorps %xmm1, %xmm0
ucomiss %xmm0, %xmm1
ja 0x3480
cvtss2sd %xmm0, %xmm0
ucomisd 0x27bf2(%rip), %xmm0    # 0x2b070
jbe 0x34b6
xorps %xmm0, %xmm0
movaps -0x80(%rbp), %xmm1
ucomiss %xmm0, %xmm1
ja 0x349a
cvtss2sd %xmm3, %xmm0
mulsd 0x27be0(%rip), %xmm0    # 0x2b078
jmp 0x34a2
movsd 0x27bde(%rip), %xmm0    # 0x2b080
cvtss2sd %xmm2, %xmm1
subsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, -0x84(%rbp)
andl $0x0, 0x4790b(%rip)     # 0x4adc8
leaq -0x88(%rbp), %rdi
movaps %xmm3, %xmm0
movaps %xmm3, %xmm1
movss %xmm3, -0x40(%rbp)
callq 0x29cd
leaq -0x84(%rbp), %rbx
movq %rbx, %rdi
movss -0x40(%rbp), %xmm0
movaps %xmm0, %xmm1
callq 0x29cd
movss -0x4(%rbx), %xmm1
movss (%rbx), %xmm0
cvtss2sd %xmm1, %xmm1
movsd 0x27b78(%rip), %xmm3    # 0x2b078
movapd %xmm3, %xmm5
minsd %xmm1, %xmm5
movsd 0x27b78(%rip), %xmm4    # 0x2b088
ucomisd %xmm5, %xmm4
movss 0x27af8(%rip), %xmm1    # 0x2b014
movaps %xmm1, %xmm2
ja 0x3525
cvtsd2ss %xmm5, %xmm2
cvtss2sd %xmm0, %xmm0
minsd %xmm0, %xmm3
ucomisd %xmm3, %xmm4
ja 0x3537
cvtsd2ss %xmm3, %xmm1
movaps %xmm2, %xmm0
callq 0x2530a
movlps %xmm0, 0x47862(%rip)    # 0x4ada8
movaps %xmm0, -0x50(%rbp)
movlps %xmm0, -0xc0(%rbp)
pushq $0xc
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
testb %al, %al
je 0x3565
callq 0x2a22
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x258d0
movss 0x47841(%rip), %xmm0    # 0x4adb8
movss %xmm0, -0x6c(%rbp)
cvtss2sd 0x10(%rax), %xmm0
movsd 0x27b07(%rip), %xmm1    # 0x2b090
movsd %xmm0, -0xb8(%rbp)
divsd %xmm0, %xmm1
movsd %xmm1, -0x40(%rbp)
movss 0x27a62(%rip), %xmm0    # 0x2b004
movss 0x27a6e(%rip), %xmm3    # 0x2b018
xorpd %xmm1, %xmm1
movaps %xmm0, %xmm2
callq 0x2531f
movaps %xmm0, -0xb0(%rbp)
movapd %xmm1, -0xa0(%rbp)
movss 0x27a3f(%rip), %xmm3    # 0x2b00c
xorpd %xmm1, %xmm1
movss 0x27a2b(%rip), %xmm0    # 0x2b004
movaps %xmm0, %xmm2
callq 0x2531f
movaps %xmm0, -0x80(%rbp)
movapd %xmm1, -0x60(%rbp)
pushq $0x10
popq %rdi
pushq $0xf
popq %rsi
callq 0x25731
testb %al, %al
je 0x360f
movaps -0x80(%rbp), %xmm0
movaps %xmm0, -0xb0(%rbp)
movaps -0x60(%rbp), %xmm0
movaps %xmm0, -0xa0(%rbp)
cvtsd2ss -0x40(%rbp), %xmm0
movss %xmm0, -0x80(%rbp)
cvtss2sd -0x6c(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x68(%rbp)
pushq $0x5
popq %rbx
movl %r14d, %eax
cvtsi2sd %rax, %xmm0
movsd -0x68(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x36e2
cvtsi2ss %rax, %xmm0
mulss -0x6c(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
xorpd %xmm1, %xmm1
callq 0x2530a
movaps %xmm0, -0x60(%rbp)
movss -0x40(%rbp), %xmm0
movss 0x27995(%rip), %xmm1    # 0x2b004
callq 0x2530a
movaps %xmm0, %xmm1
movl %ebx, %edi
movaps -0x60(%rbp), %xmm0
movaps -0xb0(%rbp), %xmm2
movaps -0xa0(%rbp), %xmm3
movss -0x80(%rbp), %xmm4
callq 0x25a6d
xorps %xmm0, %xmm0
movss -0x40(%rbp), %xmm1
callq 0x2530a
movaps %xmm0, -0x60(%rbp)
movss 0x27956(%rip), %xmm0    # 0x2b004
movss -0x40(%rbp), %xmm1
callq 0x2530a
movapd %xmm0, %xmm1
movl %ebx, %edi
movaps -0x60(%rbp), %xmm0
movaps -0xb0(%rbp), %xmm2
movaps -0xa0(%rbp), %xmm3
movss -0x80(%rbp), %xmm4
callq 0x25a6d
incl %r14d
jmp 0x362f
movss 0x2791a(%rip), %xmm1    # 0x2b004
xorps %xmm0, %xmm0
xorps %xmm2, %xmm2
movaps %xmm1, %xmm3
callq 0x2531f
movaps %xmm0, %xmm2
movaps %xmm1, %xmm4
movsd 0x27992(%rip), %xmm0    # 0x2b098
divsd -0xb8(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm3
pushq $0xa
popq %rdi
movaps -0x50(%rbp), %xmm0
movaps %xmm2, %xmm1
movaps %xmm4, %xmm2
callq 0x25a77
xorl %edi, %edi
callq 0x258d0
movq %rax, %rbx
movsd (%rax), %xmm0
movaps -0x50(%rbp), %xmm1
callq 0x25389
movss 0x10(%rbx), %xmm2
movss 0x278c0(%rip), %xmm1    # 0x2b008
divss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x379f
subss %xmm1, %xmm0
mulss 0x278bf(%rip), %xmm0    # 0x2b01c
mulss %xmm0, %xmm2
movss %xmm2, -0x40(%rbp)
callq 0x252c3
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 0x475e3(%rip), %eax     # 0x4ad88
movq 0x475e4(%rip), %rbx     # 0x4ad90
imulq $0x30, %rax, %r15
movq 0x18(%rbx,%r15), %r14
pushq $0x7
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
testb %al, %al
je 0x37d2
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x295a
movq %rax, %r14
pushq $0x8
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
testb %al, %al
je 0x37ef
pushq $-0x1
popq %rsi
movq %r14, %rdi
callq 0x295a
movq %rax, %r14
addq %r15, %rbx
cmpq $-0x1, %r14
je 0x37fc
movq %r14, 0x18(%rbx)
pushq $0x2
popq %rdi
pushq $0xf
popq %rsi
callq 0x25731
testb %al, %al
jne 0x3816
xorl %edi, %edi
callq 0x25837
testb %al, %al
je 0x387e
pushq $-0x1
popq %r14
movq 0x8(%rbx), %rax
subq (%rbx), %rax
movss 0x4758b(%rip), %xmm0    # 0x4adb4
shrq $0x3, %rax
movl %eax, %r15d
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x3867
movq (%rbx), %rax
movsd (%rax,%r12,8), %xmm1
movss %xmm0, -0x40(%rbp)
movaps -0x50(%rbp), %xmm0
subps %xmm1, %xmm0
callq 0x2536d
movss -0x40(%rbp), %xmm1
ucomiss %xmm0, %xmm1
cmoval %r12d, %r14d
minss %xmm1, %xmm0
incq %r12
jmp 0x3833
testl %r14d, %r14d
pushq $0x30
popq %r12
js 0x387e
movl %r14d, %eax
movq (%rbx), %rcx
movaps -0x50(%rbp), %xmm0
movlps %xmm0, (%rcx,%rax,8)
pushq $0x3
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
testb %al, %al
jne 0x3899
pushq $0x3
popq %rdi
callq 0x25809
testb %al, %al
je 0x3905
movss 0x47513(%rip), %xmm0    # 0x4adb4
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
movl %eax, %r15d
pushq $-0x1
popq %r14
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x38ea
movq (%rbx), %rax
movsd (%rax,%r12,8), %xmm1
movss %xmm0, -0x40(%rbp)
movaps -0x50(%rbp), %xmm0
subps %xmm1, %xmm0
callq 0x2536d
movss -0x40(%rbp), %xmm1
ucomiss %xmm0, %xmm1
cmoval %r12d, %r14d
minss %xmm1, %xmm0
incq %r12
jmp 0x38b6
testl %r14d, %r14d
pushq $0x30
popq %r12
js 0x3905
movl %r14d, %esi
shlq $0x3, %rsi
addq (%rbx), %rsi
movq %rbx, %rdi
callq 0x3fec
pushq $0x1
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
testb %al, %al
jne 0x3924
pushq $0x2
popq %rdi
callq 0x25809
testb %al, %al
je 0x3a12
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
movaps -0x50(%rbp), %xmm0
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm0, -0x40(%rbp)
movl %eax, %r14d
leaq -0x1(%r14), %rax
movq %rax, -0x68(%rbp)
movss 0x276d2(%rip), %xmm0    # 0x2b020
xorl %eax, %eax
xorl %r15d, %r15d
movq (%rbx), %rcx
cmpq %rax, %r14
je 0x39f8
movss %xmm0, -0xb0(%rbp)
movss (%rcx,%rax,8), %xmm0
movss 0x4(%rcx,%rax,8), %xmm1
movq %rbx, %r12
leaq 0x1(%rax), %rbx
cmpq %rax, -0x68(%rbp)
movl %ebx, %r13d
movl $0x0, %eax
cmovel %eax, %r13d
movss (%rcx,%r13,8), %xmm2
movaps %xmm2, -0x80(%rbp)
movss 0x4(%rcx,%r13,8), %xmm2
movaps %xmm2, -0xa0(%rbp)
subss -0x50(%rbp), %xmm0
subss -0x40(%rbp), %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
callq 0x2536d
movss %xmm0, -0x60(%rbp)
movaps -0x80(%rbp), %xmm0
subss -0x50(%rbp), %xmm0
movaps -0xa0(%rbp), %xmm1
subss -0x40(%rbp), %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
callq 0x2536d
addss -0x60(%rbp), %xmm0
movss -0xb0(%rbp), %xmm1
ucomiss %xmm0, %xmm1
cmoval %r13d, %r15d
minss %xmm1, %xmm0
movq %rbx, %rax
movq %r12, %rbx
jmp 0x3953
movslq %r15d, %rax
leaq (%rcx,%rax,8), %rsi
leaq -0xc0(%rbp), %rdx
movq %rbx, %rdi
callq 0x4026
pushq $0x30
popq %r12
pushq $0xb
popq %rdi
pushq $0xf
popq %rsi
callq 0x2571d
testb %al, %al
je 0x3a8e
movq 0x47398(%rip), %rdi     # 0x4adc0
leaq 0x33772(%rip), %rsi     # 0x371a1
callq 0x2520
movq %rax, %rbx
xorl %r15d, %r15d
leaq -0xf0(%rbp), %r14
movl %r15d, %r15d
movq 0x4734d(%rip), %rax     # 0x4ad98
movq 0x4733e(%rip), %rsi     # 0x4ad90
subq %rsi, %rax
cqto
idivq %r12
cmpq %r15, %rax
jbe 0x3a86
imulq $0x30, %r15, %rax
addq %rax, %rsi
movq %r14, %rdi
callq 0x4094
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2848
movq %r14, %rdi
callq 0x416e
incl %r15d
jmp 0x3a41
movq %rbx, %rdi
callq 0x2270
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x416e
movq %rbx, %rdi
callq 0x2310