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

```asm
<range>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x70,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %rdx,-0x58(%rbp)
  mov    %rcx,-0x60(%rbp)
  mov    %r8,-0x68(%rbp)
  mov    %r9d,-0x6c(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x6c(%rbp),%eax
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  sar    %eax
  mov    %eax,-0x18(%rbp)
  mov    -0x18(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,-0x14(%rbp)
  mov    -0x6c(%rbp),%eax
  imul   %eax,%eax
  mov    %eax,-0x38(%rbp)
  mov    -0x38(%rbp),%eax
  cltq
  add    %rax,%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x10(%rbp)
  movl   $0xfa,-0x20(%rbp)
  movl   $0x10,-0x1c(%rbp)
  cmpq   $0x4,-0x68(%rbp)
  jne    L102
  movl   $0xa,-0x20(%rbp)
  movl   $0x3,-0x1c(%rbp)
L102:
  mov    $0xa,%edi
  call   <putchar@plt>
  mov    -0x18(%rbp),%eax
  mov    %eax,-0x28(%rbp)
  jmp    L25
L37:
  mov    -0x28(%rbp),%ecx
  movslq %ecx,%rax
  imul   $0x66666667,%rax,%rax
  shr    $0x20,%rax
  sar    $0x2,%eax
  mov    %ecx,%esi
  sar    $0x1f,%esi
  sub    %esi,%eax
  mov    %eax,%edx
  mov    %edx,%eax
  shl    $0x2,%eax
  add    %edx,%eax
  add    %eax,%eax
  sub    %eax,%ecx
  mov    %ecx,%edx
  test   %edx,%edx
  jne    L45
  mov    -0x28(%rbp),%eax
  mov    %eax,%esi
  lea    D2(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
L45:
  mov    -0x18(%rbp),%eax
  mov    %eax,-0x24(%rbp)
  jmp    L156
L55:
  movl   $0x0,-0x2c(%rbp)
  mov    -0x18(%rbp),%eax
  neg    %eax
  mov    %eax,-0x34(%rbp)
  jmp    L148
L137:
  mov    -0x18(%rbp),%eax
  neg    %eax
  mov    %eax,-0x30(%rbp)
  jmp    L173
L30:
  mov    -0x28(%rbp),%edx
  mov    -0x34(%rbp),%eax
  add    %edx,%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x24(%rbp),%ecx
  mov    -0x30(%rbp),%eax
  add    %ecx,%eax
  cltq
  add    %rax,%rax
  add    %rdx,%rax
  mov    -0x2c(%rbp),%edx
  movslq %edx,%rdx
  lea    (%rdx,%rdx,1),%rcx
  mov    -0x10(%rbp),%rdx
  add    %rcx,%rdx
  movzwl (%rax),%eax
  mov    %ax,(%rdx)
  addl   $0x1,-0x2c(%rbp)
  addl   $0x1,-0x30(%rbp)
L173:
  mov    -0x30(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jl     L30
  addl   $0x1,-0x34(%rbp)
L148:
  mov    -0x34(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jl     L137
  lea    -0x38(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <sort_elements@plt>
  mov    -0x38(%rbp),%eax
  cltq
  add    %rax,%rax
  lea    -0x2(%rax),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movzwl (%rax),%eax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rax
  movzwl (%rax),%eax
  sub    %eax,%edx
  mov    -0x28(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rcx
  mov    -0x50(%rbp),%rax
  add    %rcx,%rax
  mov    (%rax),%rcx
  mov    -0x24(%rbp),%eax
  cltq
  add    %rax,%rax
  add    %rcx,%rax
  mov    %dx,(%rax)
  addl   $0x1,-0x24(%rbp)
L156:
  mov    -0x24(%rbp),%eax
  cltq
  mov    -0x18(%rbp),%edx
  movslq %edx,%rcx
  mov    -0x60(%rbp),%rdx
  sub    %rcx,%rdx
  cmp    %rdx,%rax
  jl     L55
  addl   $0x1,-0x28(%rbp)
L25:
  mov    -0x28(%rbp),%eax
  cltq
  mov    -0x18(%rbp),%edx
  movslq %edx,%rcx
  mov    -0x58(%rbp),%rdx
  sub    %rcx,%rdx
  cmp    %rdx,%rax
  jl     L37
  cmpl   $0x1,0x10(%rbp)
  jne    L155
  movl   $0x0,-0x28(%rbp)
  jmp    L101
L174:
  movl   $0x0,-0x24(%rbp)
  jmp    L44
L33:
  mov    -0x28(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x24(%rbp),%eax
  cltq
  add    %rax,%rax
  add    %rdx,%rax
  movzwl (%rax),%eax
  cwtl
  cmp    %eax,0x18(%rbp)
  jge    L129
  mov    -0x28(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x24(%rbp),%eax
  cltq
  add    %rax,%rax
  add    %rdx,%rax
  mov    -0x20(%rbp),%edx
  mov    %dx,(%rax)
  jmp    L3
L129:
  mov    -0x28(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x24(%rbp),%eax
  cltq
  add    %rax,%rax
  add    %rdx,%rax
  mov    -0x1c(%rbp),%edx
  mov    %dx,(%rax)
L3:
  addl   $0x1,-0x24(%rbp)
L44:
  mov    -0x24(%rbp),%eax
  cltq
  cmp    %rax,-0x60(%rbp)
  jg     L33
  addl   $0x1,-0x28(%rbp)
L101:
  mov    -0x28(%rbp),%eax
  cltq
  cmp    %rax,-0x58(%rbp)
  jg     L174
L155:
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    $0x1,%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L96
  call   <__stack_chk_fail@plt>
L96:
  leave
  ret
```

tool_calls: name: read_data
arguments: label: D2
data_type: string

tool: D2: %4d 

assistant: ```c
int range(the_image, out_image, rows, cols, bits_per_pixel, size, threshold, high)
int high, threshold, size;
short **the_image, **out_image;
long rows, cols, bits_per_pixel;
{
  int a, b, count, i, j, k, new_hi, new_low, length, sd2, sd2p1, ss, width;
  short *elements;
  sd2 = size / 2;
  sd2p1 = sd2 + 1;
  ss = size * size;
  elements = (short *)malloc(ss * sizeof(short));
  new_hi = 250;
  new_low = 16;
  if (bits_per_pixel == 4) {
    new_hi = 10;
    new_low = 3;
  }
  printf("\n");
  for (i = sd2; i < rows - sd2; i++) {
    if ((i % 10) == 0)
      printf("%4d ", i);
    for (j = sd2; j < cols - sd2; j++) {
      count = 0;
      for (a = -sd2; a < sd2p1; a++) {
        for (b = -sd2; b < sd2p1; b++) {
          elements[count] = the_image[i + a][j + b];
          count++;
        }
      }
      sort_elements(elements, &ss);
      out_image[i][j] = elements[ss - 1] - elements[0];
    }
  }
  if (threshold == 1) {
    for (i = 0; i < rows; i++) {
      for (j = 0; j < cols; j++) {
        if (out_image[i][j] > high) {
          out_image[i][j] = new_hi;
        } else {
          out_image[i][j] = new_low;
        }
      }
    }
  }
  free(elements);
  return (1);
}
```