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

```asm
<how_many_mines>:
  endbr64
  push   %rbx
  movslq %edx,%rbx
  mov    %ecx,%edx
  mov    %rdi,%r8
  lea    -0x1(%rbx),%ecx
  mov    %esi,%eax
  mov    %rbx,%r10
  cmp    %ecx,%edx
  mov    %ecx,%edi
  movslq %ecx,%rcx
  setle  %sil
  shr    $0x1f,%edi
  or     %edi,%esi
  lea    0x1(%rbx),%edi
  test   %edi,%edi
  js     L409
  cmp    %edi,%edx
  jle    L409
  movslq %edi,%r11
  test   %sil,%sil
  jne    L58
  mov    %eax,%esi
  sub    $0x1,%esi
  js     L303
  cmp    %esi,%edx
  jle    L303
  movslq %esi,%rsi
  xor    %r9d,%r9d
  mov    (%r8,%rsi,8),%rsi
  cmpl   $0x3e8,(%rsi,%rcx,4)
  sete   %r9b
  test   %ebx,%ebx
  js     L41
  cmp    %ebx,%edx
  jle    L41
  cmpl   $0x3e8,(%rsi,%rbx,4)
  jne    L41
  add    $0x1,%r9d
  nopl   0x0(%rax)
L41:
  cmpl   $0x3e8,(%rsi,%r11,4)
  jne    L140
  add    $0x1,%r9d
  jmp    L140
  nopw   0x0(%rax,%rax,1)
L409:
  test   %sil,%sil
  je     L33
  lea    -0x1(%rax),%ecx
  cmp    %ecx,%edx
  jle    L536
  test   %ecx,%ecx
  js     L536
  cmp    %r10d,%edx
  jle    L536
  test   %r10d,%r10d
  js     L536
  movslq %ecx,%rcx
  xor    %r9d,%r9d
  mov    (%r8,%rcx,8),%rcx
  cmpl   $0x3e8,(%rcx,%rbx,4)
  sete   %r9b
  jmp    L540
  nopl   0x0(%rax)
L33:
  lea    -0x1(%rax),%esi
  cmp    %esi,%edx
  jle    L638
  test   %esi,%esi
  js     L638
  movslq %esi,%rsi
  xor    %r9d,%r9d
  mov    (%r8,%rsi,8),%rsi
  cmpl   $0x3e8,(%rsi,%rcx,4)
  sete   %r9b
  cmp    %r10d,%edx
  jle    L148
  test   %r10d,%r10d
  js     L148
  cmpl   $0x3e8,(%rsi,%rbx,4)
  jne    L148
  add    $0x1,%r9d
  jmp    L148
  nopl   (%rax)
L536:
  xor    %r9d,%r9d
L540:
  add    $0x1,%eax
  js     L21
  cmp    %edx,%eax
  jge    L21
  cmp    %r10d,%edx
  jle    L21
  test   %r10d,%r10d
  js     L21
  cltq
  mov    (%r8,%rax,8),%rax
L205:
  cmpl   $0x3e8,(%rax,%rbx,4)
  je     L289
L21:
  mov    %r9d,%eax
  pop    %rbx
  ret
  cs nopw 0x0(%rax,%rax,1)
L58:
  lea    -0x1(%rax),%ecx
  cmp    %ecx,%edx
  jle    L465
  test   %ecx,%ecx
  js     L465
  cmp    %ebx,%edx
  jle    L483
  test   %ebx,%ebx
  js     L483
  movslq %ecx,%rcx
  xor    %r9d,%r9d
  mov    (%r8,%rcx,8),%rsi
  cmpl   $0x3e8,(%rsi,%rbx,4)
  sete   %r9b
  jmp    L4
  nopl   (%rax)
L638:
  xor    %r9d,%r9d
L148:
  cmp    %edx,%eax
  jge    L341
  test   %eax,%eax
  js     L341
  movslq %eax,%rsi
  mov    (%r8,%rsi,8),%rsi
  cmpl   $0x3e8,(%rsi,%rcx,4)
  je     L661
  nop
L341:
  add    $0x1,%eax
  cmp    %eax,%edx
  jle    L21
  test   %eax,%eax
  js     L21
  cltq
  mov    (%r8,%rax,8),%rax
  cmpl   $0x3e8,(%rax,%rcx,4)
  je     L683
L364:
  cmp    %r10d,%edx
  jle    L21
  test   %r10d,%r10d
  jns    L205
  jmp    L21
  nopl   (%rax)
L465:
  xor    %r9d,%r9d
L509:
  cmp    %edx,%eax
  jge    L204
  test   %eax,%eax
  js     L204
  movslq %eax,%rcx
  mov    (%r8,%rcx,8),%rcx
  cmpl   $0x3e8,(%rcx,%r11,4)
  je     L56
L204:
  add    $0x1,%eax
  js     L21
  cmp    %eax,%edx
  jle    L21
  cltq
  test   %r10d,%r10d
  js     L99
  cmp    %r10d,%edx
  jle    L99
  mov    (%r8,%rax,8),%rdx
  cmpl   $0x3e8,(%rdx,%rbx,4)
  jne    L99
  add    $0x1,%r9d
  cs nopw 0x0(%rax,%rax,1)
L99:
  mov    (%r8,%rax,8),%rax
L616:
  cmpl   $0x3e8,(%rax,%r11,4)
  jne    L21
L289:
  add    $0x1,%r9d
  jmp    L21
  nopl   0x0(%rax,%rax,1)
L303:
  xor    %r9d,%r9d
L140:
  test   %eax,%eax
  js     L130
  cmp    %edx,%eax
  jge    L130
  movslq %eax,%rsi
  mov    (%r8,%rsi,8),%rsi
  cmpl   $0x3e8,(%rsi,%rcx,4)
  je     L52
L23:
  cmpl   $0x3e8,(%rsi,%r11,4)
  je     L159
L130:
  add    $0x1,%eax
  cmp    %eax,%edx
  jle    L21
  test   %eax,%eax
  js     L21
  cltq
  mov    (%r8,%rax,8),%rax
  cmpl   $0x3e8,(%rax,%rcx,4)
  je     L663
L108:
  cmp    %r10d,%edx
  jle    L616
  test   %r10d,%r10d
  js     L616
  cmpl   $0x3e8,(%rax,%rbx,4)
  jne    L616
  add    $0x1,%r9d
  jmp    L616
  nopl   0x0(%rax,%rax,1)
L483:
  xor    %r9d,%r9d
  movslq %ecx,%rcx
L4:
  mov    (%r8,%rcx,8),%rcx
  cmpl   $0x3e8,(%rcx,%r11,4)
  jne    L509
  add    $0x1,%r9d
  jmp    L509
L661:
  add    $0x1,%r9d
  jmp    L341
L663:
  add    $0x1,%r9d
  jmp    L108
L683:
  add    $0x1,%r9d
  jmp    L364
L52:
  add    $0x1,%r9d
  jmp    L23
L56:
  add    $0x1,%r9d
  jmp    L204
L159:
  add    $0x1,%r9d
  jmp    L130
```

assistant: ```c
int how_many_mines(int **map, int x, int y, int length) {
  int i, j, counts = 0;
  for (i = -1; i <= 1; i++) {
    if ((x + i) < 0 || (x + i) >= length) {
      continue;
    }
    for (j = -1; j <= 1; j++) {
      if (((y + j) < 0) || ((y + j) >= length) || (i == j && i == 0)) {
        continue;
      }
      if (1000 == map[x + i][y + j]) {
        counts++;
      }
    }
  }
  return counts;
}
```