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

```asm
<orangesRotting>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    (%rdx),%ebp
  test   %esi,%esi
  jle    L549
  mov    %ebp,%eax
  mov    %esi,%r12d
  mov    %ebp,%r8d
  movdqa D0(%rip),%xmm2
  shr    $0x2,%eax
  lea    -0x1(%r12),%ebx
  mov    %rdi,%r15
  mov    %rdi,%rsi
  sub    $0x1,%eax
  shl    $0x3,%rbx
  lea    -0x1(%rbp),%r9d
  and    $0xfffffffc,%r8d
  shl    $0x4,%rax
  lea    0x8(%rdi,%rbx,1),%rdi
  xor    %r13d,%r13d
  mov    %rax,0x20(%rsp)
  lea    0x10(%rax),%r10
  xchg   %ax,%ax
L492:
  test   %ebp,%ebp
  jle    L44
  mov    (%rsi),%rcx
  cmp    $0x2,%r9d
  jbe    L705
  mov    %rcx,%rax
  lea    (%r10,%rcx,1),%rdx
  pxor   %xmm1,%xmm1
L619:
  movdqu (%rax),%xmm0
  add    $0x10,%rax
  pcmpeqd %xmm2,%xmm0
  psubd  %xmm0,%xmm1
  cmp    %rdx,%rax
  jne    L619
  movdqa %xmm1,%xmm0
  psrldq $0x8,%xmm0
  paddd  %xmm0,%xmm1
  movdqa %xmm1,%xmm0
  psrldq $0x4,%xmm0
  paddd  %xmm0,%xmm1
  movd   %xmm1,%eax
  add    %eax,%r13d
  mov    %r8d,%eax
  cmp    %r8d,%ebp
  je     L44
L127:
  movslq %eax,%rdx
  cmpl   $0x1,(%rcx,%rdx,4)
  lea    0x0(,%rdx,4),%r11
  sete   %dl
  movzbl %dl,%edx
  add    %edx,%r13d
  lea    0x1(%rax),%edx
  cmp    %ebp,%edx
  jge    L44
  cmpl   $0x1,0x4(%rcx,%r11,1)
  jne    L443
  add    $0x1,%r13d
L443:
  add    $0x2,%eax
  cmp    %ebp,%eax
  jge    L44
  cmpl   $0x1,0x8(%rcx,%r11,1)
  jne    L44
  add    $0x1,%r13d
  nopl   0x0(%rax)
L44:
  add    $0x8,%rsi
  cmp    %rdi,%rsi
  jne    L492
  mov    %r9d,0x18(%rsp)
  mov    %r8d,0x3c(%rsp)
  test   %r13d,%r13d
  je     L194
  lea    0x0(,%r12,8),%r14d
  mov    %r14d,%edi
  call   <malloc@plt>
  mov    %r14d,%edi
  lea    0x0(,%rbp,4),%r14d
  mov    %rax,0x28(%rsp)
  call   <malloc@plt>
  mov    %r13d,0x48(%rsp)
  mov    %rax,0x10(%rsp)
  mov    0x28(%rsp),%rax
  mov    %r12d,0x4c(%rsp)
  mov    %ebp,%r12d
  mov    0x3c(%rsp),%ebp
  lea    0x8(%rax,%rbx,1),%rsi
  mov    0x18(%rsp),%ebx
  sub    %rax,%r15
  mov    %rsi,0x8(%rsp)
  lea    0x4(,%rbx,4),%rdi
  mov    %r15,0x18(%rsp)
  mov    %rax,%r15
  mov    %rdi,0x30(%rsp)
  mov    %ebx,0x38(%rsp)
  mov    %rbx,0x40(%rsp)
  mov    %rax,%rbx
  nopw   0x0(%rax,%rax,1)
L74:
  mov    %r14d,%edi
  call   <malloc@plt>
  mov    %r14d,%edi
  mov    %rax,%r13
  call   <malloc@plt>
  mov    %rax,%rdx
  test   %r12d,%r12d
  jle    L540
  mov    0x18(%rsp),%rax
  mov    %r13,%r10
  mov    (%rax,%r15,1),%rdi
  mov    %rdx,%rax
  lea    0x4(%rdi),%r9
  sub    %r9,%rax
  cmp    $0x8,%rax
  seta   %al
  sub    %r9,%r10
  cmp    $0x8,%r10
  seta   %r9b
  and    %r9d,%eax
  cmp    $0x1,%r12d
  setne  %r9b
  test   %r9b,%al
  je     L252
  lea    0x4(%rdx),%r9
  mov    %r13,%rax
  sub    %r9,%rax
  cmp    $0x8,%rax
  jbe    L252
  cmpl   $0x2,0x38(%rsp)
  jbe    L591
  mov    0x20(%rsp),%rax
  mov    %rdi,%r10
  mov    %r13,%r9
  sub    %rdx,%r10
  sub    %rdx,%r9
  lea    0x10(%rdx,%rax,1),%r11
  mov    %rdx,%rax
  nopl   0x0(%rax,%rax,1)
L221:
  movdqu (%r10,%rax,1),%xmm0
  movups %xmm0,(%rax)
  movups %xmm0,(%r9,%rax,1)
  add    $0x10,%rax
  cmp    %r11,%rax
  jne    L221
  cmp    %ebp,%r12d
  je     L540
  mov    %r12d,%r9d
  sub    %ebp,%r9d
  cmp    $0x1,%r9d
  je     L616
  mov    %ebp,%r10d
  mov    %ebp,%eax
L588:
  mov    (%rdi,%r10,4),%r11
  mov    %r11,(%rdx,%r10,4)
  mov    %r11,0x0(%r13,%r10,4)
  mov    %r9d,%r10d
  and    $0xfffffffe,%r10d
  add    %r10d,%eax
  cmp    %r10d,%r9d
  je     L540
L43:
  cltq
  mov    (%rdi,%rax,4),%edi
  mov    %edi,(%rdx,%rax,4)
  mov    %edi,0x0(%r13,%rax,4)
L540:
  mov    0x10(%rsp),%rax
  mov    %r13,(%r15)
  sub    %rbx,%rax
  mov    %rdx,(%rax,%r15,1)
  add    $0x8,%r15
  cmp    0x8(%rsp),%r15
  jne    L74
  mov    0x4c(%rsp),%r15d
  mov    0x40(%rsp),%rbx
  mov    %r12d,%ebp
  xor    %r11d,%r11d
  mov    0x48(%rsp),%r13d
  mov    0x10(%rsp),%r14
  mov    0x28(%rsp),%r9
  mov    %r15,%r12
  nopw   0x0(%rax,%rax,1)
L177:
  add    $0x1,%r11d
  xor    %edi,%edi
  xor    %r10d,%r10d
  nopl   0x0(%rax)
L477:
  test   %ebp,%ebp
  jle    L247
  lea    0x1(%rdi),%eax
  mov    (%r9,%rdi,8),%rdx
  mov    (%r14,%rdi,8),%rsi
  cmp    %eax,%r12d
  mov    $0x0,%eax
  jle    L86
  test   %rdi,%rdi
  je     L338
  mov    %r11d,0x8(%rsp)
  jmp    L613
  nopl   0x0(%rax)
L167:
  mov    %ecx,(%rsi,%rax,4)
  lea    0x1(%rax),%rcx
  cmp    %rbx,%rax
  je     L548
L108:
  mov    %rcx,%rax
L613:
  mov    (%rdx,%rax,4),%ecx
  lea    0x0(,%rax,4),%r8
  cmp    $0x1,%ecx
  jne    L167
  mov    -0x8(%r9,%rdi,8),%r11
  cmpl   $0x2,(%r11,%rax,4)
  je     L615
  mov    0x8(%r9,%rdi,8),%r11
  cmpl   $0x2,(%r11,%r8,1)
  je     L615
  test   %rax,%rax
  je     L332
  cmpl   $0x2,-0x4(%rdx,%rax,4)
  je     L615
L332:
  lea    0x1(%rax),%r8d
  cmp    %r8d,%ebp
  jle    L299
  cmpl   $0x2,0x4(%rdx,%rax,4)
  je     L615
L299:
  mov    %ecx,(%rsi,%rax,4)
  add    $0x1,%r10d
  lea    0x1(%rax),%rcx
  cmp    %rbx,%rax
  jne    L108
  nopl   0x0(%rax,%rax,1)
L548:
  mov    0x8(%rsp),%r11d
L247:
  add    $0x1,%rdi
  cmp    %rdi,%r15
  jne    L477
  cmp    %r13d,%r10d
  je     L503
  mov    %r14,%rax
  mov    %r9,%r14
  test   %r10d,%r10d
  jle    L313
  mov    %r10d,%r13d
  mov    %rax,%r9
  jmp    L177
L313:
  mov    0x10(%rsp),%rsi
  mov    0x28(%rsp),%rdi
  mov    %r12d,%edx
  mov    %r11d,0x8(%rsp)
  call   <freeSpace@plt>
  mov    0x8(%rsp),%r13d
L194:
  add    $0x58,%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L705:
  xor    %eax,%eax
  jmp    L127
  cs nopw 0x0(%rax,%rax,1)
L333:
  mov    $0x2,%ecx
  nopl   (%rax)
L187:
  mov    %ecx,(%rsi,%rax,4)
  lea    0x1(%rax),%rcx
  cmp    %rbx,%rax
  je     L247
  mov    %rcx,%rax
L338:
  mov    (%rdx,%rax,4),%ecx
  cmp    $0x1,%ecx
  jne    L187
  mov    0x8(%r9),%r8
  cmpl   $0x2,(%r8,%rax,4)
  je     L333
  test   %rax,%rax
  je     L465
  cmpl   $0x2,-0x4(%rdx,%rax,4)
  je     L333
L465:
  lea    0x1(%rax),%r8d
  cmp    %r8d,%ebp
  jle    L528
  cmpl   $0x2,0x4(%rdx,%rax,4)
  je     L333
L528:
  add    $0x1,%r10d
  jmp    L187
  nopl   0x0(%rax)
L615:
  mov    $0x2,%ecx
  jmp    L167
  nopw   0x0(%rax,%rax,1)
L86:
  test   %rdi,%rdi
  jne    L200
  jmp    L695
  nopw   0x0(%rax,%rax,1)
L508:
  mov    %ecx,(%rsi,%rax,4)
  lea    0x1(%rax),%rcx
  cmp    %rbx,%rax
  je     L247
  mov    %rcx,%rax
L200:
  mov    (%rdx,%rax,4),%ecx
  cmp    $0x1,%ecx
  jne    L508
  mov    -0x8(%r9,%rdi,8),%r8
  cmpl   $0x2,(%r8,%rax,4)
  je     L4
  test   %rax,%rax
  je     L0
  cmpl   $0x2,-0x4(%rdx,%rax,4)
  je     L4
L0:
  lea    0x1(%rax),%r8d
  cmp    %r8d,%ebp
  jle    L211
  cmpl   $0x2,0x4(%rdx,%rax,4)
  je     L4
L211:
  add    $0x1,%r10d
  jmp    L508
  nopl   0x0(%rax)
L70:
  test   %rax,%rax
  je     L385
  cmpl   $0x2,-0x4(%rdx,%rax,4)
  je     L325
L385:
  lea    0x1(%rax),%r8d
  cmp    %r8d,%ebp
  jle    L551
  cmpl   $0x2,0x4(%rdx,%rax,4)
  je     L325
L551:
  add    $0x1,%r10d
L414:
  mov    %ecx,(%rsi,%rax,4)
  lea    0x1(%rax),%rcx
  cmp    %rbx,%rax
  je     L247
  mov    %rcx,%rax
L695:
  mov    (%rdx,%rax,4),%ecx
  cmp    $0x1,%ecx
  jne    L414
  jmp    L70
  nopl   (%rax)
L4:
  mov    $0x2,%ecx
  jmp    L508
L325:
  mov    $0x2,%ecx
  jmp    L414
L252:
  mov    0x30(%rsp),%rax
  mov    %r13,%r11
  sub    %rdx,%rdi
  sub    %rdx,%r11
  lea    (%rdx,%rax,1),%r10
  mov    %rdx,%rax
  cs nopw 0x0(%rax,%rax,1)
L132:
  mov    (%rdi,%rax,1),%ecx
  mov    %ecx,(%rax)
  mov    %ecx,(%r11,%rax,1)
  add    $0x4,%rax
  cmp    %r10,%rax
  jne    L132
  jmp    L540
L591:
  mov    %r12d,%r9d
  xor    %r10d,%r10d
  xor    %eax,%eax
  jmp    L588
L503:
  mov    0x10(%rsp),%rsi
  mov    0x28(%rsp),%rdi
  mov    %r12d,%edx
  mov    $0xffffffff,%r13d
  call   <freeSpace@plt>
  jmp    L194
L616:
  mov    %ebp,%eax
  jmp    L43
L549:
  xor    %r13d,%r13d
  jmp    L194
```

tool_calls: name: read_data
arguments: tag: D0
type: byte[16]

tool: {"D0": [0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00]}

assistant: ```c
int orangesRotting(int **grid, int gridSize, int *gridColSize) {
  int colSize = *gridColSize;
  int firstFresh = 0;
  for (int i = 0; i < gridSize; i++) {
    for (int j = 0; j < colSize; j++) {
      if (grid[i][j] == 1) {
        firstFresh++;
      }
    }
  }
  if (firstFresh == 0) {
    return 0;
  }
  int **gridA, **gridB, **cur, **next, **temp;
  gridA = (int **)malloc(sizeof(int *) * gridSize);
  gridB = (int **)malloc(sizeof(int *) * gridSize);
  for (int i = 0; i < gridSize; i++) {
    int *rowA = (int *)malloc(sizeof(int) * colSize);
    int *rowB = (int *)malloc(sizeof(int) * colSize);
    for (int j = 0; j < colSize; j++) {
      rowA[j] = rowB[j] = grid[i][j];
    }
    gridA[i] = rowA;
    gridB[i] = rowB;
  }
  cur = gridA, next = gridB;
  int prevFresh = firstFresh, fresh = 0;
  int minute = 0;
  while (prevFresh > 0) {
    fresh = 0;
    minute++;
    for (int i = 0; i < gridSize; i++) {
      for (int j = 0; j < colSize; j++) {
        if (cur[i][j] == 1) {
          if ((i - 1 >= 0 && cur[i - 1][j] == 2) || (i + 1 < gridSize && cur[i + 1][j] == 2) || (j - 1 >= 0 && cur[i][j - 1] == 2) || (j + 1 < colSize && cur[i][j + 1] == 2)) {
            next[i][j] = 2;
          } else {
            next[i][j] = cur[i][j];
            fresh++;
          }
        } else {
          next[i][j] = cur[i][j];
        }
      }
    }
    if (fresh == prevFresh) {
      freeSpace(gridA, gridB, gridSize);
      return -1;
    } else {
      prevFresh = fresh;
      temp = cur;
      cur = next;
      next = temp;
    }
  }
  freeSpace(gridA, gridB, gridSize);
  return minute;
}
```