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

```asm
<isMagic>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,0x18(%rsp)
  test   %esi,%esi
  jle    L9
  mov    %esi,%r15d
  lea    -0x1(%rsi),%eax
  mov    0x18(%rsp),%rcx
  mov    %rcx,%r14
  lea    0x4(%rcx,%rax,4),%r12
  imul   $0xfa0,%rax,%rax
  lea    0xfa0(%rcx,%rax,1),%rax
  mov    %rax,0x10(%rsp)
  mov    %r12,%rbp
  mov    %esi,%eax
  neg    %rax
  shl    $0x2,%rax
  mov    %rax,0x8(%rsp)
  lea    D20(%rip),%r13
L81:
  mov    0x8(%rsp),%rax
  lea    (%rax,%rbp,1),%rbx
L124:
  mov    %rbx,%rsi
  mov    %r13,%rdi
  call   <scanf@plt>
  add    $0x4,%rbx
  cmp    %rbp,%rbx
  jne    L124
  add    $0xf9c,%rbp
  cmp    0x10(%rsp),%rbp
  jne    L81
  mov    $0x0,%r11d
  mov    $0x0,%r10d
  mov    $0x0,%edi
  mov    $0x1,%r9d
  mov    $0x0,%r8d
  jmp    L118
L9:
  mov    $0x0,%esi
  mov    $0x1,%r9d
  mov    $0x0,%r8d
  mov    $0x0,%ecx
  jmp    L111
L113:
  mov    %r8d,%r9d
L105:
  lea    0x1(%rdi),%eax
  add    $0x4,%r14
  add    $0xf9c,%r12
  cmp    %eax,%r15d
  je     L41
  mov    %esi,%r11d
  mov    %ecx,%r10d
  mov    %eax,%edi
L118:
  mov    0x8(%rsp),%rax
  add    %r12,%rax
  mov    %r14,%rdx
  mov    %r8d,%esi
  mov    %r8d,%ecx
L109:
  add    (%rax),%ecx
  add    (%rdx),%esi
  add    $0x4,%rax
  add    $0xf9c,%rdx
  cmp    %r12,%rax
  jne    L109
  test   %edi,%edi
  je     L105
  cmp    %r10d,%ecx
  jne    L113
  cmp    %r11d,%esi
  jne    L113
  jmp    L105
L24:
  lea    D11(%rip),%rdi
  call   <printf@plt>
  jmp    L26
L41:
  movslq %edi,%rcx
  imul   $0xf9c,%rcx,%rax
  add    0x18(%rsp),%rax
  mov    %rax,%rdx
  lea    (%rax,%rcx,4),%rax
  mov    $0x0,%r8d
  mov    $0x0,%ecx
L72:
  add    (%rdx),%ecx
  add    (%rax),%r8d
  sub    $0xf98,%rdx
  sub    $0xfa0,%rax
  sub    $0x1,%edi
  jns    L72
L111:
  cmp    %ecx,%esi
  setne  %al
  cmp    %r8d,%esi
  setne  %dl
  or     %dl,%al
  jne    L7
  test   %r9d,%r9d
  jne    L24
L7:
  lea    D4(%rip),%rdi
  call   <printf@plt>
L26:
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: unpack_data
arguments: label: D20
type_infered: string
name: unpack_data
arguments: label: D11
type_infered: string
name: unpack_data
arguments: label: D4
type_infered: string

tool: D20: %d

tool: D11: 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");
}
```