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

```asm
<mat_d>:
  endbr64
  push   %r15
  mov    %rdi,%r11
  mov    %ecx,%edi
  push   %r14
  push   %r13
  push   %r12
  movslq %edx,%r12
  push   %rbp
  movslq %esi,%rbp
  lea    0x1(%rbp),%ecx
  mov    %ebp,%r10d
  push   %rbx
  movslq %ecx,%rcx
  sub    $0x1,%r10d
  js     L21
  movslq %r12d,%rbx
  movslq %r10d,%rax
  xor    %esi,%esi
  add    %rbx,%rbx
  nopw   0x0(%rax,%rax,1)
L454:
  mov    (%r11,%rax,8),%rdx
  cmp    %di,(%rdx,%rbx,1)
  je     L439
  cmp    %rcx,%r8
  jg     L487
L425:
  xor    %edx,%edx
  test   %si,%si
  jg     L428
L600:
  mov    %edx,%eax
  mov    %esi,%edx
  mov    %eax,%esi
L444:
  mov    %r12d,%eax
  xor    %ebx,%ebx
  sub    $0x1,%eax
  mov    %eax,-0x8(%rsp)
  js     L524
L603:
  movslq %ebp,%rax
  xor    %ebx,%ebx
  mov    (%r11,%rax,8),%r13
  movslq -0x8(%rsp),%rax
  nopl   0x0(%rax)
L570:
  cmp    %di,0x0(%r13,%rax,2)
  je     L453
L524:
  cmp    %bx,%dx
  jle    L491
L108:
  lea    0x1(%r12),%eax
  xor    %r13d,%r13d
  cltq
  mov    %rax,-0x10(%rsp)
  cmp    %rax,%r9
  jle    L310
  movslq %ebp,%r13
  movslq %r12d,%rax
  lea    -0x1(%r9),%rsi
  mov    (%r11,%r13,8),%r13
  sub    %rax,%rsi
  lea    0x0(%r13,%rax,2),%r14
  xor    %eax,%eax
  nopl   0x0(%rax)
L286:
  mov    %eax,%r13d
  cmp    %di,0x2(%r14,%rax,2)
  je     L14
L310:
  cmp    %bx,%r13w
  jl     L388
  cmp    %dx,%r13w
  cmovle %r13d,%edx
  mov    %ebx,%r13d
  mov    %edx,%ebx
L388:
  not    %r10d
  mov    -0x8(%rsp),%eax
  shr    $0x1f,%r10d
  mov    %r10d,-0x4(%rsp)
  test   %eax,%eax
  js     L460
  test   %r10b,%r10b
  je     L460
  movslq %eax,%r14
  lea    -0x2(%rbp),%esi
  mov    %r12d,%r15d
  xor    %eax,%eax
  movslq %esi,%rsi
  add    %r14,%r14
  sub    %ebp,%r15d
  nopw   0x0(%rax,%rax,1)
L533:
  mov    0x8(%r11,%rsi,8),%rdx
  cmp    %di,(%rdx,%r14,1)
  je     L118
L436:
  cwtl
  imul   $0xe,%eax,%eax
  add    $0x7,%eax
  movslq %eax,%rdx
  sar    $0x1f,%eax
  imul   $0x66666667,%rdx,%rdx
  sar    $0x22,%rdx
  sub    %eax,%edx
L142:
  cmp    %dx,%r13w
  jg     L350
  cmp    %dx,%bx
  cmovg  %edx,%ebx
  mov    %r13d,%edx
  mov    %ebx,%r13d
L350:
  mov    -0x10(%rsp),%rax
  cmp    %rax,%r9
  jle    L412
  cmpb   $0x0,-0x4(%rsp)
  jne    L37
L412:
  test   %dx,%dx
  jle    L345
  cmp    -0x10(%rsp),%r9
  jg     L420
  xor    %r9d,%r9d
  xor    %eax,%eax
  jmp    L45
  nop
L428:
  mov    %r12d,%eax
  xor    %edx,%edx
  sub    $0x1,%eax
  mov    %eax,-0x8(%rsp)
  jns    L603
  xor    %ebx,%ebx
L491:
  cmp    %si,%bx
  cmovle %ebx,%esi
  mov    %edx,%ebx
  mov    %esi,%edx
  jmp    L108
  nopl   0x0(%rax,%rax,1)
L118:
  lea    (%r15,%rsi,1),%edx
  mov    %esi,%r10d
  add    $0x1,%eax
  sub    $0x1,%rsi
  not    %edx
  not    %r10d
  sub    $0x2,%r14
  shr    $0x1f,%edx
  shr    $0x1f,%r10d
  test   %r10b,%dl
  jne    L533
  jmp    L436
  nopl   0x0(%rax)
L453:
  sub    $0x1,%rax
  add    $0x1,%ebx
  test   %eax,%eax
  jns    L570
  jmp    L524
  nopl   0x0(%rax)
L14:
  lea    0x1(%rax),%r13d
  add    $0x1,%rax
  cmp    %rax,%rsi
  jne    L286
  jmp    L310
  cs nopw 0x0(%rax,%rax,1)
L439:
  sub    $0x1,%rax
  add    $0x1,%esi
  test   %eax,%eax
  jns    L454
  cmp    %rcx,%r8
  jle    L425
L487:
  mov    %rcx,%rax
  xor    %edx,%edx
L478:
  mov    (%r11,%rax,8),%r13
  cmp    %di,0x0(%r13,%rbx,1)
  je     L225
L561:
  cmp    %si,%dx
  jl     L444
  cmp    $0xfe,%dx
  jle    L600
  mov    %esi,%edx
  mov    $0xff,%esi
  jmp    L444
  nopl   0x0(%rax)
L225:
  add    $0x1,%rax
  add    $0x1,%edx
  cmp    %rax,%r8
  jg     L478
  jmp    L561
  xchg   %ax,%ax
L460:
  xor    %edx,%edx
  jmp    L142
  nopw   0x0(%rax,%rax,1)
L37:
  lea    -0x2(%rbp),%esi
  lea    (%rax,%rax,1),%r14
  xor    %r10d,%r10d
  movslq %esi,%rsi
  lea    0x1(%rax),%rbx
  nopl   0x0(%rax)
L99:
  mov    0x8(%r11,%rsi,8),%rax
  cmp    %di,(%rax,%r14,1)
  je     L580
L40:
  movswl %r10w,%r10d
  imul   $0xe,%r10d,%r10d
  add    $0x7,%r10d
  movslq %r10d,%rax
  sar    $0x1f,%r10d
  imul   $0x66666667,%rax,%rax
  sar    $0x22,%rax
  sub    %r10d,%eax
  mov    %eax,%esi
  cmp    %ax,%dx
  jg     L35
  cmp    %ax,%r13w
  cmovg  %eax,%r13d
L595:
  mov    %edx,%esi
  mov    %r13d,%edx
  nopl   (%rax)
L35:
  cmp    %rcx,%r8
  jg     L88
  xor    %r9d,%r9d
  nopl   0x0(%rax)
L571:
  cmp    %r9w,%si
  jle    L219
  mov    -0x8(%rsp),%eax
  test   %eax,%eax
  js     L212
L223:
  cmp    %rcx,%r8
  jle    L212
  movslq %eax,%rdx
  mov    %eax,%eax
  lea    0x1(%rbp,%rax,1),%r10
  add    %rdx,%rdx
  xor    %eax,%eax
  xchg   %ax,%ax
L29:
  mov    (%r11,%rcx,8),%rbx
  cmp    %di,(%rbx,%rdx,1)
  je     L470
L181:
  cwtl
  imul   $0xe,%eax,%eax
  add    $0x7,%eax
  movslq %eax,%rdx
  sar    $0x1f,%eax
  imul   $0x66666667,%rdx,%rdx
  sar    $0x22,%rdx
  sub    %eax,%edx
  mov    %edx,%eax
  cmp    %dx,%r9w
  jle    L384
  mov    %edx,%r9d
  xor    %edi,%edi
  jmp    L296
  xchg   %ax,%ax
L580:
  mov    %esi,%eax
  add    $0x1,%r10d
  not    %eax
  shr    $0x1f,%eax
  cmp    %rbx,%r9
  setg   %r15b
  sub    $0x1,%rsi
  add    $0x2,%r14
  add    $0x1,%rbx
  test   %al,%r15b
  je     L40
  jmp    L99
L345:
  xor    %eax,%eax
  test   %r13w,%r13w
  cmovg  %eax,%r13d
  cmp    -0x10(%rsp),%r9
  jg     L595
  mov    %edx,%esi
  xor    %r9d,%r9d
  mov    %r13d,%edx
  nopl   0x0(%rax)
L219:
  mov    %esi,%eax
L45:
  cmp    %dx,%r9w
  mov    %edx,%esi
  cmovle %r9d,%esi
  mov    %eax,%r9d
  mov    -0x8(%rsp),%eax
  test   %eax,%eax
  jns    L223
L212:
  xor    %eax,%eax
  test   %r9w,%r9w
  jg     L93
L384:
  cmp    %ax,%si
  cmovle %esi,%eax
  cmp    %ax,%r9w
  mov    $0x0,%eax
  cmovne %eax,%edi
L296:
  xor    %edx,%edx
  movswl %di,%eax
  test   %r9w,%r9w
  cmove  %edx,%eax
L93:
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L470:
  add    $0x1,%eax
  cmp    %rcx,%r10
  je     L181
  add    $0x1,%rcx
  sub    $0x2,%rdx
  cmp    %rcx,%r8
  je     L181
  jmp    L29
  nopw   0x0(%rax,%rax,1)
L21:
  xor    %esi,%esi
  cmp    %rcx,%r8
  jle    L428
  movslq %r12d,%rbx
  xor    %esi,%esi
  add    %rbx,%rbx
  jmp    L487
L88:
  mov    -0x10(%rsp),%rax
  lea    0x1(%r12,%r8,1),%r13
  lea    (%rax,%rax,1),%rbx
  lea    0x1(%rax),%r10
  movslq %ebp,%rax
  sub    %rax,%r13
  sub    %r12,%rax
  lea    (%r11,%rax,8),%r14
  xor    %eax,%eax
  nopl   0x0(%rax)
L49:
  mov    (%r14,%rbx,4),%r12
  cmp    %di,(%r12,%rbx,1)
  je     L13
L169:
  cwtl
  imul   $0xe,%eax,%eax
  add    $0x7,%eax
  movslq %eax,%r9
  sar    $0x1f,%eax
  imul   $0x66666667,%r9,%r9
  sar    $0x22,%r9
  sub    %eax,%r9d
  jmp    L571
  nopl   0x0(%rax,%rax,1)
L13:
  add    $0x1,%eax
  cmp    %r10,%r9
  jle    L169
  add    $0x1,%r10
  add    $0x2,%rbx
  cmp    %r10,%r13
  jne    L49
  jmp    L169
L420:
  xor    %esi,%esi
  jmp    L35
```

assistant: ```c
int mat_d(the_image, a, b, value, rows, cols)
int a, b;
short **the_image, value;
long cols, rows;
{
  int i, j, measuring;
  short dist1 = 0, dist2 = 0, dist3 = 0, dist4 = 0, dist5 = 0, dist6 = 0, dist7 = 0, dist8 = 0, min1 = 255, min2 = 255, result = 0;
  measuring = 1;
  i = a;
  j = b;
  while (measuring) {
    i--;
    if (i >= 0) {
      if (the_image[i][j] == value)
        dist1++;
      else
        measuring = 0;
    } else
      measuring = 0;
  }
  result = dist1;
  min1 = dist1;
  measuring = 1;
  i = a;
  j = b;
  while (measuring) {
    i++;
    if (i <= rows - 1) {
      if (the_image[i][j] == value)
        dist2++;
      else
        measuring = 0;
    } else
      measuring = 0;
  }
  if (dist2 <= result)
    result = dist2;
  if (dist2 < min1) {
    min2 = min1;
    min1 = dist2;
  } else if (dist2 < min2)
    min2 = dist2;
  measuring = 1;
  i = a;
  j = b;
  while (measuring) {
    j--;
    if (j >= 0) {
      if (the_image[i][j] == value)
        dist3++;
      else
        measuring = 0;
    } else
      measuring = 0;
  }
  if (dist3 <= result)
    result = dist3;
  if (dist3 < min1) {
    min2 = min1;
    min1 = dist3;
  } else if (dist3 < min2)
    min2 = dist3;
  measuring = 1;
  i = a;
  j = b;
  while (measuring) {
    j++;
    if (j <= cols - 1) {
      if (the_image[i][j] == value)
        dist4++;
      else
        measuring = 0;
    } else
      measuring = 0;
  }
  if (dist4 <= result)
    result = dist4;
  if (dist4 < min1) {
    min2 = min1;
    min1 = dist4;
  } else if (dist4 < min2)
    min2 = dist4;
  measuring = 1;
  i = a;
  j = b;
  while (measuring) {
    j--;
    i--;
    if (j >= 0 && i >= 0) {
      if (the_image[i][j] == value)
        dist5++;
      else
        measuring = 0;
    } else
      measuring = 0;
  }
  dist5 = ((dist5 * 14) + 7) / 10;
  if (dist5 <= result)
    result = dist5;
  if (dist5 < min1) {
    min2 = min1;
    min1 = dist5;
  } else if (dist5 < min2)
    min2 = dist5;
  measuring = 1;
  i = a;
  j = b;
  while (measuring) {
    j++;
    i--;
    if (j <= cols - 1 && i >= 0) {
      if (the_image[i][j] == value)
        dist6++;
      else
        measuring = 0;
    } else
      measuring = 0;
  }
  dist6 = ((dist6 * 14) + 7) / 10;
  if (dist6 <= result)
    result = dist6;
  if (dist6 < min1) {
    min2 = min1;
    min1 = dist6;
  } else if (dist6 < min2)
    min2 = dist6;
  measuring = 1;
  i = a;
  j = b;
  while (measuring) {
    j++;
    i++;
    if (j <= cols - 1 && i <= rows - 1) {
      if (the_image[i][j] == value)
        dist7++;
      else
        measuring = 0;
    } else
      measuring = 0;
  }
  dist7 = ((dist7 * 14) + 7) / 10;
  if (dist7 <= result)
    result = dist7;
  if (dist7 < min1) {
    min2 = min1;
    min1 = dist7;
  } else if (dist7 < min2)
    min2 = dist7;
  measuring = 1;
  i = a;
  j = b;
  while (measuring) {
    j--;
    i++;
    if (j >= 0 && i <= rows - 1) {
      if (the_image[i][j] == value)
        dist8++;
      else
        measuring = 0;
    } else
      measuring = 0;
  }
  dist8 = ((dist8 * 14) + 7) / 10;
  if (dist8 <= result)
    result = dist8;
  if (dist8 < min1) {
    min2 = min1;
    min1 = dist8;
  } else if (dist8 < min2)
    min2 = dist8;
  if (min1 == min2)
    result = value;
  else
    result = 0;
  if (min1 == 0)
    result = 0;
  return (result);
}
```