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

```asm
<least_squares>:
  endbr64
  push   %rbx
  mov    %rdx,%rbx
  mov    %esi,%ecx
  sub    $0x40,%rsp
  mov    %esi,0x8(%rsp)
  mov    %edi,0xc(%rsp)
  mov    %fs:0x28,%rdx
  mov    %rdx,0x38(%rsp)
  xor    %edx,%edx
  test   %edi,%edi
  setle  %dl
  test   %esi,%esi
  setle  %sil
  or     %sil,%dl
  jne    L0
  mov    %edi,%eax
  cmp    %ecx,%edi
  jl     L0
  imul   %edi,%eax
  lea    0x20(%rsp),%rdi
  mov    %eax,%esi
  mov    %eax,0x1c(%rsp)
  call   <allocate_double_vector@plt>
  test   %eax,%eax
  je     L139
  mov    0xc(%rsp),%edx
  mov    0x8(%rsp),%esi
  lea    0x28(%rsp),%rdi
  movb   $0x4e,0x17(%rsp)
  call   <allocate_double_matrix@plt>
  test   %eax,%eax
  je     L139
  mov    0xc(%rsp),%r10d
  test   %r10d,%r10d
  jle    L11
  movslq 0x8(%rsp),%rsi
  movslq %r10d,%r8
  mov    0x28(%rsp),%rdi
  xor    %edx,%edx
  shl    $0x3,%r8
  mov    %rsi,%r9
  xchg   %ax,%ax
L125:
  xor    %eax,%eax
  test   %r9d,%r9d
  jle    L103
  nopw   0x0(%rax,%rax,1)
L130:
  mov    (%rbx,%rax,8),%rcx
  movsd  (%rcx,%rdx,1),%xmm0
  mov    (%rdi,%rax,8),%rcx
  add    $0x1,%rax
  movsd  %xmm0,(%rcx,%rdx,1)
  cmp    %rsi,%rax
  jne    L130
L103:
  add    $0x8,%rdx
  cmp    %r8,%rdx
  jne    L125
L11:
  lea    0x30(%rsp),%rdi
  mov    %r10d,%edx
  mov    %r10d,%esi
  call   <allocate_double_matrix@plt>
  test   %eax,%eax
  je     L139
  movslq 0xc(%rsp),%rcx
  mov    0x30(%rsp),%rdi
  xor    %edx,%edx
  pxor   %xmm1,%xmm1
  movsd  D3(%rip),%xmm2
  test   %ecx,%ecx
  jle    L70
  nopl   0x0(%rax,%rax,1)
L7:
  mov    (%rdi,%rdx,8),%rsi
  xor    %eax,%eax
  jmp    L84
  nopl   0x0(%rax,%rax,1)
L12:
  movsd  %xmm0,(%rsi,%rax,8)
  add    $0x1,%rax
  cmp    %rax,%rcx
  je     L159
L84:
  movapd %xmm1,%xmm0
  cmp    %eax,%edx
  jne    L12
  movapd %xmm2,%xmm0
  movsd  %xmm0,(%rsi,%rax,8)
  add    $0x1,%rax
  cmp    %rax,%rcx
  jne    L84
L159:
  add    $0x1,%rdx
  cmp    %rdx,%rcx
  jne    L7
L70:
  lea    0xc(%rsp),%rsi
  lea    0x17(%rsp),%r10
  lea    0x8(%rsp),%rdx
  sub    $0x8,%rsp
  mov    %rsi,%r9
  mov    %rsi,%rcx
  lea    0x20(%rsp),%rax
  push   %rax
  lea    0x2c(%rsp),%rax
  push   %rax
  push   0x38(%rsp)
  push   %rsi
  push   (%rdi)
  mov    0x58(%rsp),%rax
  mov    %r10,%rdi
  mov    (%rax),%r8
  call   <dgels_@plt>
  movslq 0x38(%rsp),%rax
  add    $0x30,%rsp
  test   %eax,%eax
  jle    L102
  movslq 0xc(%rsp),%rdi
  mov    0x30(%rsp),%r8
  lea    0x0(,%rax,8),%r9
  xor    %ecx,%ecx
  mov    %rdi,%r10
  nopl   0x0(%rax)
L167:
  test   %r10d,%r10d
  jle    L135
  mov    (%rbx,%rcx,1),%rsi
  xor    %eax,%eax
  nopl   0x0(%rax,%rax,1)
L5:
  mov    (%r8,%rax,8),%rdx
  movsd  (%rdx,%rcx,1),%xmm0
  movsd  %xmm0,(%rsi,%rax,8)
  add    $0x1,%rax
  cmp    %rax,%rdi
  jne    L5
L135:
  add    $0x8,%rcx
  cmp    %rcx,%r9
  jne    L167
L102:
  mov    0x28(%rsp),%rdi
  call   <free_matrix@plt>
  mov    0x30(%rsp),%rdi
  call   <free_matrix@plt>
  mov    0x20(%rsp),%rdi
  call   <free_vector@plt>
  mov    $0x1,%eax
L216:
  mov    0x38(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L205
  add    $0x40,%rsp
  pop    %rbx
  ret
L139:
  mov    $0xffffffff,%eax
  jmp    L216
L0:
  mov    $0xfffffffe,%eax
  jmp    L216
L205:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: label: D3
type_infered: byte[8]

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

assistant: ```c
int least_squares(int m, int n, double **matrix) {
  if (m < 1 || n < 1 || n > m)
    return -2;
  int i, j;
  int info, lwork = m * m;
  double *work;
  if (!allocate_double_vector(&work, lwork)) {
    return -1;
  }
  char transa = 'N';
  double **a_matrix;
  if (!allocate_double_matrix(&a_matrix, n, m)) {
    return -1;
  }
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++)
      a_matrix[j][i] = matrix[j][i];
  double **b_matrix;
  if (!allocate_double_matrix(&b_matrix, m, m)) {
    return -1;
  }
  for (i = 0; i < m; i++)
    for (j = 0; j < m; j++)
      b_matrix[i][j] = (i == j);
  dgels_(&transa, &m, &n, &m, a_matrix[0], &m, b_matrix[0], &m, work, &lwork, &info);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      matrix[i][j] = b_matrix[j][i];
  free_matrix((void **)a_matrix);
  free_matrix((void **)b_matrix);
  free_vector(work);
  return 1;
}
```