user: 请将以下的汇编代码转换成C语言代码:

```asm
<CalculateLiveNeighbours>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r13
  push   %r12
  mov    %rdi,-0x38(%rbp)
  mov    %esi,-0x3c(%rbp)
  mov    %edx,-0x40(%rbp)
  mov    %ecx,-0x44(%rbp)
  mov    %r8d,-0x48(%rbp)
  mov    -0x3c(%rbp),%eax
  mov    %eax,%edx
  sub    $0x1,%rdx
  mov    %rdx,-0x28(%rbp)
  mov    %eax,%edx
  mov    %rdx,%r12
  mov    $0x0,%r13d
  mov    -0x3c(%rbp),%ecx
  mov    %ecx,%edx
  sub    $0x1,%rdx
  mov    %rdx,-0x20(%rbp)
  mov    %ecx,%edx
  mov    %rdx,%r10
  mov    $0x0,%r11d
  mov    -0x38(%rbp),%rdx
  mov    %rdx,-0x18(%rbp)
  movl   $0x0,-0x2c(%rbp)
  mov    -0x48(%rbp),%edx
  add    $0x1,%edx
  cmp    %edx,-0x40(%rbp)
  jbe    L108
  mov    -0x48(%rbp),%edx
  add    $0x1,%edx
  mov    %edx,%ecx
  mov    %eax,%edx
  imul   %rdx,%rcx
  mov    -0x18(%rbp),%rdx
  add    %rdx,%rcx
  mov    -0x44(%rbp),%edx
  movzbl (%rcx,%rdx,1),%edx
  movzbl %dl,%edx
  jmp    L89
L108:
  mov    $0x0,%edx
L89:
  add    %edx,-0x2c(%rbp)
  mov    -0x44(%rbp),%edx
  add    $0x1,%edx
  cmp    %edx,-0x3c(%rbp)
  jbe    L8
  mov    -0x48(%rbp),%edx
  add    $0x1,%edx
  cmp    %edx,-0x40(%rbp)
  jbe    L8
  mov    -0x48(%rbp),%edx
  add    $0x1,%edx
  mov    %edx,%ecx
  mov    %eax,%edx
  imul   %rdx,%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  mov    -0x44(%rbp),%ecx
  add    $0x1,%ecx
  mov    %ecx,%ecx
  movzbl (%rdx,%rcx,1),%edx
  movzbl %dl,%edx
  jmp    L181
L8:
  mov    $0x0,%edx
L181:
  add    %edx,-0x2c(%rbp)
  mov    -0x44(%rbp),%edx
  add    $0x1,%edx
  cmp    %edx,-0x3c(%rbp)
  jbe    L41
  mov    -0x48(%rbp),%edx
  mov    %eax,%ecx
  imul   %rdx,%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  mov    -0x44(%rbp),%ecx
  add    $0x1,%ecx
  mov    %ecx,%ecx
  movzbl (%rdx,%rcx,1),%edx
  movzbl %dl,%edx
  jmp    L157
L41:
  mov    $0x0,%edx
L157:
  add    %edx,-0x2c(%rbp)
  mov    -0x44(%rbp),%edx
  add    $0x1,%edx
  cmp    %edx,-0x3c(%rbp)
  jbe    L46
  cmpl   $0x0,-0x48(%rbp)
  je     L46
  mov    -0x48(%rbp),%edx
  sub    $0x1,%edx
  mov    %edx,%ecx
  mov    %eax,%edx
  imul   %rdx,%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  mov    -0x44(%rbp),%ecx
  add    $0x1,%ecx
  mov    %ecx,%ecx
  movzbl (%rdx,%rcx,1),%edx
  movzbl %dl,%edx
  jmp    L2
L46:
  mov    $0x0,%edx
L2:
  add    %edx,-0x2c(%rbp)
  cmpl   $0x0,-0x48(%rbp)
  je     L166
  mov    -0x48(%rbp),%edx
  sub    $0x1,%edx
  mov    %edx,%ecx
  mov    %eax,%edx
  imul   %rdx,%rcx
  mov    -0x18(%rbp),%rdx
  add    %rdx,%rcx
  mov    -0x44(%rbp),%edx
  movzbl (%rcx,%rdx,1),%edx
  movzbl %dl,%edx
  jmp    L57
L166:
  mov    $0x0,%edx
L57:
  add    %edx,-0x2c(%rbp)
  cmpl   $0x0,-0x44(%rbp)
  je     L154
  cmpl   $0x0,-0x48(%rbp)
  je     L154
  mov    -0x48(%rbp),%edx
  sub    $0x1,%edx
  mov    %edx,%ecx
  mov    %eax,%edx
  imul   %rdx,%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  mov    -0x44(%rbp),%ecx
  sub    $0x1,%ecx
  mov    %ecx,%ecx
  movzbl (%rdx,%rcx,1),%edx
  movzbl %dl,%edx
  jmp    L135
L154:
  mov    $0x0,%edx
L135:
  add    %edx,-0x2c(%rbp)
  cmpl   $0x0,-0x44(%rbp)
  je     L12
  mov    -0x48(%rbp),%edx
  mov    %eax,%ecx
  imul   %rdx,%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  mov    -0x44(%rbp),%ecx
  sub    $0x1,%ecx
  mov    %ecx,%ecx
  movzbl (%rdx,%rcx,1),%edx
  movzbl %dl,%edx
  jmp    L95
L12:
  mov    $0x0,%edx
L95:
  add    %edx,-0x2c(%rbp)
  cmpl   $0x0,-0x44(%rbp)
  je     L110
  mov    -0x48(%rbp),%edx
  add    $0x1,%edx
  cmp    %edx,-0x40(%rbp)
  jbe    L110
  mov    -0x48(%rbp),%edx
  add    $0x1,%edx
  mov    %edx,%edx
  mov    %eax,%eax
  imul   %rax,%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    -0x44(%rbp),%edx
  sub    $0x1,%edx
  mov    %edx,%edx
  movzbl (%rax,%rdx,1),%eax
  movzbl %al,%eax
  jmp    L53
L110:
  mov    $0x0,%eax
L53:
  add    %eax,-0x2c(%rbp)
  mov    -0x2c(%rbp),%eax
  pop    %r12
  pop    %r13
  pop    %rbp
  ret
```

assistant: ```c
int CalculateLiveNeighbours(unsigned char *grid, unsigned int dim_x, unsigned int dim_y, unsigned int x, unsigned int y) {
  unsigned char(*c_grid)[dim_x] = (unsigned char(*)[dim_x])grid;
  int live_neighbors = 0;
  live_neighbors += ((y + 1) < dim_y) ? c_grid[y + 1][x] : 0;
  live_neighbors += ((x + 1) < dim_x && (y + 1) < dim_y) ? c_grid[y + 1][x + 1] : 0;
  live_neighbors += ((x + 1) < dim_x) ? c_grid[y][x + 1] : 0;
  live_neighbors += ((x + 1) < dim_x && y != 0) ? c_grid[y - 1][x + 1] : 0;
  live_neighbors += (y != 0) ? c_grid[y - 1][x] : 0;
  live_neighbors += (x != 0 && y != 0) ? c_grid[y - 1][x - 1] : 0;
  live_neighbors += (x != 0) ? c_grid[y][x - 1] : 0;
  live_neighbors += (x != 0 && y + 1 < dim_y) ? c_grid[y + 1][x - 1] : 0;
  return live_neighbors;
}
```