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

```asm
<edge_gray_shade_region>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x848,%rsp
  mov    %rdi,(%rsp)
  mov    %rsi,%r13
  mov    %rdx,%r14
  mov    %ecx,%r15d
  mov    %r8d,0xc(%rsp)
  mov    %r9d,0x10(%rsp)
  mov    0x880(%rsp),%eax
  mov    %eax,0x14(%rsp)
  mov    0x888(%rsp),%eax
  mov    %eax,0x1c(%rsp)
  mov    0x890(%rsp),%ebx
  mov    %ebx,0x8(%rsp)
  mov    0x898(%rsp),%r12
  mov    0x8a0(%rsp),%rbp
  pxor   %xmm1,%xmm1
  cvtsd2ss %xmm0,%xmm1
  movss  %xmm1,0x18(%rsp)
  mov    %eax,%ebx
  mov    %fs:0x28,%rax
  mov    %rax,0x838(%rsp)
  xor    %eax,%eax
  lea    -0x1(%rcx),%eax
  cmp    $0x2,%eax
  jbe    L161
  cmp    $0x4,%ecx
  je     L370
  cmp    $0x5,%ecx
  jne    L89
  sub    $0x8,%rsp
  push   $0x0
  mov    $0x0,%r9d
  mov    0x8b8(%rsp),%r8
  mov    %rbp,%rcx
  mov    %r12,%rdx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <homogeneity@plt>
  add    $0x10,%rsp
  jmp    L178
L161:
  push   0x8a8(%rsp)
  push   %rbp
  mov    %r12,%r9
  mov    $0x0,%r8d
  mov    $0x0,%ecx
  mov    %r15d,%edx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <detect_edges@plt>
  add    $0x10,%rsp
L89:
  cmp    $0x6,%r15d
  je     L155
L289:
  cmp    $0x7,%r15d
  je     L208
L178:
  cmp    $0x8,%r15d
  je     L357
L322:
  cmp    $0xa,%r15d
  je     L306
L53:
  cmp    $0xb,%r15d
  je     L93
L175:
  test   %r12,%r12
  jle    L252
  mov    %r14,%rsi
  mov    %r13,%rdi
  lea    (%r14,%r12,8),%r9
  lea    0x0(%rbp,%rbp,1),%r8
  jmp    L130
L370:
  sub    $0x8,%rsp
  push   0x8b0(%rsp)
  mov    %rbp,%r9
  mov    %r12,%r8
  mov    $0x0,%ecx
  mov    $0x0,%edx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <quick_edge@plt>
  add    $0x10,%rsp
  jmp    L289
L155:
  sub    $0x8,%rsp
  push   $0x0
  mov    $0x0,%r9d
  mov    0x8b8(%rsp),%r8
  mov    %rbp,%rcx
  mov    %r12,%rdx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <difference_edge@plt>
  add    $0x10,%rsp
  jmp    L322
L208:
  sub    $0x8,%rsp
  push   $0x0
  mov    $0x0,%r9d
  mov    0x8b8(%rsp),%r8
  mov    %rbp,%rcx
  mov    %r12,%rdx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <contrast_edge@plt>
  add    $0x10,%rsp
  jmp    L53
L357:
  push   $0x0
  push   $0x0
  mov    $0x3,%r9d
  mov    0x8b8(%rsp),%r8
  mov    %rbp,%rcx
  mov    %r12,%rdx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <gaussian_edge@plt>
  add    $0x10,%rsp
  jmp    L175
L306:
  push   $0x0
  push   $0x0
  mov    $0x3,%r9d
  mov    0x8b8(%rsp),%r8
  mov    %rbp,%rcx
  mov    %r12,%rdx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <range@plt>
  add    $0x10,%rsp
  jmp    L175
L93:
  sub    $0x8,%rsp
  push   $0x0
  mov    $0x0,%r9d
  mov    0x8b8(%rsp),%r8
  mov    %rbp,%rcx
  mov    %r12,%rdx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <variance@plt>
  add    $0x10,%rsp
  jmp    L175
L378:
  mov    (%rsi),%rdx
  movzwl (%rdx,%rax,1),%ecx
  mov    (%rdi),%rdx
  mov    %cx,(%rdx,%rax,1)
  add    $0x2,%rax
  cmp    %r8,%rax
  jne    L378
L116:
  add    $0x8,%rsi
  add    $0x8,%rdi
  cmp    %r9,%rsi
  je     L105
L130:
  mov    $0x0,%eax
  test   %rbp,%rbp
  jg     L378
  jmp    L116
L237:
  mov    (%rdi),%rdx
  movzwl (%rdx,%rax,1),%ecx
  mov    (%rsi),%rdx
  mov    %cx,(%rdx,%rax,1)
  add    $0x2,%rax
  cmp    %rax,%r8
  jne    L237
L209:
  add    $0x1,%r9
  add    $0x8,%rdi
  add    $0x8,%rsi
  cmp    %r9,%r12
  jle    L72
L82:
  mov    $0x0,%eax
  test   %rbp,%rbp
  jg     L237
  jmp    L209
L103:
  mov    %r14,%rdi
  mov    %r13,%rsi
  lea    0x0(%rbp,%rbp,1),%r8
  mov    $0x0,%r9d
  jmp    L82
L72:
  movswl 0x8(%rsp),%ecx
  mov    %rbp,%r9
  mov    %r12,%r8
  mov    %r15d,%edx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <erode_image_array@plt>
  mov    %r13,%rsi
  mov    (%rsp),%rdi
  mov    $0x0,%eax
  call   <read_image_array@plt>
  test   %r12,%r12
  jle    L251
L94:
  mov    %r13,%rdi
  mov    %r14,%rcx
  lea    (%r14,%r12,8),%r8
  lea    0x0(%rbp,%rbp,1),%rsi
  jmp    L336
L337:
  add    $0x2,%rax
  cmp    %rsi,%rax
  je     L48
L62:
  mov    (%rcx),%rdx
  cmp    %bx,(%rdx,%rax,1)
  jne    L337
  mov    (%rdi),%rdx
  movw   $0xffce,(%rdx,%rax,1)
  jmp    L337
L48:
  add    $0x8,%rdi
  add    $0x8,%rcx
  cmp    %rcx,%r8
  je     L251
L336:
  mov    $0x0,%eax
  test   %rbp,%rbp
  jg     L62
  jmp    L48
L105:
  lea    0x30(%rsp),%r15
  mov    $0x100,%esi
  mov    %r15,%rdi
  mov    $0x0,%eax
  call   <zero_histogram@plt>
  mov    %rbp,%rcx
  mov    %r12,%rdx
  mov    %r15,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <calculate_histogram@plt>
  lea    0x2e(%rsp),%rsi
  pxor   %xmm0,%xmm0
  cvtss2sd 0x18(%rsp),%xmm0
  mov    %rbp,%rcx
  mov    %r12,%rdx
  mov    %r15,%rdi
  mov    $0x1,%eax
  call   <find_cutoff_point@plt>
  movswl 0x1c(%rsp),%r15d
  movswl 0x2e(%rsp),%ecx
  sub    $0x8,%rsp
  push   %rbp
  mov    %r12,%r9
  mov    %r15d,%r8d
  mov    $0xff,%edx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <threshold_image_array@plt>
  add    $0x10,%rsp
  cmpw   $0x0,0x8(%rsp)
  jne    L103
  mov    %r13,%rsi
  mov    (%rsp),%rdi
  mov    $0x0,%eax
  call   <read_image_array@plt>
  jmp    L94
L252:
  lea    0x30(%rsp),%r15
  mov    $0x100,%esi
  mov    %r15,%rdi
  mov    $0x0,%eax
  call   <zero_histogram@plt>
  mov    %rbp,%rcx
  mov    %r12,%rdx
  mov    %r15,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <calculate_histogram@plt>
  lea    0x2e(%rsp),%rsi
  pxor   %xmm0,%xmm0
  cvtss2sd 0x18(%rsp),%xmm0
  mov    %rbp,%rcx
  mov    %r12,%rdx
  mov    %r15,%rdi
  mov    $0x1,%eax
  call   <find_cutoff_point@plt>
  movswl 0x1c(%rsp),%r15d
  movswl 0x2e(%rsp),%ecx
  sub    $0x8,%rsp
  push   %rbp
  mov    %r12,%r9
  mov    %r15d,%r8d
  mov    $0xff,%edx
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <threshold_image_array@plt>
  add    $0x10,%rsp
  cmpw   $0x0,0x8(%rsp)
  jne    L72
  mov    %r13,%rsi
  mov    (%rsp),%rdi
  mov    $0x0,%eax
  call   <read_image_array@plt>
L251:
  movswl 0xc(%rsp),%ecx
  movswl 0x14(%rsp),%edx
  sub    $0x8,%rsp
  push   %rbp
  mov    %r12,%r9
  movswl 0x20(%rsp),%r8d
  mov    %r14,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <pixel_grow@plt>
  add    $0x10,%rsp
  mov    0x838(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L147
  mov    $0x1,%eax
  add    $0x848,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L147:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int edge_gray_shade_region(in_name, the_image, out_image, edge_type, min_area, max_area, diff, percent, set_value, erode, rows, cols, bits_per_pixel)
char in_name[];
float percent;
int edge_type;
long bits_per_pixel, cols, rows;
short diff, erode, max_area, min_area, set_value, **the_image, **out_image;
{
  int a, b, count, i, j, k, length, width;
  short cutoff;
  unsigned long histogram[255 + 1];
  if (edge_type == 1 || edge_type == 2 || edge_type == 3)
    detect_edges(the_image, out_image, edge_type, 0, 0, rows, cols, bits_per_pixel);
  if (edge_type == 4) {
    quick_edge(the_image, out_image, 0, 0, rows, cols, bits_per_pixel);
  }
  if (edge_type == 5) {
    homogeneity(the_image, out_image, rows, cols, bits_per_pixel, 0, 0);
  }
  if (edge_type == 6) {
    difference_edge(the_image, out_image, rows, cols, bits_per_pixel, 0, 0);
  }
  if (edge_type == 7) {
    contrast_edge(the_image, out_image, rows, cols, bits_per_pixel, 0, 0);
  }
  if (edge_type == 8) {
    gaussian_edge(the_image, out_image, rows, cols, bits_per_pixel, 3, 0, 0);
  }
  if (edge_type == 10) {
    range(the_image, out_image, rows, cols, bits_per_pixel, 3, 0, 0);
  }
  if (edge_type == 11) {
    variance(the_image, out_image, rows, cols, bits_per_pixel, 0, 0);
  }
  for (i = 0; i < rows; i++)
    for (j = 0; j < cols; j++)
      the_image[i][j] = out_image[i][j];
  zero_histogram(histogram, 255 + 1);
  calculate_histogram(the_image, histogram, rows, cols);
  find_cutoff_point(histogram, percent, &cutoff, rows, cols);
  threshold_image_array(the_image, out_image, 255, cutoff, set_value, rows, cols);
  if (erode != 0) {
    for (i = 0; i < rows; i++)
      for (j = 0; j < cols; j++)
        the_image[i][j] = out_image[i][j];
    erode_image_array(the_image, out_image, set_value, erode, rows, cols);
  }
  read_image_array(in_name, the_image);
  for (i = 0; i < rows; i++)
    for (j = 0; j < cols; j++)
      if (out_image[i][j] == set_value)
        the_image[i][j] = -50;
  pixel_grow(the_image, out_image, diff, min_area, max_area, rows, cols);
  return (1);
}
```