user: 请从给定的汇编指令推导出C源代码:

```asm
<checksq>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  movq   $0x0,-0x20(%rbp)
  movq   $0x0,-0x28(%rbp)
  jmp    L124
L217:
  mov    -0x28(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  add    %rax,-0x20(%rbp)
  addq   $0x1,-0x28(%rbp)
L124:
  mov    -0x28(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  jb     L217
  movq   $0x1,-0x30(%rbp)
  jmp    L149
L123:
  movq   $0x0,-0x18(%rbp)
  movq   $0x0,-0x28(%rbp)
  jmp    L158
L37:
  mov    -0x40(%rbp),%rax
  imul   -0x30(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  add    %rax,-0x18(%rbp)
  addq   $0x1,-0x28(%rbp)
L158:
  mov    -0x28(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  jb     L37
  mov    -0x20(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  je     L114
  mov    $0x0,%eax
  jmp    L146
L114:
  addq   $0x1,-0x30(%rbp)
L149:
  mov    -0x30(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  jb     L123
  movq   $0x0,-0x28(%rbp)
  jmp    L12
L84:
  movq   $0x0,-0x10(%rbp)
  movq   $0x0,-0x30(%rbp)
  jmp    L10
L56:
  mov    -0x40(%rbp),%rax
  imul   -0x30(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  add    %rax,-0x10(%rbp)
  addq   $0x1,-0x30(%rbp)
L10:
  mov    -0x30(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  jb     L56
  mov    -0x20(%rbp),%rax
  cmp    -0x10(%rbp),%rax
  je     L211
  mov    $0x0,%eax
  jmp    L146
L211:
  addq   $0x1,-0x28(%rbp)
L12:
  mov    -0x28(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  jb     L84
  movq   $0x0,-0x8(%rbp)
  movq   $0x0,-0x30(%rbp)
  jmp    L72
L208:
  mov    -0x40(%rbp),%rax
  add    $0x1,%rax
  imul   -0x30(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  add    %rax,-0x8(%rbp)
  addq   $0x1,-0x30(%rbp)
L72:
  mov    -0x30(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  jb     L208
  mov    -0x20(%rbp),%rax
  cmp    -0x8(%rbp),%rax
  je     L44
  mov    $0x0,%eax
  jmp    L146
L44:
  movq   $0x0,-0x8(%rbp)
  movq   $0x0,-0x30(%rbp)
  jmp    L94
L164:
  mov    -0x40(%rbp),%rax
  imul   -0x30(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x40(%rbp),%rax
  sub    -0x30(%rbp),%rax
  add    %rdx,%rax
  sub    $0x1,%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  add    %rax,-0x8(%rbp)
  addq   $0x1,-0x30(%rbp)
L94:
  mov    -0x30(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  jb     L164
  mov    -0x20(%rbp),%rax
  cmp    -0x8(%rbp),%rax
  je     L176
  mov    $0x0,%eax
  jmp    L146
L176:
  mov    -0x20(%rbp),%rax
L146:
  pop    %rbp
  ret
```

assistant: ```c
unsigned long int checksq(const unsigned long int *magicsq, unsigned long int d) {
  unsigned long int i, j;
  unsigned long int mc = 0;
  for (j = 0; j < d; j++) {
    mc += magicsq[j];
  }
  for (i = 1; i < d; i++) {
    unsigned long int ms = 0;
    for (j = 0; j < d; j++) {
      ms += magicsq[d * i + j];
    }
    if (mc != ms)
      return 0;
  }
  for (j = 0; j < d; j++) {
    unsigned long int ms = 0;
    for (i = 0; i < d; i++) {
      ms += magicsq[d * i + j];
    }
    if (mc != ms)
      return 0;
  }
  unsigned long int ms = 0;
  for (i = 0; i < d; i++) {
    ms += magicsq[d * i + i];
  }
  if (mc != ms)
    return 0;
  ms = 0;
  for (i = 0; i < d; i++) {
    ms += magicsq[d * i + (d - i - 1)];
  }
  if (mc != ms)
    return 0;
  return mc;
}
```