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

```asm
<read_mosaic_grid_data>:
  endbr64
  push   %r15
  mov    %rsi,%r15
  push   %r14
  push   %r13
  mov    %ecx,%r13d
  push   %r12
  mov    %edx,%r12d
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  mov    %r8,%rbx
  sub    $0x338,%rsp
  mov    %r9d,0x1c(%rsp)
  lea    0x220(%rsp),%r8
  lea    0x20(%rsp),%r14
  mov    %r8,%rsi
  mov    %fs:0x28,%rax
  mov    %rax,0x328(%rsp)
  xor    %eax,%eax
  mov    %r8,0x10(%rsp)
  call   <get_file_dir@plt>
  lea    0x120(%rsp),%r9
  mov    %rbp,%rdi
  lea    0x1c(%rsp),%rcx
  mov    %r9,%rdx
  lea    D22(%rip),%rsi
  mov    %r9,0x8(%rsp)
  call   <get_string_data_level@plt>
  mov    0x10(%rsp),%rdx
  mov    0x8(%rsp),%rcx
  mov    %r14,%rdi
  lea    D48(%rip),%rsi
  call   <sprintf@plt>
  lea    D40(%rip),%rsi
  mov    %r14,%rdi
  call   <get_dimlen@plt>
  lea    D42(%rip),%rsi
  mov    %r14,%rdi
  mov    %eax,%ebp
  call   <get_dimlen@plt>
  mov    %eax,%edx
  lea    (%r12,%r12,1),%eax
  cmp    %ebp,%eax
  jne    L20
  lea    0x0(%r13,%r13,1),%eax
  cmp    %edx,%eax
  je     L12
L20:
  lea    D19(%rip),%rdi
  mov    %edx,0x8(%rsp)
  call   <error_handler@plt>
  mov    0x8(%rsp),%edx
L12:
  lea    0x1(%rbp),%ecx
  add    $0x1,%edx
  imul   %ecx,%edx
  mov    %ecx,0x8(%rsp)
  lea    0x0(,%rdx,8),%edi
  call   <malloc@plt>
  mov    %r15,%rsi
  mov    %r14,%rdi
  mov    %rax,%rdx
  mov    %rax,%rbp
  call   <get_var_data@plt>
  lea    0x1(%r13),%r8d
  lea    0x1(%r12),%r9d
  sub    0x378(%rsp),%r8d
  sub    0x370(%rsp),%r9d
  test   %r8d,%r8d
  jle    L22
  mov    0x8(%rsp),%ecx
  mov    0x378(%rsp),%esi
  xor    %r10d,%r10d
  xor    %edi,%edi
  movslq 0x370(%rsp),%r11
  lea    -0x1(%r9),%r14d
  lea    0x8(%rbx),%r13
  imul   %ecx,%esi
  lea    (%rcx,%rcx,1),%r12d
  nopl   0x0(%rax)
L14:
  test   %r9d,%r9d
  jle    L37
  movslq %esi,%rax
  movslq %r10d,%rcx
  add    %r11,%rax
  lea    0x0(%rbp,%rax,8),%rdx
  lea    (%rbx,%rcx,8),%rax
  add    %r14,%rcx
  lea    0x0(%r13,%rcx,8),%rcx
  nop
L42:
  movsd  (%rdx),%xmm0
  add    $0x8,%rax
  add    $0x10,%rdx
  movsd  %xmm0,-0x8(%rax)
  cmp    %rcx,%rax
  jne    L42
L37:
  add    $0x1,%edi
  add    %r12d,%esi
  add    %r9d,%r10d
  cmp    %edi,%r8d
  jne    L14
L22:
  mov    %rbp,%rdi
  call   <free@plt>
  mov    0x328(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L32
  add    $0x338,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L32:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: tag: D22
data_type: string
name: parse_data
arguments: tag: D48
data_type: string
name: parse_data
arguments: tag: D40
data_type: string
name: parse_data
arguments: tag: D42
data_type: string
name: parse_data
arguments: tag: D19
data_type: string

tool: D22: gridfiles

tool: D48: %s/%s

tool: D40: nx

tool: D42: ny

tool: D19: supergrid size should be double of the model grid size

assistant: ```c
void read_mosaic_grid_data(const char *mosaic_file, const char *name, int nx, int ny, double *data, int level, int ioff, int joff) {
  char tilefile[255], gridfile[255], dir[255];
  double *tmp;
  int ni, nj, nxp, nyp, i, j;
  get_file_dir(mosaic_file, dir);
  get_string_data_level(mosaic_file, "gridfiles", gridfile, &level);
  sprintf(tilefile, "%s/%s", dir, gridfile);
  ni = get_dimlen(tilefile, "nx");
  nj = get_dimlen(tilefile, "ny");
  if (ni != nx * 2 || nj != ny * 2)
    error_handler("supergrid size should be double of the model grid size");
  tmp = (double *)malloc((ni + 1) * (nj + 1) * sizeof(double));
  get_var_data(tilefile, name, tmp);
  nxp = nx + 1 - ioff;
  nyp = ny + 1 - joff;
  for (j = 0; j < nyp; j++)
    for (i = 0; i < nxp; i++)
      data[j * nxp + i] = tmp[(2 * j + joff) * (ni + 1) + 2 * i + ioff];
  free(tmp);
}
```