// File: /workspace/github_c_makefile_star2_O2/FredTheDino[P]Fog/src/engine/logic/block_physics.cpp
// Function: Physics::solve(Physics::Overlap)
void solve(Overlap overlap)
{
    if (!overlap) {
        return;
    }

    Body *a = overlap.a;
    Body *b = overlap.b;

    f32 total_mass = 1.0f / (a->inverse_mass + b->inverse_mass);

    // Position
    Vec2 relative_position = (a->position + a->offset) - (b->position + b->offset);
    Vec2 normal = -overlap.normal * (f32) SIGN(dot(relative_position, overlap.normal));
#if 1
    a->position -= overlap.normal * overlap.depth * total_mass * a->inverse_mass;
    b->position += overlap.normal * overlap.depth * total_mass * b->inverse_mass;
#endif

    // Don't do velocity correct unless you have to.
    Vec2 relative_velocity = a->velocity - b->velocity;
    f32 normal_velocity = dot(normal, relative_velocity);
    if (normal_velocity < 0)
        return;

    // Normal
    f32 bounce = MAX(a->bounce, b->bounce);
    f32 normal_force = normal_velocity * total_mass * (1.0f + bounce);
    a->velocity -= normal * normal_force * a->inverse_mass;
    b->velocity += normal * normal_force * b->inverse_mass;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
cmpb $0x0, 0x2c(%rbp)
je 0x23605
leaq 0x10(%rbp), %rdx
movq (%rdx), %rcx
movq 0x8(%rdx), %rax
movss 0x3c(%rcx), %xmm2
movss 0x3c(%rax), %xmm0
addss %xmm2, %xmm0
movss 0x7ba5(%rip), %xmm3     # 0x2b004
movsd 0x8(%rcx), %xmm1
movss 0x14(%rcx), %xmm4
movaps %xmm1, %xmm8
addss %xmm4, %xmm8
movss 0x18(%rcx), %xmm5
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
addss %xmm5, %xmm1
movsd 0x8(%rax), %xmm6
movss 0x14(%rax), %xmm7
addss %xmm6, %xmm7
subss %xmm7, %xmm8
shufps $0x55, %xmm6, %xmm6     # xmm6 = xmm6[1,1,1,1]
addss 0x18(%rax), %xmm6
subss %xmm6, %xmm1
movsd 0x14(%rdx), %xmm6
movaps %xmm6, %xmm7
shufps $0x55, %xmm6, %xmm7     # xmm7 = xmm7[1,1],xmm6[1,1]
mulss %xmm1, %xmm7
mulss %xmm6, %xmm8
addss %xmm7, %xmm8
xorps %xmm10, %xmm10
cmpltss %xmm8, %xmm10
andps %xmm3, %xmm10
divss %xmm0, %xmm3
movss 0x14(%rdx), %xmm0
movaps 0x7b68(%rip), %xmm11    # 0x2b040
xorps %xmm11, %xmm0
movss 0x18(%rdx), %xmm9
xorps %xmm9, %xmm11
xorps %xmm7, %xmm7
cmpltss %xmm7, %xmm8
movss 0x7d31(%rip), %xmm1     # 0x2b228
andps %xmm8, %xmm1
andnps %xmm10, %xmm8
orps %xmm8, %xmm1
mulss %xmm1, %xmm0
mulss %xmm11, %xmm1
movss 0x10(%rdx), %xmm8
mulss %xmm8, %xmm6
mulss %xmm8, %xmm9
mulss %xmm3, %xmm6
mulss %xmm3, %xmm9
movaps %xmm2, %xmm8
mulss %xmm6, %xmm8
mulss %xmm9, %xmm2
subss %xmm8, %xmm4
movss %xmm4, 0x14(%rcx)
subss %xmm2, %xmm5
movss %xmm5, 0x18(%rcx)
movss 0x3c(%rax), %xmm2
mulss %xmm2, %xmm6
mulss %xmm2, %xmm9
addss 0x14(%rax), %xmm6
movss %xmm6, 0x14(%rax)
addss 0x18(%rax), %xmm9
movss %xmm9, 0x18(%rax)
movsd 0x24(%rax), %xmm6
movss 0x24(%rcx), %xmm4
movss 0x28(%rcx), %xmm2
movaps %xmm4, %xmm5
subss %xmm6, %xmm5
shufps $0x55, %xmm6, %xmm6     # xmm6 = xmm6[1,1,1,1]
movaps %xmm2, %xmm8
subss %xmm6, %xmm8
mulss %xmm1, %xmm8
mulss %xmm0, %xmm5
addss %xmm8, %xmm5
ucomiss %xmm5, %xmm7
ja 0x23605
movss 0x3c(%rcx), %xmm6
movss 0x44(%rcx), %xmm7
maxss 0x44(%rax), %xmm7
addss 0x7a4d(%rip), %xmm7     # 0x2b004
mulss %xmm5, %xmm3
mulss %xmm3, %xmm7
mulss %xmm7, %xmm0
mulss %xmm7, %xmm1
movaps %xmm6, %xmm3
mulss %xmm0, %xmm3
mulss %xmm1, %xmm6
subss %xmm3, %xmm4
movss %xmm4, 0x24(%rcx)
subss %xmm6, %xmm2
movss %xmm2, 0x28(%rcx)
movss 0x3c(%rax), %xmm2
mulss %xmm2, %xmm0
mulss %xmm2, %xmm1
addss 0x24(%rax), %xmm0
movss %xmm0, 0x24(%rax)
addss 0x28(%rax), %xmm1
movss %xmm1, 0x28(%rax)
popq %rbp
retq