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

```asm
<balance>:
  endbr64
  push   %r15
  lea    -0x1(%rsi),%eax
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x68,%rsp
  mov    %rdx,0x30(%rsp)
  mov    %rcx,0x38(%rsp)
  mov    %r8,0x28(%rsp)
  mov    %eax,0x5c(%rsp)
  test   %eax,%eax
  js     L373
  movslq 0x5c(%rsp),%r14
  mov    %esi,%r12d
  mov    %rdi,%rbx
  movslq %r12d,%rax
  mov    %r14,%rsi
  shl    $0x3,%rax
  imul   %r12d,%esi
  mov    %rax,0x40(%rsp)
  lea    0x8(%rdi),%rax
  mov    %rax,0x20(%rsp)
  mov    %esi,0x18(%rsp)
  mov    %esi,0x10(%rsp)
L229:
  mov    %r14d,0x4c(%rsp)
  mov    0x10(%rsp),%r15d
  mov    %r14d,%r13d
  mov    %r14d,0x8(%rsp)
  nopl   0x0(%rax)
L81:
  xor    %ebp,%ebp
  nopw   0x0(%rax,%rax,1)
L62:
  cmp    %r13d,%ebp
  je     L254
  lea    0x0(%rbp,%r15,1),%eax
  cltq
  movsd  (%rbx,%rax,8),%xmm0
  call   <fabs@plt>
  test   %rax,%rax
  jne    L75
L254:
  add    $0x1,%ebp
  cmp    %r14d,%ebp
  jle    L62
L287:
  pxor   %xmm0,%xmm0
  mov    0x28(%rsp),%rax
  mov    %r14d,%ecx
  cvtsi2sd %r13d,%xmm0
  movsd  %xmm0,(%rax,%r14,8)
  cmp    %r14d,%r13d
  jne    L210
L298:
  mov    0x4c(%rsp),%eax
  sub    $0x1,%r14
  sub    %r12d,0x18(%rsp)
  sub    %r12d,0x10(%rsp)
  sub    $0x1,%eax
  mov    %eax,0x8(%rsp)
  test   %r14d,%r14d
  jns    L229
L373:
  mov    %eax,%ebp
  xor    %eax,%eax
L48:
  mov    0x38(%rsp),%rdi
  mov    0x30(%rsp),%rcx
  mov    %ebp,(%rdi)
  mov    %eax,(%rcx)
L27:
  add    $0x68,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L75:
  cmp    %r14d,%ebp
  jg     L287
  sub    $0x1,%r13d
  sub    %r12d,%r15d
  cmp    $0xffffffff,%r13d
  jne    L81
  lea    0x8(%rbx),%rax
  mov    0x8(%rsp),%ebp
  movl   $0x0,0x10(%rsp)
  movq   $0x0,0x8(%rsp)
  mov    %rax,0x18(%rsp)
L152:
  mov    0x8(%rsp),%rax
  mov    %eax,0x48(%rsp)
  mov    %eax,%r15d
  mov    %eax,0x20(%rsp)
  nopl   0x0(%rax)
L181:
  mov    0x10(%rsp),%eax
  mov    0x20(%rsp),%r13d
  lea    (%r15,%rax,1),%r14d
  nopl   (%rax)
L198:
  cmp    %r15d,%r13d
  je     L311
  movslq %r14d,%rax
  movsd  (%rbx,%rax,8),%xmm0
  call   <fabs@plt>
  test   %rax,%rax
  jne    L348
L311:
  add    $0x1,%r13d
  add    %r12d,%r14d
  cmp    %r13d,%ebp
  jge    L198
L159:
  pxor   %xmm0,%xmm0
  mov    0x8(%rsp),%rax
  mov    0x28(%rsp),%rsi
  cvtsi2sd %r15d,%xmm0
  mov    %eax,%edi
  movsd  %xmm0,(%rsi,%rax,8)
  cmp    %eax,%r15d
  jne    L197
L71:
  cmp    %r15d,%ebp
  jl     L247
  addq   $0x1,0x8(%rsp)
  mov    0x48(%rsp),%eax
  mov    0x8(%rsp),%rsi
  add    %r12d,0x10(%rsp)
  add    $0x1,%eax
  cmp    %esi,%ebp
  jge    L152
  jmp    L48
  nopw   0x0(%rax,%rax,1)
L348:
  cmp    %r13d,%ebp
  jl     L159
  add    $0x1,%r15d
  cmp    %r15d,%ebp
  jge    L181
L247:
  mov    0x38(%rsp),%rax
  mov    0x30(%rsp),%rcx
  mov    %ebp,(%rax)
  mov    0x20(%rsp),%eax
  mov    %eax,(%rcx)
  cmp    %eax,%ebp
  jl     L27
  movslq %eax,%rsi
  mov    0x28(%rsp),%rdi
  mov    0x4c(%rsp),%edx
  mov    %rsi,0x50(%rsp)
  sub    0x48(%rsp),%edx
  add    %rsi,%rdx
  lea    (%rdi,%rsi,8),%rax
  lea    0x8(%rdi,%rdx,8),%rdx
L360:
  mov    D3(%rip),%rcx
  add    $0x8,%rax
  mov    %rcx,-0x8(%rax)
  cmp    %rax,%rdx
  jne    L360
  mov    0x48(%rsp),%eax
  imul   %r12d,%eax
  mov    %eax,0x38(%rsp)
L175:
  mov    0x38(%rsp),%eax
  movl   $0x1,0x58(%rsp)
  mov    0x50(%rsp),%r15
  mov    %eax,0x18(%rsp)
  mov    %eax,0x30(%rsp)
  cs nopw 0x0(%rax,%rax,1)
L271:
  mov    0x38(%rsp),%eax
  pxor   %xmm2,%xmm2
  mov    0x20(%rsp),%r14d
  movsd  %xmm2,0x8(%rsp)
  lea    (%rax,%r15,1),%r13d
  nopw   0x0(%rax,%rax,1)
L151:
  cmp    %r15d,%r14d
  je     L12
  movslq %r13d,%rax
  movsd  %xmm2,0x10(%rsp)
  movsd  (%rbx,%rax,8),%xmm0
  call   <fabs@plt>
  pxor   %xmm0,%xmm0
  cvtsi2sd %rax,%xmm0
  mov    0x18(%rsp),%eax
  addsd  0x8(%rsp),%xmm0
  add    %r14d,%eax
  cltq
  movsd  %xmm0,0x8(%rsp)
  movsd  (%rbx,%rax,8),%xmm0
  call   <fabs@plt>
  pxor   %xmm0,%xmm0
  movsd  0x10(%rsp),%xmm2
  cvtsi2sd %rax,%xmm0
  addsd  %xmm0,%xmm2
L12:
  add    $0x1,%r14d
  add    %r12d,%r13d
  cmp    %r14d,%ebp
  jge    L151
  movsd  0x8(%rsp),%xmm1
  pxor   %xmm6,%xmm6
  mov    $0x1,%edx
  ucomisd %xmm6,%xmm1
  setp   %al
  cmovne %edx,%eax
  test   %al,%al
  je     L355
  ucomisd %xmm6,%xmm2
  setp   %al
  cmovne %edx,%eax
  test   %al,%al
  jne    L375
L355:
  add    $0x1,%r15
  add    %r12d,0x30(%rsp)
  add    %r12d,0x18(%rsp)
  cmp    %r15d,%ebp
  jge    L271
  mov    0x58(%rsp),%eax
  test   %eax,%eax
  je     L175
  add    $0x68,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L197:
  mov    0x8(%rsp),%r8
  movslq %r15d,%rcx
  xor    %edx,%edx
  lea    (%rbx,%rcx,8),%rax
  sub    %rcx,%r8
L391:
  movsd  (%rax),%xmm0
  movsd  (%rax,%r8,8),%xmm1
  add    $0x1,%edx
  movsd  %xmm1,(%rax)
  movsd  %xmm0,(%rax,%r8,8)
  add    0x40(%rsp),%rax
  cmp    %edx,%ebp
  jge    L391
  cmp    %edi,%r12d
  jle    L71
  mov    %r12d,%edi
  mov    0x8(%rsp),%rcx
  mov    0x5c(%rsp),%edx
  imul   %r15d,%edi
  sub    0x48(%rsp),%edx
  add    %rcx,%rdx
  movslq %edi,%rdi
  lea    (%rdi,%rcx,1),%rax
  mov    0x18(%rsp),%rcx
  add    %rdi,%rdx
  lea    (%rbx,%rax,8),%rax
  lea    (%rcx,%rdx,8),%rcx
  movslq 0x10(%rsp),%rdx
  sub    %rdi,%rdx
L43:
  movsd  (%rax),%xmm0
  movsd  (%rax,%rdx,8),%xmm1
  movsd  %xmm1,(%rax)
  movsd  %xmm0,(%rax,%rdx,8)
  add    $0x8,%rax
  cmp    %rax,%rcx
  jne    L43
  jmp    L71
L210:
  movslq %r13d,%rsi
  mov    %r14,%rdi
  xor    %edx,%edx
  lea    (%rbx,%rsi,8),%rax
  sub    %rsi,%rdi
L273:
  movsd  (%rax),%xmm0
  movsd  (%rax,%rdi,8),%xmm1
  add    $0x1,%edx
  movsd  %xmm1,(%rax)
  movsd  %xmm0,(%rax,%rdi,8)
  add    0x40(%rsp),%rax
  cmp    %ecx,%edx
  jle    L273
  test   %r12d,%r12d
  jle    L298
  mov    %r13d,%esi
  mov    0x5c(%rsp),%edx
  mov    0x20(%rsp),%rcx
  imul   %r12d,%esi
  movslq %esi,%rsi
  add    %rsi,%rdx
  lea    (%rbx,%rsi,8),%rax
  lea    (%rcx,%rdx,8),%rcx
  movslq 0x18(%rsp),%rdx
  sub    %rsi,%rdx
  nopl   0x0(%rax)
L131:
  movsd  (%rax),%xmm0
  movsd  (%rax,%rdx,8),%xmm1
  movsd  %xmm1,(%rax)
  movsd  %xmm0,(%rax,%rdx,8)
  add    $0x8,%rax
  cmp    %rcx,%rax
  jne    L131
  jmp    L298
L375:
  movsd  D16(%rip),%xmm3
  mov    D3(%rip),%rax
  movapd %xmm1,%xmm4
  addsd  %xmm2,%xmm4
  mulsd  %xmm2,%xmm3
  movq   %rax,%xmm0
  comisd %xmm1,%xmm3
  jbe    L169
  cs nopw 0x0(%rax,%rax,1)
L4:
  mulsd  D13(%rip),%xmm1
  addsd  %xmm0,%xmm0
  comisd %xmm1,%xmm3
  ja     L4
L169:
  movapd %xmm2,%xmm3
  addsd  %xmm2,%xmm3
  comisd %xmm3,%xmm1
  jb     L117
L350:
  mulsd  D11(%rip),%xmm1
  mulsd  D16(%rip),%xmm0
  comisd %xmm3,%xmm1
  jae    L350
L117:
  addsd  %xmm1,%xmm2
  mulsd  D10(%rip),%xmm4
  divsd  %xmm0,%xmm2
  comisd %xmm2,%xmm4
  jbe    L355
  mov    0x28(%rsp),%rax
  movsd  D3(%rip),%xmm2
  movsd  (%rax,%r15,8),%xmm1
  divsd  %xmm0,%xmm2
  mulsd  %xmm0,%xmm1
  movsd  %xmm1,(%rax,%r15,8)
  cmp    %r12d,0x20(%rsp)
  jge    L174
  mov    0x50(%rsp),%rsi
  movslq 0x30(%rsp),%rcx
  mov    0x5c(%rsp),%edx
  sub    0x48(%rsp),%edx
  add    %rsi,%rdx
  lea    (%rsi,%rcx,1),%rax
  add    %rcx,%rdx
  lea    (%rbx,%rax,8),%rax
  lea    0x8(%rbx,%rdx,8),%rdx
  nopl   (%rax)
L371:
  movsd  (%rax),%xmm1
  add    $0x8,%rax
  mulsd  %xmm2,%xmm1
  movsd  %xmm1,-0x8(%rax)
  cmp    %rax,%rdx
  jne    L371
L174:
  mov    0x4c(%rsp),%ecx
  mov    0x40(%rsp),%rsi
  lea    (%rbx,%r15,8),%rax
  xor    %edx,%edx
  add    $0x1,%ecx
  nopl   0x0(%rax,%rax,1)
L344:
  movsd  (%rax),%xmm1
  add    $0x1,%edx
  mulsd  %xmm0,%xmm1
  movsd  %xmm1,(%rax)
  add    %rsi,%rax
  cmp    %ecx,%edx
  jne    L344
  movl   $0x0,0x58(%rsp)
  jmp    L355
```

tool_calls: name: retrieve_data
arguments: label: D3
type_infered: byte[8]
name: retrieve_data
arguments: label: D16
type_infered: byte[8]
name: retrieve_data
arguments: label: D13
type_infered: byte[8]
name: retrieve_data
arguments: label: D11
type_infered: byte[8]
name: retrieve_data
arguments: label: D10
type_infered: f64

tool: {"D3": [0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f]}

tool: {"D16": [0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x3f]}

tool: {"D13": [0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x40]}

tool: {"D11": [0x00,0x00,0x00,0x00,0x00,0x00,0xd0,0x3f]}

tool: D10: 0.95

assistant: ```c
void balance(double *mat, int n, int *low, int *hi, double *scale) {
  double c, f, g, r, s;
  int i, j, k, l, done;
  for (k = n - 1; k >= 0; k--) {
    for (j = k; j >= 0; j--) {
      for (i = 0; i <= k; i++) {
        if (i != j && fabs(mat[((j) * (n) + (i))]) != 0)
          break;
      }
      if (i > k) {
        scale[k] = j;
        if (j != k) {
          for (i = 0; i <= k; i++) {
            c = mat[((i) * (n) + (j))];
            mat[((i) * (n) + (j))] = mat[((i) * (n) + (k))];
            mat[((i) * (n) + (k))] = c;
          }
          for (i = 0; i < n; i++) {
            c = mat[((j) * (n) + (i))];
            mat[((j) * (n) + (i))] = mat[((k) * (n) + (i))];
            mat[((k) * (n) + (i))] = c;
          }
        }
        break;
      }
    }
    if (j < 0)
      break;
  }
  for (l = 0; l <= k; l++) {
    for (j = l; j <= k; j++) {
      for (i = l; i <= k; i++) {
        if (i != j && fabs(mat[((i) * (n) + (j))]) != 0)
          break;
      }
      if (i > k) {
        scale[l] = j;
        if (j != l) {
          for (i = 0; i <= k; i++) {
            c = mat[((i) * (n) + (j))];
            mat[((i) * (n) + (j))] = mat[((i) * (n) + (l))];
            mat[((i) * (n) + (l))] = c;
          }
          for (i = l; i < n; i++) {
            c = mat[((j) * (n) + (i))];
            mat[((j) * (n) + (i))] = mat[((l) * (n) + (i))];
            mat[((l) * (n) + (i))] = c;
          }
        }
        break;
      }
    }
    if (j > k)
      break;
  }
  *hi = k;
  *low = l;
  for (i = l; i <= k; i++) {
    scale[i] = 1;
  }
  do {
    for (done = 1, i = l; i <= k; i++) {
      for (c = 0, r = 0, j = l; j <= k; j++) {
        if (j != i) {
          c += fabs(mat[((j) * (n) + (i))]);
          r += fabs(mat[((i) * (n) + (j))]);
        }
      }
      if (c != 0 && r != 0) {
        g = r / 2;
        f = 1;
        s = c + r;
        while (c < g) {
          f *= 2;
          c *= 2 * 2;
        }
        g = r * 2;
        while (c >= g) {
          f /= 2;
          c /= 2 * 2;
        }
        if ((c + r) / f < 0.95 * s) {
          done = 0;
          g = 1 / f;
          scale[i] *= f;
          for (j = l; j < n; j++) {
            mat[((i) * (n) + (j))] *= g;
          }
          for (j = 0; j <= k; j++) {
            mat[((j) * (n) + (i))] *= f;
          }
        }
      }
    }
  } while (!done);
}
```