// File: /workspace/github_c_makefile_star2_O0/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
subq $0x120, %rsp            # imm = 0x120
leaq 0x10(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x43860
cmpb $0x0, %al
jne 0x33ed4
jmp 0x3426b
movq -0xf8(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x8(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movss 0x3c(%rax), %xmm1
movq -0x10(%rbp), %rax
movss 0x3c(%rax), %xmm0
addss %xmm0, %xmm1
movss 0x11100(%rip), %xmm0    # 0x45008
divss %xmm1, %xmm0
movss %xmm0, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, %rdi
addq $0x14, %rdi
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x40dc0
movlpd %xmm0, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rdi
addq $0x14, %rdi
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0x40dc0
movlpd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
leaq -0x24(%rbp), %rdi
callq 0x5850
movq -0xf8(%rbp), %rdi
movlpd %xmm0, -0x1c(%rbp)
addq $0x14, %rdi
callq 0x40d80
movq -0xf8(%rbp), %rax
movlpd %xmm0, -0x50(%rbp)
movq -0x1c(%rbp), %rcx
movq %rcx, -0x58(%rbp)
movq 0x14(%rax), %rax
movq %rax, -0x60(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
callq 0xb340
movaps %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x33fbb
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0xfc(%rbp)
jmp 0x33ff7
movq -0xf8(%rbp), %rax
movq -0x1c(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movq 0x14(%rax), %rax
movq %rax, -0x70(%rbp)
movsd -0x68(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
callq 0xb340
xorps %xmm1, %xmm1
xorl %eax, %eax
movl $0x1, %ecx
ucomiss %xmm1, %xmm0
cmoval %ecx, %eax
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
cvtsi2ss %eax, %xmm0
leaq -0x50(%rbp), %rdi
callq 0x5810
movq -0xf8(%rbp), %rax
movlpd %xmm0, -0x48(%rbp)
movq %rax, %rdi
addq $0x14, %rdi
movq %rdi, -0x108(%rbp)
movss 0x10(%rax), %xmm0
callq 0x5810
movlpd %xmm0, -0x88(%rbp)
movss -0x14(%rbp), %xmm0
leaq -0x88(%rbp), %rdi
callq 0x5810
movlpd %xmm0, -0x80(%rbp)
movq -0x8(%rbp), %rax
movss 0x3c(%rax), %xmm0
leaq -0x80(%rbp), %rdi
callq 0x5810
movlpd %xmm0, -0x78(%rbp)
movq -0x8(%rbp), %rdi
addq $0x14, %rdi
movsd -0x78(%rbp), %xmm0
callq 0x43880
movq -0xf8(%rbp), %rax
movq -0x108(%rbp), %rdi
movss 0x10(%rax), %xmm0
callq 0x5810
movlpd %xmm0, -0xa0(%rbp)
movss -0x14(%rbp), %xmm0
leaq -0xa0(%rbp), %rdi
callq 0x5810
movlpd %xmm0, -0x98(%rbp)
movq -0x10(%rbp), %rax
movss 0x3c(%rax), %xmm0
leaq -0x98(%rbp), %rdi
callq 0x5810
movlpd %xmm0, -0x90(%rbp)
movq -0x10(%rbp), %rdi
addq $0x14, %rdi
movsd -0x90(%rbp), %xmm0
callq 0x5410
movq -0x8(%rbp), %rdi
addq $0x24, %rdi
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rax
movq %rax, -0xb0(%rbp)
movsd -0xb0(%rbp), %xmm0
callq 0x5850
movlpd %xmm0, -0xa8(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm1
callq 0xb340
movss %xmm0, -0xb4(%rbp)
xorps %xmm0, %xmm0
ucomiss -0xb4(%rbp), %xmm0
jbe 0x34153
jmp 0x3426b
movq -0x8(%rbp), %rax
movss 0x44(%rax), %xmm0
movq -0x10(%rbp), %rax
ucomiss 0x44(%rax), %xmm0
jbe 0x34179
movq -0x8(%rbp), %rax
movss 0x44(%rax), %xmm0
movss %xmm0, -0x10c(%rbp)
jmp 0x3418a
movq -0x10(%rbp), %rax
movss 0x44(%rax), %xmm0
movss %xmm0, -0x10c(%rbp)
movss -0x10c(%rbp), %xmm0
movss %xmm0, -0xcc(%rbp)
movss -0xb4(%rbp), %xmm0
movss -0x14(%rbp), %xmm1
mulss %xmm1, %xmm0
movss -0xcc(%rbp), %xmm1
movss 0x10e4d(%rip), %xmm2    # 0x45008
addss %xmm2, %xmm1
mulss %xmm1, %xmm0
movss %xmm0, -0xd0(%rbp)
movss -0xd0(%rbp), %xmm0
leaq -0x48(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x5810
movlpd %xmm0, -0xe0(%rbp)
movq -0x8(%rbp), %rax
movss 0x3c(%rax), %xmm0
leaq -0xe0(%rbp), %rdi
callq 0x5810
movlpd %xmm0, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
addq $0x24, %rdi
movsd -0xd8(%rbp), %xmm0
callq 0x43880
movq -0x118(%rbp), %rdi
movss -0xd0(%rbp), %xmm0
callq 0x5810
movlpd %xmm0, -0xf0(%rbp)
movq -0x10(%rbp), %rax
movss 0x3c(%rax), %xmm0
leaq -0xf0(%rbp), %rdi
callq 0x5810
movlpd %xmm0, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
addq $0x24, %rdi
movsd -0xe8(%rbp), %xmm0
callq 0x5410
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw %cs:(%rax,%rax)