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

```asm
<mat_prod>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %r9d,%r13d
  push   %r12
  push   %rbp
  push   %rbx
  mov    %edx,%ebx
  sub    $0x48,%rsp
  mov    %rdi,0x8(%rsp)
  mov    %esi,0x14(%rsp)
  mov    %rcx,0x20(%rsp)
  cmp    %r8d,%edx
  je     L12
  lea    D23(%rip),%rdi
  call   <die@plt>
L12:
  cmpq   $0x0,0x8(%rsp)
  je     L54
  cmpq   $0x0,0x20(%rsp)
  je     L54
L106:
  mov    0x14(%rsp),%edi
  imul   %r13d,%edi
  shl    $0x2,%edi
  call   <malloc@plt>
  mov    %rax,0x18(%rsp)
  test   %rax,%rax
  je     L51
L69:
  mov    0x14(%rsp),%eax
  test   %eax,%eax
  jle    L24
  test   %r13d,%r13d
  jle    L24
  movslq %r13d,%rax
  movl   $0x0,0x10(%rsp)
  xor    %r15d,%r15d
  xor    %r14d,%r14d
  mov    %rax,0x28(%rsp)
  lea    0x0(,%rax,4),%r10
  mov    0x8(%rsp),%rax
  add    $0x4,%rax
  mov    %rax,0x38(%rsp)
  lea    -0x1(%rbx),%eax
  mov    %rax,0x30(%rsp)
  nopl   (%rax)
L1:
  mov    0x18(%rsp),%rax
  mov    0x8(%rsp),%rsi
  xor    %r11d,%r11d
  mov    0x20(%rsp),%rbp
  lea    (%rax,%r15,4),%r8
  movslq %r14d,%rax
  lea    (%rsi,%rax,4),%r12
  mov    0x38(%rsp),%rsi
  add    0x30(%rsp),%rax
  lea    (%rsi,%rax,4),%r9
  nopl   0x0(%rax,%rax,1)
L90:
  movl   $0x0,(%r8)
  mov    %rbp,%rsi
  mov    %r12,%rcx
  xor    %eax,%eax
  test   %ebx,%ebx
  jle    L19
  nopl   0x0(%rax,%rax,1)
L21:
  mov    (%rcx),%edx
  imul   (%rsi),%edx
  add    $0x4,%rcx
  add    %r10,%rsi
  add    %eax,%edx
  movslq %edx,%rax
  mov    %edx,%edi
  imul   $0x3ee4f99d,%rax,%rax
  sar    $0x1f,%edi
  sar    $0x27,%rax
  sub    %edi,%eax
  imul   $0x209,%eax,%edi
  mov    %edx,%eax
  sub    %edi,%eax
  mov    %eax,(%r8)
  cmp    %rcx,%r9
  jne    L21
L19:
  add    $0x1,%r11d
  add    $0x4,%r8
  add    $0x4,%rbp
  cmp    %r11d,%r13d
  jne    L90
  addl   $0x1,0x10(%rsp)
  add    %ebx,%r14d
  mov    0x10(%rsp),%eax
  add    0x28(%rsp),%r15
  cmp    %eax,0x14(%rsp)
  jne    L1
L24:
  mov    0x18(%rsp),%rax
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L54:
  lea    D8(%rip),%rdi
  call   <die@plt>
  jmp    L106
L51:
  lea    D13(%rip),%rdi
  call   <die@plt>
  jmp    L69
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D23
datatype: string
name: extract_symbolic_data
arguments: data_tag: D8
datatype: string
name: extract_symbolic_data
arguments: data_tag: D13
datatype: string

tool: D23: tried to multiply matrices with mismatched dimensions.

tool: D8: tried to matrix-multiply a null pointer.

tool: D13: malloc fail.

assistant: ```c
int *mat_prod(int x[], int xrows, int xcols, int y[], int yrows, int ycols) {
  int i;
  int j;
  int k;
  int *z;
  if (xcols != yrows) {
    die("tried to multiply matrices with mismatched dimensions.");
  }
  if ((x == NULL) || (y == NULL)) {
    die("tried to matrix-multiply a null pointer.");
  }
  z = malloc(xrows * ycols * sizeof(int));
  if (z == NULL) {
    die("malloc fail.");
  }
  for (i = 0; i < xrows; i++) {
    for (j = 0; j < ycols; j++) {
      z[i * ycols + j] = 0;
      for (k = 0; k < xcols; k++) {
        z[i * ycols + j] += x[i * xcols + k] * y[k * ycols + j];
        z[i * ycols + j] %= 521;
      }
    }
  }
  return z;
}
```