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

```asm
<Search>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %edi,-0x44(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %edx,-0x48(%rbp)
  mov    %rcx,-0x58(%rbp)
  mov    -0x44(%rbp),%eax
  add    %eax,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  movl   $0x0,-0x2c(%rbp)
  mov    -0x58(%rbp),%rax
  movsd  (%rax),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  jbe    L346
  mov    -0x58(%rbp),%rax
  movsd  (%rax),%xmm0
  mov    -0x58(%rbp),%rax
  add    $0x8,%rax
  movsd  (%rax),%xmm1
  comisd %xmm1,%xmm0
  ja     L17
L346:
  mov    -0x58(%rbp),%rax
  movsd  (%rax),%xmm1
  pxor   %xmm0,%xmm0
  comisd %xmm1,%xmm0
  jbe    L38
  mov    -0x58(%rbp),%rax
  movsd  (%rax),%xmm1
  mov    -0x58(%rbp),%rax
  add    $0x8,%rax
  movsd  (%rax),%xmm0
  comisd %xmm1,%xmm0
  jbe    L38
L17:
  mov    -0x2c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x2c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movl   $0x0,(%rax)
L38:
  movl   $0x1,-0x34(%rbp)
  jmp    L183
L98:
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mov    -0x34(%rbp),%eax
  cltq
  shl    $0x3,%rax
  lea    -0x8(%rax),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  comisd %xmm1,%xmm0
  jb     L335
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mov    -0x34(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  comisd %xmm1,%xmm0
  jbe    L335
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  ja     L219
L335:
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  mov    -0x34(%rbp),%eax
  cltq
  shl    $0x3,%rax
  lea    -0x8(%rax),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  comisd %xmm1,%xmm0
  jb     L136
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  mov    -0x34(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  comisd %xmm1,%xmm0
  jbe    L136
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  pxor   %xmm0,%xmm0
  comisd %xmm1,%xmm0
  jbe    L136
L219:
  mov    -0x2c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x2c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rax,%rdx
  mov    -0x34(%rbp),%eax
  mov    %eax,(%rdx)
L136:
  addl   $0x1,-0x34(%rbp)
L183:
  mov    -0x48(%rbp),%eax
  sub    $0x1,%eax
  cmp    %eax,-0x34(%rbp)
  jl     L98
  mov    -0x48(%rbp),%eax
  sub    $0x1,%eax
  mov    %eax,-0x30(%rbp)
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  jbe    L32
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mov    -0x30(%rbp),%eax
  cltq
  shl    $0x3,%rax
  lea    -0x8(%rax),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  comisd %xmm1,%xmm0
  ja     L244
L32:
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  pxor   %xmm0,%xmm0
  comisd %xmm1,%xmm0
  jbe    L75
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  mov    -0x30(%rbp),%eax
  cltq
  shl    $0x3,%rax
  lea    -0x8(%rax),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  comisd %xmm1,%xmm0
  jbe    L75
L244:
  mov    -0x2c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x2c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rax,%rdx
  mov    -0x30(%rbp),%eax
  mov    %eax,(%rdx)
L75:
  mov    -0x44(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    -0x2c(%rbp),%eax
  sub    %edx,%eax
  mov    %eax,-0x24(%rbp)
  jmp    L20
L316:
  mov    -0x18(%rbp),%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  jbe    L273
  movl   $0x1,-0x20(%rbp)
  jmp    L100
L273:
  movl   $0x0,-0x20(%rbp)
L100:
  movl   $0x0,-0x28(%rbp)
  movl   $0x1,-0x1c(%rbp)
  movl   $0x1,-0x30(%rbp)
  jmp    L165
L249:
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  movq   %rax,%xmm0
  call   <fabs@plt>
  mov    %rax,%rbx
  mov    -0x28(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  movq   %rax,%xmm0
  call   <fabs@plt>
  cmp    %rax,%rbx
  jge    L377
  mov    -0x30(%rbp),%eax
  mov    %eax,-0x28(%rbp)
L377:
  cmpl   $0x0,-0x20(%rbp)
  je     L40
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  pxor   %xmm0,%xmm0
  comisd %xmm1,%xmm0
  jbe    L40
  movl   $0x0,-0x20(%rbp)
  jmp    L326
L40:
  cmpl   $0x0,-0x20(%rbp)
  jne    L313
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  jbe    L313
  movl   $0x1,-0x20(%rbp)
  jmp    L326
L313:
  movl   $0x0,-0x1c(%rbp)
  jmp    L31
L326:
  addl   $0x1,-0x30(%rbp)
L165:
  mov    -0x30(%rbp),%eax
  cmp    -0x2c(%rbp),%eax
  jl     L249
L31:
  cmpl   $0x0,-0x1c(%rbp)
  je     L43
  cmpl   $0x1,-0x24(%rbp)
  jne    L43
  mov    -0x2c(%rbp),%eax
  cltq
  shl    $0x2,%rax
  lea    -0x4(%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  movq   %rax,%xmm0
  call   <fabs@plt>
  mov    %rax,%rbx
  mov    -0x18(%rbp),%rax
  mov    (%rax),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  movq   %rax,%xmm0
  call   <fabs@plt>
  cmp    %rax,%rbx
  jge    L378
  mov    -0x2c(%rbp),%eax
  cltq
  shl    $0x2,%rax
  lea    -0x4(%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    %eax,-0x28(%rbp)
  jmp    L43
L378:
  mov    -0x18(%rbp),%rax
  mov    (%rax),%eax
  mov    %eax,-0x28(%rbp)
L43:
  mov    -0x28(%rbp),%eax
  mov    %eax,-0x30(%rbp)
  jmp    L289
L208:
  mov    -0x30(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    -0x30(%rbp),%edx
  movslq %edx,%rdx
  lea    0x0(,%rdx,4),%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rax),%eax
  mov    %eax,(%rdx)
  addl   $0x1,-0x30(%rbp)
L289:
  mov    -0x30(%rbp),%eax
  cmp    -0x2c(%rbp),%eax
  jl     L208
  subl   $0x1,-0x2c(%rbp)
  subl   $0x1,-0x24(%rbp)
L20:
  cmpl   $0x0,-0x24(%rbp)
  jg     L316
  movl   $0x0,-0x34(%rbp)
  jmp    L199
L57:
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    -0x34(%rbp),%edx
  movslq %edx,%rdx
  lea    0x0(,%rdx,4),%rcx
  mov    -0x50(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rax),%eax
  mov    %eax,(%rdx)
  addl   $0x1,-0x34(%rbp)
L199:
  mov    -0x34(%rbp),%eax
  cmp    -0x44(%rbp),%eax
  jle    L57
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  nop
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

assistant: ```c
void Search(int r, int Ext[], int gridsize, double E[]) {
  int i, j, k, l, extra;
  int up, alt;
  int *foundExt;
  foundExt = (int *)malloc((2 * r) * sizeof(int));
  k = 0;
  if (((E[0] > 0.0) && (E[0] > E[1])) || ((E[0] < 0.0) && (E[0] < E[1])))
    foundExt[k++] = 0;
  for (i = 1; i < gridsize - 1; i++) {
    if (((E[i] >= E[i - 1]) && (E[i] > E[i + 1]) && (E[i] > 0.0)) || ((E[i] <= E[i - 1]) && (E[i] < E[i + 1]) && (E[i] < 0.0)))
      foundExt[k++] = i;
  }
  j = gridsize - 1;
  if (((E[j] > 0.0) && (E[j] > E[j - 1])) || ((E[j] < 0.0) && (E[j] < E[j - 1])))
    foundExt[k++] = j;
  extra = k - (r + 1);
  while (extra > 0) {
    if (E[foundExt[0]] > 0.0)
      up = 1;
    else
      up = 0;
    l = 0;
    alt = 1;
    for (j = 1; j < k; j++) {
      if (fabs(E[foundExt[j]]) < fabs(E[foundExt[l]]))
        l = j;
      if ((up) && (E[foundExt[j]] < 0.0))
        up = 0;
      else if ((!up) && (E[foundExt[j]] > 0.0))
        up = 1;
      else {
        alt = 0;
        break;
      }
    }
    if ((alt) && (extra == 1)) {
      if (fabs(E[foundExt[k - 1]]) < fabs(E[foundExt[0]]))
        l = foundExt[k - 1];
      else
        l = foundExt[0];
    }
    for (j = l; j < k; j++) {
      foundExt[j] = foundExt[j + 1];
    }
    k--;
    extra--;
  }
  for (i = 0; i <= r; i++) {
    Ext[i] = foundExt[i];
  }
  free(foundExt);
}
```