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

```asm
<lnsrch>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %rdi,%r13
  mov    %rsi,%rbp
  mov    %rdx,(%rsp)
  mov    %rcx,%r12
  mov    %r8d,%ebx
  mov    %r9,%r14
  movsd  %xmm1,0x8(%rsp)
  mov    0x90(%rsp),%r15
  mov    $0x8,%edi
  call   <malloc@plt>
  mov    %rax,0x10(%rsp)
  mov    $0x20,%edi
  call   <malloc@plt>
  mov    %rax,0x28(%rsp)
  mov    $0x10,%edi
  call   <malloc@plt>
  mov    %rax,0x30(%rsp)
  mov    $0x10,%edi
  call   <malloc@plt>
  mov    %rax,0x20(%rsp)
  lea    0x0(,%rbx,8),%edi
  call   <malloc@plt>
  mov    %rax,0x18(%rsp)
  mov    $0x1,%r9d
  mov    %ebx,%r8d
  mov    $0x1,%ecx
  mov    0x10(%rsp),%rdx
  mov    %r12,%rsi
  mov    (%rsp),%rdi
  call   <mmult@plt>
  test   %ebx,%ebx
  jle    L142
  mov    %ebx,%eax
  mov    0x18(%rsp),%rcx
  lea    (%rcx,%rax,8),%rdi
  mov    %rcx,%rax
  mov    %rbp,%rsi
  sub    %rcx,%rsi
  movq   D70(%rip),%xmm2
  mov    %r14,%rdx
  sub    %rcx,%rdx
  movsd  D41(%rip),%xmm4
  mov    %r12,%r10
  sub    %rcx,%r10
  mov    %r10,%rcx
L158:
  movsd  (%rsi,%rax,1),%xmm0
  andpd  %xmm2,%xmm0
  movsd  (%rdx,%rax,1),%xmm1
  andpd  %xmm2,%xmm1
  movapd %xmm4,%xmm3
  divsd  %xmm1,%xmm3
  maxsd  %xmm3,%xmm0
  movsd  (%rcx,%rax,1),%xmm1
  divsd  %xmm0,%xmm1
  movsd  %xmm1,(%rax)
  add    $0x8,%rax
  cmp    %rdi,%rax
  jne    L158
L142:
  mov    %ebx,%esi
  mov    0x18(%rsp),%rdi
  call   <array_max_abs@plt>
  movsd  0x8(%rsp),%xmm6
  divsd  %xmm0,%xmm6
  movsd  %xmm6,0x38(%rsp)
  movsd  D41(%rip),%xmm7
  movsd  %xmm7,(%rsp)
  mov    $0x64,%r14d
L138:
  cmp    $0x1,%r14d
  jle    L57
  movsd  (%rsp),%xmm0
  mov    %ebx,%edx
  mov    $0x1,%esi
  mov    %r12,%rdi
  call   <scale@plt>
  mov    %ebx,%r8d
  mov    $0x1,%ecx
  mov    %r15,%rdx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <madd@plt>
  mov    %ebx,%esi
  mov    %r15,%rdi
  call   *%r13
  movsd  %xmm0,0x8(%rsp)
  mov    %ebx,%esi
  mov    %rbp,%rdi
  call   *%r13
  movapd %xmm0,%xmm1
  mov    0x10(%rsp),%rax
  movsd  (%rax),%xmm2
  movsd  (%rsp),%xmm0
  mulsd  D65(%rip),%xmm0
  mulsd  %xmm2,%xmm0
  addsd  %xmm1,%xmm0
  comisd 0x8(%rsp),%xmm0
  jb     L203
  mov    $0x0,%r14d
  jmp    L138
L203:
  movsd  0x38(%rsp),%xmm7
  comisd (%rsp),%xmm7
  ja     L130
  movsd  (%rsp),%xmm6
  ucomisd D41(%rip),%xmm6
  jp     L9
  jne    L9
  movapd %xmm2,%xmm0
  xorpd  D20(%rip),%xmm0
  movsd  0x8(%rsp),%xmm3
  subsd  %xmm1,%xmm3
  subsd  %xmm2,%xmm3
  divsd  %xmm3,%xmm0
L8:
  movsd  (%rsp),%xmm7
  movapd %xmm7,%xmm1
  mulsd  D78(%rip),%xmm1
  comisd %xmm0,%xmm1
  jb     L71
  movsd  0x8(%rsp),%xmm6
  movsd  %xmm6,0x48(%rsp)
  movsd  %xmm7,0x40(%rsp)
  movsd  %xmm1,(%rsp)
  jmp    L138
L130:
  test   %ebx,%ebx
  jle    L12
  mov    %ebx,%edx
  mov    $0x0,%eax
L171:
  movsd  0x0(%rbp,%rax,8),%xmm0
  movsd  %xmm0,(%r15,%rax,8)
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L171
  mov    $0x1,%r14d
  jmp    L138
L9:
  movsd  0x40(%rsp),%xmm5
  movapd %xmm5,%xmm3
  mulsd  %xmm5,%xmm3
  movsd  (%rsp),%xmm7
  movapd %xmm7,%xmm6
  subsd  %xmm5,%xmm6
  movsd  %xmm6,0x40(%rsp)
  movsd  D41(%rip),%xmm2
  movapd %xmm7,%xmm4
  mulsd  %xmm7,%xmm4
  divsd  %xmm4,%xmm2
  mov    0x28(%rsp),%rdi
  movsd  %xmm2,(%rdi)
  movsd  D72(%rip),%xmm2
  divsd  %xmm3,%xmm2
  movsd  %xmm2,0x8(%rdi)
  movapd %xmm5,%xmm2
  xorpd  D20(%rip),%xmm2
  divsd  %xmm4,%xmm2
  movsd  %xmm2,0x10(%rdi)
  movapd %xmm7,%xmm4
  divsd  %xmm3,%xmm4
  movsd  %xmm4,0x18(%rdi)
  movsd  0x8(%rsp),%xmm4
  subsd  %xmm1,%xmm4
  movapd %xmm4,%xmm0
  mov    0x10(%rsp),%rcx
  mulsd  (%rcx),%xmm7
  subsd  %xmm7,%xmm0
  mov    0x30(%rsp),%rsi
  movsd  %xmm0,(%rsi)
  movsd  0x48(%rsp),%xmm7
  subsd  %xmm1,%xmm7
  movapd %xmm7,%xmm0
  mulsd  (%rcx),%xmm5
  subsd  %xmm5,%xmm0
  movsd  %xmm0,0x8(%rsi)
  mov    $0x1,%r9d
  mov    $0x2,%r8d
  mov    $0x2,%ecx
  mov    0x20(%rsp),%rdx
  call   <mmult@plt>
  movsd  0x40(%rsp),%xmm0
  mov    $0x2,%edx
  mov    $0x1,%esi
  mov    0x20(%rsp),%rdi
  call   <scale@plt>
  mov    0x20(%rsp),%rax
  movsd  (%rax),%xmm0
  ucomisd D79(%rip),%xmm0
  jp     L65
  jne    L65
  mov    0x10(%rsp),%rcx
  movsd  (%rcx),%xmm0
  xorpd  D20(%rip),%xmm0
  movsd  0x8(%rax),%xmm1
  addsd  %xmm1,%xmm1
  divsd  %xmm1,%xmm0
L117:
  movsd  (%rsp),%xmm1
  mulsd  D108(%rip),%xmm1
  minsd  %xmm0,%xmm1
  movapd %xmm1,%xmm0
  jmp    L8
L65:
  mov    0x20(%rsp),%rax
  movsd  0x8(%rax),%xmm6
  movsd  %xmm6,0x40(%rsp)
  movapd %xmm0,%xmm7
  mulsd  D109(%rip),%xmm7
  movsd  %xmm7,0x48(%rsp)
  movapd %xmm6,%xmm0
  mulsd  %xmm6,%xmm0
  mov    0x10(%rsp),%rax
  mulsd  (%rax),%xmm7
  subsd  %xmm7,%xmm0
  pxor   %xmm1,%xmm1
  ucomisd %xmm0,%xmm1
  ja     L85
  sqrtsd %xmm0,%xmm0
L37:
  subsd  0x40(%rsp),%xmm0
  divsd  0x48(%rsp),%xmm0
  jmp    L117
L85:
  call   <sqrt@plt>
  jmp    L37
L12:
  mov    $0x1,%r14d
  jmp    L138
L71:
  movsd  0x8(%rsp),%xmm7
  movsd  %xmm7,0x48(%rsp)
  movsd  (%rsp),%xmm4
  movsd  %xmm4,0x40(%rsp)
  movsd  %xmm0,(%rsp)
  jmp    L138
L57:
  mov    0x10(%rsp),%rdi
  call   <free@plt>
  mov    0x28(%rsp),%rdi
  call   <free@plt>
  mov    0x30(%rsp),%rdi
  call   <free@plt>
  mov    0x20(%rsp),%rdi
  call   <free@plt>
  mov    0x18(%rsp),%rdi
  call   <free@plt>
  mov    %r14d,%eax
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: unpack_data
arguments: data_tag: D70
type_infered: qword
name: unpack_data
arguments: data_tag: D41
type_infered: f64
name: unpack_data
arguments: data_tag: D65
type_infered: byte[8]
name: unpack_data
arguments: data_tag: D20
type_infered: f32[4]
name: unpack_data
arguments: data_tag: D78
type_infered: f64
name: unpack_data
arguments: data_tag: D72
type_infered: f32[2]
name: unpack_data
arguments: data_tag: D79
type_infered: f32[2]
name: unpack_data
arguments: data_tag: D108
type_infered: f64
name: unpack_data
arguments: data_tag: D109
type_infered: f64

tool: D70: 9223372036854775807

tool: D41: 1

tool: {"D65": [0x2d,0x43,0x1c,0xeb,0xe2,0x36,0x1a,0x3f]}

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

tool: D78: 0.1

tool: {"D72": [0.0,-1.875]}

tool: {"D79": [0.0,0.0]}

tool: D108: 0.5

tool: D109: 3

assistant: ```c
int lnsrch(double (*funcpt)(double *, int), double *xi, double *jac, double *p, int N, double maxstep, double *dx, double stol, double *x) {
  int retval, i, j;
  double alpha, lambda, lambdamin, funcf, funci, lambdaprev, lambdatemp, funcprev;
  double lambda2, lambdaprev2, ll, den, rell;
  double *slopei, *temp1, *temp2, *ab, *rcheck;
  slopei = (double *)malloc(sizeof(double) * 1);
  temp1 = (double *)malloc(sizeof(double) * 4);
  temp2 = (double *)malloc(sizeof(double) * 2);
  ab = (double *)malloc(sizeof(double) * 2);
  rcheck = (double *)malloc(sizeof(double) * N);
  retval = 100;
  alpha = 1e-04;
  lambda = 1.0;
  mmult(jac, p, slopei, 1, N, 1);
  for (i = 0; i < N; ++i) {
    if (fabs(xi[i]) > 1.0 / fabs(dx[i])) {
      den = fabs(xi[i]);
    } else {
      den = 1.0 / fabs(dx[i]);
    }
    rcheck[i] = p[i] / den;
  }
  rell = array_max_abs(rcheck, N);
  lambdamin = stol / rell;
  while (retval > 1) {
    scale(p, 1, N, lambda);
    madd(xi, p, x, 1, N);
    funcf = funcpt(x, N);
    funci = funcpt(xi, N);
    if (funcf <= funci + alpha * lambda * slopei[0]) {
      retval = 0;
    } else if (lambda < lambdamin) {
      retval = 1;
      for (i = 0; i < N; ++i) {
        x[i] = xi[i];
      }
    } else {
      if (lambda == 1.0) {
        lambdatemp = -slopei[0] / (funcf - funci - slopei[0]);
      } else {
        lambda2 = lambda * lambda;
        lambdaprev2 = lambdaprev * lambdaprev;
        ll = lambda - lambdaprev;
        temp1[0] = 1.0 / lambda2;
        temp1[1] = -1.0 / lambdaprev2;
        temp1[2] = -lambdaprev / lambda2;
        temp1[3] = lambda / lambdaprev2;
        temp2[0] = funcf - funci - lambda * slopei[0];
        temp2[1] = funcprev - funci - lambdaprev * slopei[0];
        mmult(temp1, temp2, ab, 2, 2, 1);
        scale(ab, 1, 2, ll);
        if (ab[0] == 0.0) {
          lambdatemp = -slopei[0] / (2.0 * ab[1]);
        } else {
          lambdatemp = (-ab[1] + sqrt(ab[1] * ab[1] - 3.0 * ab[0] * slopei[0])) / (3.0 * ab[0]);
        }
        if (lambdatemp > 0.5 * lambda) {
          lambdatemp = 0.5 * lambda;
        }
      }
      lambdaprev = lambda;
      funcprev = funcf;
      if (lambdatemp <= 0.1 * lambda) {
        lambda = 0.1 * lambda;
      } else {
        lambda = lambdatemp;
      }
    }
  }
  free(slopei);
  free(temp1);
  free(temp2);
  free(ab);
  free(rcheck);
  return retval;
}
```