__attribute__((naked)) void Mem_Swap(int *p)
{
  __asm__ volatile(
    "push {r4, r5, lr}\n\t"
    "add r4, r0, #0\n\t"
    "bl Math_InitSystem\n\t"
    "add r2, r0, #0\n\t"
    "ldr r0, [r4, #28]\n\t"
    "sub r0, #1\n\t"
    "str r0, [r4, #28]\n\t"
    "cmp r0, #0\n\t"
    "bne 2f\n\t"
    "ldr r1, [r2, #0]\n\t"
    "cmp r4, r1\n\t"
    "bne 1f\n\t"
    "ldrb r0, [r4, #20]\n\t"
    "cmp r0, #0\n\t"
    "beq 2f\n\t"
    "1:\n\t"
    "cmp r1, #0\n\t"
    "beq 3f\n\t"
    "ldr r5, [r4, #24]\n\t"
    "ldr r3, [r4, #16]\n\t"
    "cmp r1, r4\n\t"
    "beq 4f\n\t"
    "5:\n\t"
    "ldr r0, [r2, #0]\n\t"
    "add r2, r0, #0\n\t"
    "add r2, #24\n\t"
    "ldr r0, [r0, #24]\n\t"
    "cmp r0, #0\n\t"
    "beq 3f\n\t"
    "add r1, r0, #0\n\t"
    "cmp r1, r4\n\t"
    "bne 5b\n\t"
    "4:\n\t"
    "cmp r1, #0\n\t"
    "bne 6f\n\t"
    "3:\n\t"
    "bl Mem_CopyBytes\n\t"
    "6:\n\t"
    "str r5, [r2, #0]\n\t"
    "cmp r3, #0\n\t"
    "beq 7f\n\t"
    "ldr r0, [r4, #8]\n\t"
    "mov r1, #2\n\t"
    "bl Math_SqrtFixed\n\t"
    "7:\n\t"
    "ldr r0, [r4, #12]\n\t"
    "bl Collision_HasResult\n\t"
    "lsl r0, r0, #24\n\t"
    "cmp r0, #0\n\t"
    "bne 8f\n\t"
    "ldr r0, [r4, #32]\n\t"
    "bl Mem_FillBytes\n\t"
    "8:\n\t"
    "add r0, r4, #0\n\t"
    "bl Mem_FillBytes\n\t"
    "2:\n\t"
    "pop {r4, r5, pc}");
}
