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

```asm
<qrfac>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  movslq %esi,%r12
  push   %rbp
  push   %rbx
  sub    $0xd8,%rsp
  mov    0x120(%rsp),%rax
  mov    %rdi,0x50(%rsp)
  mov    %edx,0x30(%rsp)
  mov    0x118(%rsp),%r11
  mov    %r8d,0xc(%rsp)
  mov    %r9,0x58(%rsp)
  mov    %rax,0x10(%rsp)
  movsd  %xmm0,0x80(%rsp)
  cmp    $0x1,%r8d
  jbe    L145
  lea    D7(%rip),%rdi
  mov    %r11,(%rsp)
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
  mov    (%rsp),%r11
L145:
  movslq 0x30(%rsp),%rbx
  lea    0x0(,%r12,8),%r13d
  mov    %r11,(%rsp)
  movslq %r12d,%rbp
  mov    %ebx,%edi
  imul   %r13d,%edi
  call   <malloc@plt>
  lea    0x0(,%rbx,8),%edi
  mov    %rax,%r15
  mov    %rax,0x70(%rsp)
  call   <malloc@plt>
  mov    %r13d,%edi
  mov    %rax,0x60(%rsp)
  call   <malloc@plt>
  mov    0x50(%rsp),%rdi
  mov    %r15,%rcx
  mov    %ebx,%edx
  mov    %r12d,%esi
  mov    %rax,0x68(%rsp)
  call   <mtranspose@plt>
  test   %ebx,%ebx
  mov    (%rsp),%r11
  jle    L304
  mov    0x70(%rsp),%r15
  xor    %r13d,%r13d
  mov    %rbx,(%rsp)
  shl    $0x3,%rbp
  mov    0x60(%rsp),%r14
  mov    %r14,%rbx
  mov    %r15,%r14
  mov    %r13,%r15
  mov    %r11,%r13
  nopl   (%rax)
L256:
  mov    %r12d,%esi
  mov    %r14,%rdi
  call   <enorm@plt>
  mov    0x10(%rsp),%rax
  cmpl   $0x1,0xc(%rsp)
  movsd  %xmm0,(%rax,%r15,8)
  movsd  %xmm0,0x0(%r13,%r15,8)
  movsd  %xmm0,(%rbx)
  jne    L280
  mov    0x58(%rsp),%rax
  mov    %r15d,(%rax,%r15,4)
L280:
  add    $0x1,%r15
  add    %rbp,%r14
  add    $0x8,%rbx
  cmp    (%rsp),%r15
  jne    L256
  mov    (%rsp),%rbx
  mov    %r13,%r11
L304:
  movslq 0x30(%rsp),%rax
  cmp    %r12d,%eax
  cmovg  %r12,%rax
  test   %eax,%eax
  jle    L25
  lea    0x8(,%rbx,8),%rdi
  mov    %rax,0x40(%rsp)
  xor    %r15d,%r15d
  lea    -0x1(%r12),%eax
  mov    %rdi,0x38(%rsp)
  mov    0x30(%rsp),%edi
  lea    0x0(,%rbx,8),%r10
  xor    %ebx,%ebx
  movl   $0x0,0x34(%rsp)
  mov    0x50(%rsp),%r14
  mov    %r10,%rbp
  add    $0x1,%edi
  mov    %eax,0x4c(%rsp)
  movq   $0x1,0x20(%rsp)
  mov    %edi,0x48(%rsp)
  mov    0x68(%rsp),%rdi
  xchg   %ax,%ax
L240:
  cmpl   $0x1,0xc(%rsp)
  mov    %r15d,(%rsp)
  mov    %r15d,0x28(%rsp)
  je     L237
L319:
  mov    %r12d,%esi
  sub    (%rsp),%esi
  test   %esi,%esi
  jle    L130
  mov    0x4c(%rsp),%edx
  sub    (%rsp),%edx
  mov    %rdi,%rax
  lea    0x8(%rdi,%rdx,8),%rcx
  mov    %r14,%rdx
L313:
  movsd  (%rdx),%xmm0
  add    $0x8,%rax
  add    %rbp,%rdx
  movsd  %xmm0,-0x8(%rax)
  cmp    %rcx,%rax
  jne    L313
L130:
  mov    %r11,0x18(%rsp)
  mov    %rdi,0x10(%rsp)
  call   <enorm@plt>
  pxor   %xmm4,%xmm4
  mov    0x10(%rsp),%rdi
  mov    0x18(%rsp),%r11
  ucomisd %xmm4,%xmm0
  movapd %xmm0,%xmm1
  jp     L334
  jne    L334
  mov    0x30(%rsp),%eax
  movapd %xmm0,%xmm3
  xorpd  D27(%rip),%xmm3
  lea    (%rax,%rbx,1),%r8d
L62:
  mov    0x48(%rsp),%ebx
  movsd  %xmm3,(%r11,%r15,8)
  add    0x38(%rsp),%r14
  add    $0x1,%r15
  add    %ebx,0x34(%rsp)
  movslq %r8d,%rbx
  addq   $0x1,0x20(%rsp)
  cmp    0x40(%rsp),%r15
  jne    L240
L25:
  mov    0x70(%rsp),%rdi
  call   <free@plt>
  mov    0x60(%rsp),%rdi
  call   <free@plt>
  mov    0x68(%rsp),%rdi
  add    $0xd8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10c0 <free@plt>
  nopl   0x0(%rax)
L334:
  movsd  (%r14),%xmm0
  pxor   %xmm5,%xmm5
  movapd %xmm1,%xmm3
  xorpd  D27(%rip),%xmm3
  comisd %xmm0,%xmm5
  jbe    L47
  movq   %xmm1,%rax
  movapd %xmm3,%xmm1
  movq   %rax,%xmm3
L47:
  mov    %r15d,0x78(%rsp)
  cmp    %r15d,%r12d
  jle    L146
  mov    0x50(%rsp),%rsi
  movslq %ebx,%rax
  mov    0x28(%rsp),%edx
  add    %r15,%rax
  lea    (%rsi,%rax,8),%rax
  jmp    L101
  nopl   0x0(%rax,%rax,1)
L324:
  movsd  (%rax),%xmm0
L101:
  divsd  %xmm1,%xmm0
  add    $0x1,%edx
  movsd  %xmm0,(%rax)
  add    %rbp,%rax
  cmp    %edx,%r12d
  jne    L324
  movsd  (%r14),%xmm0
L146:
  addsd  D20(%rip),%xmm0
  mov    0x30(%rsp),%eax
  lea    (%rax,%rbx,1),%r8d
  movsd  %xmm0,(%r14)
  cmp    0x20(%rsp),%eax
  jle    L62
  mov    0x20(%rsp),%rsi
  mov    %r15,%r13
  movslq %r8d,%rax
  mov    0x50(%rsp),%rcx
  mov    0x60(%rsp),%rdx
  mov    %rdi,0x88(%rsp)
  sub    %rsi,%r13
  lea    0x0(,%rsi,8),%r9
  mov    %r8d,0xc8(%rsp)
  mov    0x28(%rsp),%r8d
  sub    %rbx,%r13
  lea    (%r11,%r9,1),%r10
  add    %rdx,%r9
  mov    %r15,0x90(%rsp)
  add    %rax,%r13
  mov    0x30(%rsp),%eax
  sub    $0x2,%eax
  sub    (%rsp),%eax
  add    $0x2,%rax
  mov    %rax,0x10(%rsp)
  lea    (%rbx,%r15,1),%rax
  mov    %r9,%r15
  mov    0x78(%rsp),%r9d
  lea    (%rcx,%rax,8),%rax
  mov    %r11,0x78(%rsp)
  mov    %r14,%r11
  mov    %r10,%r14
  mov    %rax,0x18(%rsp)
  mov    %rcx,%rax
  sub    %rdx,%rax
  lea    (%rax,%rbx,8),%rcx
  mov    0x4c(%rsp),%eax
  mov    $0x1,%ebx
  mov    %rcx,%r10
  sub    %esi,%eax
  lea    0x8(%rdi,%rax,8),%rax
  mov    %rax,0xc0(%rsp)
  nopl   (%rax)
L76:
  mov    0x18(%rsp),%rax
  mov    %ebx,%edi
  mov    %r8d,%edx
  pxor   %xmm1,%xmm1
  cmp    %r9d,%r12d
  jle    L89
  nopl   0x0(%rax,%rax,1)
L283:
  movsd  (%rax),%xmm0
  mulsd  (%rax,%rbx,8),%xmm0
  mov    %edx,%ecx
  lea    0x1(%rdx),%edx
  add    %rbp,%rax
  addsd  %xmm0,%xmm1
  cmp    %edx,%r12d
  jne    L283
  movsd  (%r11),%xmm0
  movapd %xmm1,%xmm2
  lea    (%r15,%r10,1),%rax
  mov    %r8d,%edx
  divsd  %xmm0,%xmm2
  jmp    L98
  nopl   0x0(%rax,%rax,1)
L41:
  movsd  (%rax,%r13,8),%xmm0
  mov    %esi,%edx
  add    %rbp,%rax
L98:
  mulsd  %xmm2,%xmm0
  movsd  (%rax),%xmm1
  lea    0x1(%rdx),%esi
  subsd  %xmm0,%xmm1
  movsd  %xmm1,(%rax)
  cmp    %ecx,%edx
  jne    L41
L89:
  cmpl   $0x1,0xc(%rsp)
  je     L275
L14:
  add    $0x8,%r14
  add    $0x8,%r15
  sub    $0x1,%r13
  add    $0x1,%rbx
  cmp    %rbx,0x10(%rsp)
  jne    L76
  mov    %r11,%r14
  mov    0x88(%rsp),%rdi
  mov    0x90(%rsp),%r15
  mov    0x78(%rsp),%r11
  mov    0xc8(%rsp),%r8d
  jmp    L62
  nopl   0x0(%rax)
L275:
  movsd  (%r14),%xmm0
  pxor   %xmm6,%xmm6
  ucomisd %xmm6,%xmm0
  jp     L220
  je     L14
L220:
  mov    0x34(%rsp),%eax
  mov    %edi,0x28(%rsp)
  movsd  D20(%rip),%xmm7
  mov    %r9d,0xb8(%rsp)
  add    %edi,%eax
  mov    0x50(%rsp),%rdi
  mov    %r11,0xb0(%rsp)
  cltq
  mov    %r10,0xa0(%rsp)
  movsd  (%rdi,%rax,8),%xmm1
  mov    %r8d,0x98(%rsp)
  movsd  %xmm3,0xa8(%rsp)
  divsd  %xmm0,%xmm1
  pxor   %xmm0,%xmm0
  mulsd  %xmm1,%xmm1
  subsd  %xmm1,%xmm7
  movapd %xmm7,%xmm1
  call   <pmax@plt>
  pxor   %xmm7,%xmm7
  movsd  (%r14),%xmm1
  mov    0x28(%rsp),%edi
  ucomisd %xmm0,%xmm7
  mov    0x98(%rsp),%r8d
  mov    0xa0(%rsp),%r10
  mov    0xb0(%rsp),%r11
  mov    0xb8(%rsp),%r9d
  movsd  0xa8(%rsp),%xmm3
  ja     L166
  sqrtsd %xmm0,%xmm0
L56:
  movsd  0x80(%rsp),%xmm7
  mulsd  %xmm1,%xmm0
  movsd  %xmm0,(%r14)
  divsd  (%r15),%xmm0
  mulsd  D56(%rip),%xmm0
  mulsd  %xmm0,%xmm0
  comisd %xmm0,%xmm7
  jb     L14
  mov    0x4c(%rsp),%esi
  sub    (%rsp),%esi
  test   %esi,%esi
  jle    L153
  mov    0x34(%rsp),%eax
  add    0x30(%rsp),%eax
  add    %edi,%eax
  mov    0x50(%rsp),%rdi
  mov    0xc0(%rsp),%rcx
  cltq
  lea    (%rdi,%rax,8),%rdx
  mov    0x88(%rsp),%rax
  nopw   0x0(%rax,%rax,1)
L359:
  movsd  (%rdx),%xmm0
  add    $0x8,%rax
  add    %rbp,%rdx
  movsd  %xmm0,-0x8(%rax)
  cmp    %rax,%rcx
  jne    L359
L153:
  mov    0x88(%rsp),%rdi
  mov    %r9d,0xb0(%rsp)
  mov    %r11,0xa8(%rsp)
  mov    %r10,0x98(%rsp)
  mov    %r8d,0x28(%rsp)
  movsd  %xmm3,0xa0(%rsp)
  call   <enorm@plt>
  mov    0x28(%rsp),%r8d
  mov    0x98(%rsp),%r10
  movsd  %xmm0,(%r14)
  mov    0xa8(%rsp),%r11
  movsd  0xa0(%rsp),%xmm3
  mov    0xb0(%rsp),%r9d
  movsd  %xmm0,(%r15)
  jmp    L14
  nopl   (%rax)
L237:
  mov    0x30(%rsp),%r8d
  mov    %r15d,%esi
  cmp    %r15d,%r8d
  jle    L319
  mov    %r15,%rax
  mov    %r15d,%edx
  nop
L198:
  movslq %edx,%rcx
  movsd  (%r11,%rax,8),%xmm0
  ucomisd (%r11,%rcx,8),%xmm0
  cmova  %eax,%edx
  add    $0x1,%rax
  cmp    %eax,%r8d
  jg     L198
  cmp    %esi,%edx
  je     L319
  test   %r12d,%r12d
  jle    L351
  mov    0x50(%rsp),%rax
  movslq %edx,%rdx
  xor    %ecx,%ecx
  mov    %rdx,%rsi
  lea    (%rax,%r15,8),%rax
  sub    %r15,%rsi
  nopl   0x0(%rax)
L228:
  movsd  (%rax),%xmm0
  movsd  (%rax,%rsi,8),%xmm1
  add    $0x1,%ecx
  movsd  %xmm1,(%rax)
  movsd  %xmm0,(%rax,%rsi,8)
  add    %rbp,%rax
  cmp    %ecx,%r12d
  jne    L228
L191:
  movsd  (%r11,%r15,8),%xmm0
  mov    0x60(%rsp),%rax
  mov    0x58(%rsp),%rsi
  movsd  %xmm0,(%r11,%rdx,8)
  movsd  (%rax,%r15,8),%xmm0
  movsd  %xmm0,(%rax,%rdx,8)
  lea    (%rsi,%rdx,4),%rdx
  mov    (%rsi,%r15,4),%eax
  mov    (%rdx),%ecx
  mov    %ecx,(%rsi,%r15,4)
  mov    %eax,(%rdx)
  jmp    L319
L351:
  movslq %edx,%rdx
  jmp    L191
L166:
  mov    %r9d,0xcc(%rsp)
  mov    %r11,0xb8(%rsp)
  mov    %r10,0xa8(%rsp)
  mov    %r8d,0xa0(%rsp)
  mov    %edi,0x98(%rsp)
  movsd  %xmm3,0xb0(%rsp)
  movsd  %xmm1,0x28(%rsp)
  call   <sqrt@plt>
  mov    0xcc(%rsp),%r9d
  mov    0xb8(%rsp),%r11
  movsd  0xb0(%rsp),%xmm3
  mov    0xa8(%rsp),%r10
  mov    0xa0(%rsp),%r8d
  mov    0x98(%rsp),%edi
  movsd  0x28(%rsp),%xmm1
  jmp    L56
```

tool_calls: name: unpack_data
arguments: tag: D7
datatype: string
name: unpack_data
arguments: tag: D27
datatype: f32[4]
name: unpack_data
arguments: tag: D20
datatype: f64
name: unpack_data
arguments: tag: D56
datatype: byte[8]

tool: D7: Pivot only takes binary values 0 and 1 


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

tool: D20: 1

tool: {"D56": [0x9a,0x99,0x99,0x99,0x99,0x99,0xa9,0x3f]}

assistant: ```c
void qrfac(double *A, int M, int N, int lda, int pivot, int *ipvt, int lipvt, double *rdiag, double *acnorm, double eps) {
  int i, j, jp1, k, kmax, minmn, t;
  double ajnorm, epsmch, one, p05, sum, temp, zero, temp2, pmaxval;
  double *AT, *wa, *wa2;
  if (pivot != 0 && pivot != 1) {
    printf("Pivot only takes binary values 0 and 1 \n");
    exit(-1);
  }
  AT = (double *)malloc(sizeof(double) * N * M);
  wa = (double *)malloc(sizeof(double) * N);
  wa2 = (double *)malloc(sizeof(double) * M);
  one = 1.0;
  zero = 0.0;
  p05 = 5.0e-02;
  epsmch = eps;
  mtranspose(A, M, N, AT);
  for (j = 0; j < N; ++j) {
    acnorm[j] = enorm(AT + j * M, M);
    rdiag[j] = acnorm[j];
    wa[j] = rdiag[j];
    if (pivot == 1) {
      ipvt[j] = j;
    }
  }
  if (M < N) {
    minmn = M;
  } else {
    minmn = N;
  }
  for (j = 0; j < minmn; ++j) {
    if (pivot == 1) {
      kmax = j;
      for (k = j; k < N; ++k) {
        if (rdiag[k] > rdiag[kmax]) {
          kmax = k;
        }
      }
      if (kmax != j) {
        for (i = 0; i < M; ++i) {
          t = i * N;
          temp = A[t + j];
          A[t + j] = A[t + kmax];
          A[t + kmax] = temp;
        }
        rdiag[kmax] = rdiag[j];
        wa[kmax] = wa[j];
        k = ipvt[j];
        ipvt[j] = ipvt[kmax];
        ipvt[kmax] = k;
      }
    }
    t = j * N + j;
    for (i = 0; i < M - j; ++i) {
      wa2[i] = A[t + i * N];
    }
    ajnorm = enorm(wa2, M - j);
    if (ajnorm != zero) {
      if (A[t] < zero) {
        ajnorm = -ajnorm;
      }
      for (i = j; i < M; ++i) {
        A[i * N + j] /= ajnorm;
      }
      A[t] += one;
      jp1 = j + 1;
      if (N >= jp1 + 1) {
        for (k = jp1; k < N; ++k) {
          sum = zero;
          for (i = j; i < M; ++i) {
            sum += (A[i * N + j] * A[i * N + k]);
          }
          temp = sum / A[t];
          for (i = j; i < M; ++i) {
            A[i * N + k] -= (temp * A[i * N + j]);
          }
          if (pivot == 1 && rdiag[k] != zero) {
            temp = A[j * N + k] / rdiag[k];
            pmaxval = pmax(zero, one - temp * temp);
            rdiag[k] = rdiag[k] * sqrt(pmaxval);
            temp2 = (p05 * (rdiag[k] / wa[k]));
            temp2 = temp2 * temp2;
            if (temp2 <= epsmch) {
              for (i = 0; i < M - j - 1; ++i) {
                wa2[i] = A[jp1 * N + k + i * N];
              }
              rdiag[k] = enorm(wa2, M - j - 1);
              wa[k] = rdiag[k];
            }
          }
        }
      }
    }
    rdiag[j] = -ajnorm;
  }
  free(AT);
  free(wa);
  free(wa2);
}
```