user: Converte this assembly snippet into its equivalent C code:

```asm
<mp_qrsolv>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x88,%rsp
  mov    %rsi,0x38(%rsp)
  mov    %edx,0x7c(%rsp)
  mov    %rcx,0x58(%rsp)
  mov    %r8,0x68(%rsp)
  mov    0xc8(%rsp),%r14
  test   %edi,%edi
  jle    L247
  mov    %edi,%r15d
  mov    %rsi,%rax
  movslq %edx,%rsi
  lea    0x1(%rsi),%rbx
  lea    -0x1(%rdi),%ecx
  mov    %ecx,0x78(%rsp)
  mov    %ecx,%r10d
  add    $0x2,%r10
  shl    $0x3,%rsi
  mov    $0x0,%r8d
  mov    $0x1,%edi
  lea    0x8(%rax),%r11
  mov    %rax,%rbp
  mov    0xc0(%rsp),%r12
  mov    0xd0(%rsp),%r13
  jmp    L31
L359:
  lea    0x0(%rbp,%r8,8),%rdx
  mov    %r15d,%eax
  sub    %edi,%eax
  add    %r8,%rax
  lea    (%r11,%rax,8),%rcx
  mov    %rdx,%rax
L144:
  movsd  (%rdx),%xmm0
  movsd  %xmm0,(%rax)
  add    %rsi,%rdx
  add    $0x8,%rax
  cmp    %rcx,%rax
  jne    L144
L324:
  movsd  0x0(%rbp,%r8,8),%xmm0
  movsd  %xmm0,-0x8(%r12,%rdi,8)
  movsd  -0x8(%r9,%rdi,8),%xmm0
  movsd  %xmm0,-0x8(%r13,%rdi,8)
  add    $0x1,%rdi
  add    %rbx,%r8
  cmp    %r10,%rdi
  je     L241
L31:
  lea    -0x1(%rdi),%eax
  cmp    %eax,%r15d
  jg     L359
  jmp    L324
L241:
  lea    0x8(%rsi),%rax
  mov    %rax,0x70(%rsp)
  mov    0x38(%rsp),%rax
  mov    %rax,0x48(%rsp)
  mov    0x7c(%rsp),%eax
  add    $0x1,%eax
  mov    %eax,0x50(%rsp)
  mov    %r15d,%eax
  mov    %rax,0x60(%rsp)
  mov    %r14,0x30(%rsp)
  movl   $0x0,0x54(%rsp)
  movq   $0x0,0x18(%rsp)
  mov    %r15d,%r13d
  jmp    L44
L240:
  call   <sqrt@plt>
  jmp    L306
L138:
  mov    0x8(%rsp),%rax
  movsd  (%rax),%xmm0
  divsd  0x0(%rbp),%xmm0
  movapd %xmm0,%xmm6
  movsd  %xmm0,0x20(%rsp)
  mulsd  D2(%rip),%xmm0
  mulsd  %xmm6,%xmm0
  addsd  D2(%rip),%xmm0
  pxor   %xmm4,%xmm4
  ucomisd %xmm0,%xmm4
  ja     L327
  sqrtsd %xmm0,%xmm0
L341:
  movsd  D40(%rip),%xmm2
  divsd  %xmm0,%xmm2
  movsd  0x20(%rsp),%xmm4
  mulsd  %xmm2,%xmm4
  jmp    L127
L327:
  call   <sqrt@plt>
  jmp    L341
L50:
  movapd %xmm4,%xmm6
  xorpd  D5(%rip),%xmm6
  movslq %r15d,%rax
  mov    %r14,%rdx
  sub    %rbx,%rdx
  add    0x40(%rsp),%rdx
  add    0x38(%rsp),%rdx
L322:
  movsd  (%rdx,%rax,8),%xmm0
  movsd  (%r14,%rax,8),%xmm1
  movapd %xmm6,%xmm3
  mulsd  %xmm0,%xmm3
  movapd %xmm1,%xmm5
  mulsd  %xmm2,%xmm5
  addsd  %xmm5,%xmm3
  movsd  %xmm3,(%r14,%rax,8)
  mulsd  %xmm2,%xmm0
  mulsd  %xmm4,%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%rdx,%rax,8)
  add    $0x1,%rax
  cmp    %eax,%r13d
  jg     L322
  mulsd  0x28(%rsp),%xmm2
  mulsd  %xmm6,%xmm7
  addsd  %xmm2,%xmm7
  movsd  %xmm7,0x28(%rsp)
  jmp    L252
L76:
  cmp    %r15d,%r13d
  jle    L351
L252:
  add    $0x8,%rbx
  add    $0x1,%r15d
  mov    0x50(%rsp),%edi
  add    %edi,0x14(%rsp)
  add    $0x8,%r12
L7:
  mov    %rbx,0x8(%rsp)
  pxor   %xmm6,%xmm6
  ucomisd (%rbx),%xmm6
  jp     L301
  je     L76
L301:
  movslq 0x14(%rsp),%rax
  shl    $0x3,%rax
  mov    %rax,0x40(%rsp)
  mov    0x38(%rsp),%rbp
  add    %rax,%rbp
  movsd  0x0(%rbp),%xmm0
  call   <fabs@plt>
  mov    %rax,0x20(%rsp)
  mov    0x8(%rsp),%rdi
  movsd  (%rdi),%xmm0
  call   <fabs@plt>
  cmp    %rax,0x20(%rsp)
  jge    L138
  movsd  0x0(%rbp),%xmm0
  mov    0x8(%rsp),%rax
  divsd  (%rax),%xmm0
  movapd %xmm0,%xmm7
  movsd  %xmm0,0x20(%rsp)
  movsd  D2(%rip),%xmm1
  mulsd  %xmm1,%xmm0
  mulsd  %xmm7,%xmm0
  addsd  %xmm1,%xmm0
  pxor   %xmm1,%xmm1
  ucomisd %xmm0,%xmm1
  ja     L240
  sqrtsd %xmm0,%xmm0
L306:
  movsd  D40(%rip),%xmm4
  divsd  %xmm0,%xmm4
  movsd  0x20(%rsp),%xmm2
  mulsd  %xmm4,%xmm2
L127:
  movapd %xmm2,%xmm0
  mulsd  0x0(%rbp),%xmm0
  mov    0x8(%rsp),%rax
  movapd %xmm4,%xmm1
  mulsd  (%rax),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,0x0(%rbp)
  movsd  (%r12),%xmm7
  movapd %xmm7,%xmm0
  mulsd  %xmm2,%xmm0
  movsd  0x28(%rsp),%xmm1
  mulsd  %xmm4,%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%r12)
  cmp    %r15d,%r13d
  jg     L50
L351:
  mov    0x48(%rsp),%rax
  movsd  (%rax),%xmm0
  mov    0x30(%rsp),%rbx
  movsd  %xmm0,(%rbx)
  mov    0xc0(%rsp),%rdi
  mov    0x18(%rsp),%rsi
  movsd  (%rdi,%rsi,8),%xmm0
  movsd  %xmm0,(%rax)
  add    $0x1,%rsi
  mov    %rsi,0x18(%rsp)
  mov    0x70(%rsp),%rcx
  add    %rcx,%rax
  mov    %rax,0x48(%rsp)
  add    $0x8,%rbx
  mov    %rbx,0x30(%rsp)
  mov    0x50(%rsp),%edi
  add    %edi,0x54(%rsp)
  cmp    0x60(%rsp),%rsi
  je     L268
L44:
  mov    0x18(%rsp),%rax
  mov    %eax,%esi
  mov    0x58(%rsp),%rdi
  movslq (%rdi,%rax,4),%rax
  mov    0x68(%rsp),%rdi
  lea    (%rdi,%rax,8),%rcx
  movsd  (%rcx),%xmm0
  pxor   %xmm7,%xmm7
  ucomisd %xmm7,%xmm0
  jp     L200
  je     L351
L200:
  mov    0x18(%rsp),%rbx
  cmp    %ebx,%r13d
  jle    L54
  mov    0x78(%rsp),%eax
  sub    %esi,%eax
  add    %rbx,%rax
  lea    0x8(%r14,%rax,8),%rdx
  mov    0x30(%rsp),%rax
L331:
  movq   $0x0,(%rax)
  add    $0x8,%rax
  cmp    %rdx,%rax
  jne    L331
  movsd  (%rcx),%xmm0
  mov    0x30(%rsp),%rbx
  movsd  %xmm0,(%rbx)
  lea    0x1(%rsi),%r15d
  mov    0xd0(%rsp),%rax
  mov    0x18(%rsp),%rcx
  lea    (%rax,%rcx,8),%r12
  mov    0x54(%rsp),%eax
  mov    %eax,0x14(%rsp)
  pxor   %xmm7,%xmm7
  movsd  %xmm7,0x28(%rsp)
  jmp    L7
L268:
  mov    %r13d,%r15d
  mov    %r13d,%edx
  mov    $0x0,%eax
  pxor   %xmm0,%xmm0
  mov    $0x0,%edi
  mov    0x60(%rsp),%r8
  mov    0xd0(%rsp),%r9
  jmp    L147
L14:
  add    $0x1,%rax
  cmp    %r8,%rax
  je     L335
L147:
  ucomisd (%r14,%rax,8),%xmm0
  setnp  %cl
  cmovne %edi,%ecx
  test   %cl,%cl
  je     L366
  cmp    %edx,%r15d
  cmove  %eax,%edx
L366:
  cmp    %r15d,%edx
  jge    L14
  movq   $0x0,(%r9,%rax,8)
  jmp    L14
L295:
  sub    $0x1,%rcx
  add    %r9d,%esi
  add    $0x8,%rdi
L140:
  movsd  (%r10,%rcx,8),%xmm0
  subsd  %xmm1,%xmm0
  divsd  (%r14,%rcx,8),%xmm0
  movsd  %xmm0,(%r10,%rcx,8)
  cmp    %r8,%rcx
  je     L161
  pxor   %xmm1,%xmm1
  cmp    %ecx,%edx
  jle    L295
  movslq %esi,%rax
  lea    (%rdi,%rax,8),%r11
  add    0x38(%rsp),%r11
  mov    %rcx,%rax
L233:
  movsd  (%r11,%rax,8),%xmm0
  mulsd  (%r10,%rax,8),%xmm0
  addsd  %xmm0,%xmm1
  add    $0x1,%rax
  cmp    %eax,%edx
  jg     L233
  jmp    L295
L161:
  mov    $0x0,%eax
  mov    0x58(%rsp),%rcx
  mov    0xc0(%rsp),%rsi
  mov    0xd0(%rsp),%rdi
L278:
  movsd  (%rdi,%rax,8),%xmm0
  movslq (%rcx,%rax,4),%rdx
  movsd  %xmm0,(%rsi,%rdx,8)
  add    $0x1,%rax
  cmp    %eax,%r15d
  jg     L278
L247:
  add    $0x88,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L335:
  test   %edx,%edx
  jle    L161
  lea    -0x1(%rdx),%eax
  movslq %eax,%rcx
  mov    0x7c(%rsp),%edi
  mov    %edi,%r9d
  not    %r9d
  lea    -0x2(%rdx),%esi
  imul   %edi,%esi
  add    %eax,%esi
  movslq %edx,%r8
  mov    %r8,%rdi
  neg    %rdi
  lea    0x8(,%rdi,8),%rdi
  sub    $0x1,%r8
  mov    %eax,%eax
  sub    %rax,%r8
  pxor   %xmm1,%xmm1
  mov    0xd0(%rsp),%r10
  jmp    L140
L54:
  mov    0x30(%rsp),%rax
  movsd  %xmm0,(%rax)
  jmp    L351
```

tool_calls: name: read_data
arguments: data_tag: D2
type: f64
name: read_data
arguments: data_tag: D40
type: f64
name: read_data
arguments: data_tag: D5
type: f32[4]

tool: D2: 0.25

tool: D40: 0.5

tool: {"D5": [0.0,-0.0,0.0,0.0]}

assistant: ```c
void mp_qrsolv(int n, double *r, int ldr, int *ipvt, double *diag, double *qtb, double *x, double *sdiag, double *wa) {
  int i, ij, ik, kk, j, jp1, k, kp1, l, nsing;
  double cosx, cotan, qtbpj, sinx, sum, tanx, temp;
  static double zero = 0.0;
  static double p25 = 0.25;
  static double p5 = 0.5;
  kk = 0;
  for (j = 0; j < n; j++) {
    ij = kk;
    ik = kk;
    for (i = j; i < n; i++) {
      r[ij] = r[ik];
      ij += 1;
      ik += ldr;
    }
    x[j] = r[kk];
    wa[j] = qtb[j];
    kk += ldr + 1;
  }
  for (j = 0; j < n; j++) {
    l = ipvt[j];
    if (diag[l] == zero)
      goto L90;
    for (k = j; k < n; k++)
      sdiag[k] = zero;
    sdiag[j] = diag[l];
    qtbpj = zero;
    for (k = j; k < n; k++) {
      if (sdiag[k] == zero)
        continue;
      kk = k + ldr * k;
      if (fabs(r[kk]) < fabs(sdiag[k])) {
        cotan = r[kk] / sdiag[k];
        sinx = p5 / sqrt(p25 + p25 * cotan * cotan);
        cosx = sinx * cotan;
      } else {
        tanx = sdiag[k] / r[kk];
        cosx = p5 / sqrt(p25 + p25 * tanx * tanx);
        sinx = cosx * tanx;
      }
      r[kk] = cosx * r[kk] + sinx * sdiag[k];
      temp = cosx * wa[k] + sinx * qtbpj;
      qtbpj = -sinx * wa[k] + cosx * qtbpj;
      wa[k] = temp;
      kp1 = k + 1;
      if (n > kp1) {
        ik = kk + 1;
        for (i = kp1; i < n; i++) {
          temp = cosx * r[ik] + sinx * sdiag[i];
          sdiag[i] = -sinx * r[ik] + cosx * sdiag[i];
          r[ik] = temp;
          ik += 1;
        }
      }
    }
  L90:
    kk = j + ldr * j;
    sdiag[j] = r[kk];
    r[kk] = x[j];
  }
  nsing = n;
  for (j = 0; j < n; j++) {
    if ((sdiag[j] == zero) && (nsing == n))
      nsing = j;
    if (nsing < n)
      wa[j] = zero;
  }
  if (nsing < 1)
    goto L150;
  for (k = 0; k < nsing; k++) {
    j = nsing - k - 1;
    sum = zero;
    jp1 = j + 1;
    if (nsing > jp1) {
      ij = jp1 + ldr * j;
      for (i = jp1; i < nsing; i++) {
        sum += r[ij] * wa[i];
        ij += 1;
      }
    }
    wa[j] = (wa[j] - sum) / sdiag[j];
  }
L150:
  for (j = 0; j < n; j++) {
    l = ipvt[j];
    x[l] = wa[j];
  }
}
```