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

```asm
<isMagic>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %esi,-0x3c(%rbp)
  movl   $0x1,-0x24(%rbp)
  movl   $0x0,-0x20(%rbp)
  jmp    L5
L42:
  movl   $0x0,-0x1c(%rbp)
  jmp    L30
L160:
  mov    -0x20(%rbp),%eax
  cltq
  imul   $0xf9c,%rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  mov    -0x1c(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rdx,%rax
  mov    %rax,%rsi
  lea    D17(%rip),%rax
  mov    %rax,%rdi
  call   <scanf@plt>
  addl   $0x1,-0x1c(%rbp)
L30:
  mov    -0x1c(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jl     L160
  addl   $0x1,-0x20(%rbp)
L5:
  mov    -0x20(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jl     L42
  movl   $0x0,-0x18(%rbp)
  movl   $0x0,-0x14(%rbp)
  movl   $0x0,-0x10(%rbp)
  movl   $0x0,-0xc(%rbp)
  movl   $0x0,-0x20(%rbp)
  jmp    L72
L51:
  mov    -0x18(%rbp),%eax
  mov    %eax,-0x14(%rbp)
  movl   $0x0,-0x18(%rbp)
  mov    -0x10(%rbp),%eax
  mov    %eax,-0xc(%rbp)
  movl   $0x0,-0x10(%rbp)
  movl   $0x0,-0x1c(%rbp)
  jmp    L19
L134:
  mov    -0x20(%rbp),%eax
  cltq
  imul   $0xf9c,%rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  mov    -0x1c(%rbp),%eax
  cltq
  mov    (%rdx,%rax,4),%eax
  add    %eax,-0x18(%rbp)
  mov    -0x1c(%rbp),%eax
  cltq
  imul   $0xf9c,%rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  mov    -0x20(%rbp),%eax
  cltq
  mov    (%rdx,%rax,4),%eax
  add    %eax,-0x10(%rbp)
  addl   $0x1,-0x1c(%rbp)
L19:
  mov    -0x1c(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jl     L134
  cmpl   $0x0,-0x20(%rbp)
  jne    L129
  mov    -0x18(%rbp),%eax
  mov    %eax,-0x14(%rbp)
  mov    -0x10(%rbp),%eax
  mov    %eax,-0xc(%rbp)
L129:
  mov    -0x18(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jne    L64
  mov    -0x10(%rbp),%eax
  cmp    -0xc(%rbp),%eax
  je     L121
L64:
  movl   $0x0,-0x24(%rbp)
L121:
  addl   $0x1,-0x20(%rbp)
L72:
  mov    -0x20(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jl     L51
  movl   $0x0,-0x1c(%rbp)
  movl   $0x0,-0x8(%rbp)
  movl   $0x0,-0x4(%rbp)
  mov    -0x3c(%rbp),%eax
  sub    $0x1,%eax
  mov    %eax,-0x20(%rbp)
  jmp    L105
L15:
  mov    -0x20(%rbp),%eax
  cltq
  imul   $0xf9c,%rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  mov    -0x1c(%rbp),%eax
  cltq
  mov    (%rdx,%rax,4),%eax
  add    %eax,-0x8(%rbp)
  mov    -0x20(%rbp),%eax
  cltq
  imul   $0xf9c,%rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  mov    -0x20(%rbp),%eax
  cltq
  mov    (%rdx,%rax,4),%eax
  add    %eax,-0x4(%rbp)
  addl   $0x1,-0x1c(%rbp)
  subl   $0x1,-0x20(%rbp)
L105:
  cmpl   $0x0,-0x20(%rbp)
  jns    L15
  mov    -0x8(%rbp),%eax
  cmp    -0x10(%rbp),%eax
  jne    L58
  mov    -0x4(%rbp),%eax
  cmp    -0x10(%rbp),%eax
  je     L70
L58:
  movl   $0x0,-0x24(%rbp)
L70:
  cmpl   $0x1,-0x24(%rbp)
  jne    L36
  lea    D16(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  jmp    L110
L36:
  lea    D4(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
L110:
  nop
  leave
  ret
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D17
datatype: string
name: extract_symbolic_data
arguments: data_tag: D16
datatype: string
name: extract_symbolic_data
arguments: data_tag: D4
datatype: string

tool: D17: %d

tool: D16: MAGIC


tool: D4: NO MAGIC


assistant: ```c
void isMagic(int square[999][999], int n) {
  int magical = 1;
  int i;
  int j;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      scanf("%d", &square[i][j]);
  int curr_sumrows = 0;
  int prev_sumrows = 0;
  int curr_sumcols = 0;
  int prev_sumcols = 0;
  for (i = 0; i < n; i++) {
    prev_sumrows = curr_sumrows;
    curr_sumrows = 0;
    prev_sumcols = curr_sumcols;
    curr_sumcols = 0;
    for (j = 0; j < n; j++) {
      curr_sumrows = curr_sumrows + square[i][j];
      curr_sumcols = curr_sumcols + square[j][i];
    }
    if (i == 0) {
      prev_sumrows = curr_sumrows;
      prev_sumcols = curr_sumcols;
    }
    if (curr_sumrows != prev_sumrows || curr_sumcols != prev_sumcols)
      magical = 0;
  }
  j = 0;
  int curr_sumdiag1 = 0;
  int curr_sumdiag2 = 0;
  for (i = n - 1; i >= 0; i--) {
    curr_sumdiag1 = curr_sumdiag1 + square[i][j];
    curr_sumdiag2 = curr_sumdiag2 + square[i][i];
    j++;
  }
  if (curr_sumdiag1 != curr_sumcols || curr_sumdiag2 != curr_sumcols)
    magical = 0;
  if (magical == 1)
    printf("MAGIC\n");
  else
    printf("NO MAGIC\n");
}
```