user: Please show me the C implementation that matches the assembly code listed below:

```asm
<unbalance>:
  endbr64
  push   %r15
  mov    %rsi,%r15
  push   %r14
  push   %r13
  mov    %edi,%r13d
  push   %r12
  push   %rbp
  mov    %rdx,%rbp
  push   %rbx
  mov    %ecx,-0x58(%rsp)
  mov    %r8d,-0x20(%rsp)
  mov    %r9,-0x70(%rsp)
  cmp    %r8d,%ecx
  jg     L228
  test   %edi,%edi
  jle    L228
  mov    %ecx,%esi
  mov    %ecx,%ebx
  mov    %r8d,%r10d
  movslq %edi,%rax
  imul   %edi,%esi
  lea    0x0(,%rax,8),%r14
  movslq %ebx,%r8
  lea    (%r9,%r8,8),%rdi
  movslq %esi,%rcx
  shl    $0x3,%rcx
  lea    (%r15,%rcx,1),%rax
  add    %rdx,%rcx
  mov    %r10d,%edx
  sub    %ebx,%edx
  add    %r8,%rdx
  lea    0x8(%r9,%rdx,8),%rbx
  mov    %r13d,%edx
  mov    %r13d,%r9d
  shr    %edx
  mov    %rbx,-0x68(%rsp)
  and    $0xfffffffe,%r9d
  lea    -0x1(%rdx),%r10d
  lea    -0x1(%r13),%edx
  shl    $0x3,%rdx
  add    $0x1,%r10
  sub    %r15,%rdx
  shl    $0x4,%r10
  lea    0x8(%rdx),%rbx
  mov    %rbx,-0x60(%rsp)
  xchg   %ax,%ax
L58:
  lea    0x10(%rax),%r8
  mov    %rdi,%rdx
  lea    (%rax,%r14,1),%rbx
  add    $0x8,%rdi
  cmp    %r8,%rcx
  lea    0x10(%rcx),%r8
  setae  %r11b
  cmp    %r8,%rax
  setae  %r8b
  or     %r8d,%r11d
  cmp    %rbx,%rdx
  setae  %r8b
  cmp    %rax,%rdi
  setbe  %r12b
  or     %r12d,%r8d
  and    %r11d,%r8d
  cmp    $0x1,%r13d
  setne  %r11b
  test   %r11b,%r8b
  lea    (%rcx,%r14,1),%r8
  je     L59
  cmp    %r8,%rdx
  setae  %r12b
  cmp    %rcx,%rdi
  setbe  %r11b
  or     %r12b,%r11b
  je     L59
  movsd  (%rdx),%xmm1
  xor    %r11d,%r11d
  unpcklpd %xmm1,%xmm1
  nop
L55:
  movupd (%rax,%r11,1),%xmm0
  mulpd  %xmm1,%xmm0
  movups %xmm0,(%rax,%r11,1)
  movupd (%rcx,%r11,1),%xmm0
  mulpd  %xmm1,%xmm0
  movups %xmm0,(%rcx,%r11,1)
  add    $0x10,%r11
  cmp    %r10,%r11
  jne    L55
  cmp    %r9d,%r13d
  je     L278
  lea    (%rsi,%r9,1),%eax
  cltq
  shl    $0x3,%rax
  lea    (%r15,%rax,1),%rcx
  add    %rbp,%rax
  movsd  (%rcx),%xmm0
  mulsd  (%rdx),%xmm0
  movsd  %xmm0,(%rcx)
  movsd  (%rax),%xmm0
  mulsd  (%rdx),%xmm0
  movsd  %xmm0,(%rax)
L278:
  mov    %rbx,%rax
  mov    %r8,%rcx
  add    %r13d,%esi
  cmp    -0x68(%rsp),%rdi
  jne    L58
L228:
  mov    -0x58(%rsp),%r14d
  sub    $0x1,%r14d
  js     L190
  mov    %r13d,%eax
  mov    %r14d,%ebx
  movslq %r14d,%r12
  mov    %r13d,%r14d
  shr    %eax
  imul   %r13d,%ebx
  and    $0xfffffffe,%r14d
  sub    $0x1,%eax
  add    $0x1,%rax
  shl    $0x4,%rax
  mov    %rax,-0x28(%rsp)
  lea    -0x1(%r13),%eax
  mov    %eax,-0x3c(%rsp)
  mov    %rax,-0x18(%rsp)
  lea    0x8(%r15),%rax
  mov    %rax,-0x10(%rsp)
  jmp    L306
L16:
  sub    $0x1,%r12
  sub    %r13d,%ebx
  test   %r12d,%r12d
  js     L190
  cs nopw 0x0(%rax,%rax,1)
L306:
  mov    -0x70(%rsp),%rax
  cvttsd2si (%rax,%r12,8),%eax
  cmp    %r12d,%eax
  je     L16
  test   %r13d,%r13d
  jle    L16
  imul   %r13d,%eax
  movslq %eax,%rcx
  movslq %ebx,%rax
  lea    0x10(,%rax,8),%r9
  mov    %rax,-0x38(%rsp)
  lea    0x0(,%rcx,8),%r8
  mov    %rcx,%r10
  lea    -0x10(%r9),%rax
  lea    (%r15,%r9,1),%rdi
  mov    %rcx,-0x30(%rsp)
  lea    0x0(%rbp,%rax,1),%rdx
  lea    0x0(%rbp,%r9,1),%rsi
  mov    %rax,-0x50(%rsp)
  add    %r15,%rax
  cmp    %rdx,%rdi
  lea    0x10(%r8),%r11
  mov    %rsi,-0x68(%rsp)
  lea    0x0(%rbp,%r8,1),%rcx
  setbe  -0x3d(%rsp)
  cmp    %rax,-0x68(%rsp)
  lea    0x0(%rbp,%r11,1),%rsi
  mov    %rdi,-0x58(%rsp)
  setbe  %dil
  or     -0x3d(%rsp),%dil
  cmpl   $0x1,-0x3c(%rsp)
  mov    %rsi,-0x48(%rsp)
  lea    (%r15,%r11,1),%rsi
  seta   -0x3d(%rsp)
  and    -0x3d(%rsp),%dil
  cmp    %r8,%r9
  mov    %rsi,-0x60(%rsp)
  lea    (%r15,%r8,1),%rsi
  setle  %r8b
  cmp    -0x50(%rsp),%r11
  setle  %r9b
  mov    -0x48(%rsp),%r11
  or     %r9d,%r8d
  and    %edi,%r8d
  cmp    %rcx,-0x58(%rsp)
  setbe  %dil
  cmp    %r11,%rax
  setae  %r9b
  or     %r9d,%edi
  and    %r8d,%edi
  cmp    -0x60(%rsp),%rdx
  setae  %r8b
  cmp    %rsi,-0x68(%rsp)
  setbe  %r9b
  or     %r9d,%r8d
  test   %r8b,%dil
  je     L257
  cmp    -0x60(%rsp),%rcx
  setae  %dil
  cmp    %rsi,%r11
  setbe  %r8b
  or     %dil,%r8b
  je     L257
  mov    -0x28(%rsp),%r8
  xor    %edi,%edi
  nopl   0x0(%rax)
L104:
  movupd (%rax,%rdi,1),%xmm0
  movupd (%rsi,%rdi,1),%xmm2
  movups %xmm2,(%rax,%rdi,1)
  movups %xmm0,(%rsi,%rdi,1)
  movupd (%rdx,%rdi,1),%xmm0
  movupd (%rcx,%rdi,1),%xmm3
  movups %xmm3,(%rdx,%rdi,1)
  movups %xmm0,(%rcx,%rdi,1)
  add    $0x10,%rdi
  cmp    %r8,%rdi
  jne    L104
  cmp    %r14d,%r13d
  je     L16
  lea    (%rbx,%r14,1),%edx
  lea    (%r10,%r14,1),%eax
  sub    $0x1,%r12
  sub    %r13d,%ebx
  movslq %edx,%rdx
  cltq
  shl    $0x3,%rdx
  shl    $0x3,%rax
  lea    (%r15,%rdx,1),%rcx
  lea    (%r15,%rax,1),%rsi
  add    %rbp,%rdx
  add    %rbp,%rax
  movsd  (%rcx),%xmm0
  movsd  (%rsi),%xmm1
  movsd  %xmm1,(%rcx)
  movsd  %xmm0,(%rsi)
  movsd  (%rdx),%xmm0
  movsd  (%rax),%xmm1
  movsd  %xmm1,(%rdx)
  movsd  %xmm0,(%rax)
  test   %r12d,%r12d
  jns    L306
L190:
  mov    -0x20(%rsp),%eax
  add    $0x1,%eax
  cmp    %r13d,%eax
  jge    L105
  movslq %eax,%rbx
  imul   %r13d,%eax
  mov    %r13d,%r14d
  and    $0xfffffffe,%r14d
  mov    %eax,%r12d
  mov    %r13d,%eax
  shr    %eax
  sub    $0x1,%eax
  add    $0x1,%rax
  shl    $0x4,%rax
  mov    %rax,-0x28(%rsp)
  lea    -0x1(%r13),%eax
  mov    %eax,-0x3c(%rsp)
  mov    %rax,-0x20(%rsp)
  lea    0x8(%r15),%rax
  mov    %rax,-0x18(%rsp)
  jmp    L119
L168:
  add    $0x1,%rbx
  add    %r13d,%r12d
  cmp    %ebx,%r13d
  jle    L105
  nop
L119:
  mov    -0x70(%rsp),%rax
  cvttsd2si (%rax,%rbx,8),%eax
  cmp    %ebx,%eax
  je     L168
  test   %r13d,%r13d
  jle    L168
  imul   %r13d,%eax
  movslq %eax,%rcx
  movslq %r12d,%rax
  lea    0x10(,%rax,8),%r8
  mov    %rax,-0x30(%rsp)
  lea    0x0(,%rcx,8),%r9
  mov    %rcx,%r11
  lea    -0x10(%r8),%rax
  lea    0x0(%rbp,%r8,1),%rsi
  mov    %rcx,-0x38(%rsp)
  lea    (%r15,%r8,1),%rdi
  mov    %rsi,-0x68(%rsp)
  lea    0x0(%rbp,%rax,1),%rdx
  mov    %rax,-0x50(%rsp)
  add    %r15,%rax
  cmp    -0x68(%rsp),%rax
  lea    0x10(%r9),%r10
  setae  -0x3d(%rsp)
  cmp    %rdi,%rdx
  lea    0x0(%rbp,%r10,1),%rcx
  mov    %rdi,-0x48(%rsp)
  setae  %dil
  or     -0x3d(%rsp),%dil
  lea    0x0(%rbp,%r9,1),%rsi
  cmpl   $0x1,-0x3c(%rsp)
  mov    %rcx,-0x60(%rsp)
  lea    (%r15,%r10,1),%rcx
  seta   -0x3d(%rsp)
  and    -0x3d(%rsp),%dil
  cmp    %r10,-0x50(%rsp)
  setge  %r10b
  cmp    %r8,%r9
  mov    %rcx,-0x58(%rsp)
  lea    (%r15,%r9,1),%rcx
  setge  %r8b
  or     %r8d,%r10d
  and    %edi,%r10d
  cmp    %rax,-0x60(%rsp)
  setbe  %dil
  cmp    -0x48(%rsp),%rsi
  setae  %r8b
  or     %r8d,%edi
  and    %r10d,%edi
  mov    -0x58(%rsp),%r10
  cmp    -0x68(%rsp),%rcx
  setae  %r8b
  cmp    %rdx,%r10
  setbe  %r9b
  or     %r9d,%r8d
  test   %r8b,%dil
  je     L157
  cmp    %rsi,%r10
  setbe  %dil
  cmp    -0x60(%rsp),%rcx
  setae  %r8b
  or     %dil,%r8b
  je     L157
  mov    -0x28(%rsp),%r8
  xor    %edi,%edi
  nopw   0x0(%rax,%rax,1)
L22:
  movupd (%rax,%rdi,1),%xmm0
  movupd (%rcx,%rdi,1),%xmm4
  movups %xmm4,(%rax,%rdi,1)
  movups %xmm0,(%rcx,%rdi,1)
  movupd (%rdx,%rdi,1),%xmm0
  movupd (%rsi,%rdi,1),%xmm5
  movups %xmm5,(%rdx,%rdi,1)
  movups %xmm0,(%rsi,%rdi,1)
  add    $0x10,%rdi
  cmp    %rdi,%r8
  jne    L22
  cmp    %r14d,%r13d
  je     L168
  lea    (%r12,%r14,1),%edx
  lea    (%r11,%r14,1),%eax
  add    $0x1,%rbx
  add    %r13d,%r12d
  movslq %edx,%rdx
  cltq
  shl    $0x3,%rdx
  shl    $0x3,%rax
  lea    (%r15,%rdx,1),%rcx
  lea    (%r15,%rax,1),%rsi
  add    %rbp,%rdx
  add    %rbp,%rax
  movsd  (%rcx),%xmm0
  movsd  (%rsi),%xmm1
  movsd  %xmm1,(%rcx)
  movsd  %xmm0,(%rsi)
  movsd  (%rdx),%xmm0
  movsd  (%rax),%xmm1
  movsd  %xmm1,(%rdx)
  movsd  %xmm0,(%rax)
  cmp    %ebx,%r13d
  jg     L119
L105:
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L59:
  mov    %rax,%rcx
  add    -0x60(%rsp),%rax
  sub    %r15,%rcx
  nopl   0x0(%rax,%rax,1)
L72:
  movsd  (%r15,%rcx,1),%xmm0
  mulsd  (%rdx),%xmm0
  movsd  %xmm0,(%r15,%rcx,1)
  movsd  0x0(%rbp,%rcx,1),%xmm0
  mulsd  (%rdx),%xmm0
  movsd  %xmm0,0x0(%rbp,%rcx,1)
  add    $0x8,%rcx
  cmp    %rax,%rcx
  jne    L72
  jmp    L278
L157:
  mov    -0x30(%rsp),%rdi
  mov    -0x20(%rsp),%rcx
  mov    -0x18(%rsp),%rsi
  add    %rdi,%rcx
  lea    (%rsi,%rcx,8),%rsi
  mov    -0x38(%rsp),%rcx
  sub    %rdi,%rcx
  nopl   0x0(%rax)
L308:
  movsd  (%rax),%xmm0
  movsd  (%rax,%rcx,8),%xmm1
  movsd  %xmm1,(%rax)
  movsd  %xmm0,(%rax,%rcx,8)
  movsd  (%rdx),%xmm0
  movsd  (%rdx,%rcx,8),%xmm1
  add    $0x8,%rax
  movsd  %xmm1,(%rdx)
  movsd  %xmm0,(%rdx,%rcx,8)
  add    $0x8,%rdx
  cmp    %rax,%rsi
  jne    L308
  jmp    L168
L257:
  mov    -0x38(%rsp),%rdi
  mov    -0x18(%rsp),%rcx
  mov    -0x10(%rsp),%rsi
  add    %rdi,%rcx
  lea    (%rsi,%rcx,8),%rsi
  mov    -0x30(%rsp),%rcx
  sub    %rdi,%rcx
  nopl   0x0(%rax)
L137:
  movsd  (%rax),%xmm0
  movsd  (%rax,%rcx,8),%xmm1
  movsd  %xmm1,(%rax)
  movsd  %xmm0,(%rax,%rcx,8)
  movsd  (%rdx),%xmm0
  movsd  (%rdx,%rcx,8),%xmm1
  add    $0x8,%rax
  movsd  %xmm1,(%rdx)
  movsd  %xmm0,(%rdx,%rcx,8)
  add    $0x8,%rdx
  cmp    %rsi,%rax
  jne    L137
  jmp    L16
```

assistant: ```c
void unbalance(int n, double vr[], double vi[], int low, int hi, double scale[]) {
  int i, j, k;
  double tmp;
  for (i = low; i <= hi; i++) {
    for (j = 0; j < n; j++) {
      vr[((i) * (n) + (j))] *= scale[i];
      vi[((i) * (n) + (j))] *= scale[i];
    }
  }
  for (i = low - 1; i >= 0; i--) {
    if ((k = (int)scale[i]) != i) {
      for (j = 0; j < n; j++) {
        tmp = vr[((i) * (n) + (j))];
        vr[((i) * (n) + (j))] = vr[((k) * (n) + (j))];
        vr[((k) * (n) + (j))] = tmp;
        tmp = vi[((i) * (n) + (j))];
        vi[((i) * (n) + (j))] = vi[((k) * (n) + (j))];
        vi[((k) * (n) + (j))] = tmp;
      }
    }
  }
  for (i = hi + 1; i < n; i++) {
    if ((k = (int)scale[i]) != i) {
      for (j = 0; j < n; j++) {
        tmp = vr[((i) * (n) + (j))];
        vr[((i) * (n) + (j))] = vr[((k) * (n) + (j))];
        vr[((k) * (n) + (j))] = tmp;
        tmp = vi[((i) * (n) + (j))];
        vi[((i) * (n) + (j))] = vi[((k) * (n) + (j))];
        vi[((k) * (n) + (j))] = tmp;
      }
    }
  }
}
```