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

```asm
<read_mosaic_grid_data>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x328,%rsp
  mov    %rdi,%r13
  mov    %rsi,(%rsp)
  mov    %edx,%ebx
  mov    %ecx,%ebp
  mov    %r8,%r12
  mov    %r9d,0xc(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x318(%rsp)
  xor    %eax,%eax
  lea    0x210(%rsp),%r14
  mov    %r14,%rsi
  call   <get_file_dir@plt>
  lea    0xc(%rsp),%rcx
  lea    0x110(%rsp),%r15
  mov    %r15,%rdx
  lea    D28(%rip),%rsi
  mov    %r13,%rdi
  call   <get_string_data_level@plt>
  lea    0x10(%rsp),%r13
  mov    %r15,%rcx
  mov    %r14,%rdx
  lea    D37(%rip),%rsi
  mov    %r13,%rdi
  call   <sprintf@plt>
  lea    D38(%rip),%rsi
  mov    %r13,%rdi
  call   <get_dimlen@plt>
  mov    %eax,%r14d
  lea    D30(%rip),%rsi
  mov    %r13,%rdi
  call   <get_dimlen@plt>
  mov    %eax,%r13d
  lea    (%rbx,%rbx,1),%eax
  cmp    %r14d,%eax
  jne    L5
  lea    0x0(%rbp,%rbp,1),%eax
  cmp    %r13d,%eax
  je     L14
L5:
  lea    D4(%rip),%rdi
  call   <error_handler@plt>
L14:
  add    $0x1,%r14d
  add    $0x1,%r13d
  imul   %r14d,%r13d
  lea    0x0(,%r13,8),%edi
  call   <malloc@plt>
  mov    %rax,%r13
  lea    0x10(%rsp),%rdi
  mov    %rax,%rdx
  mov    (%rsp),%rsi
  call   <get_double_data@plt>
  add    $0x1,%ebx
  sub    0x360(%rsp),%ebx
  add    $0x1,%ebp
  sub    0x368(%rsp),%ebp
  test   %ebp,%ebp
  jle    L36
  lea    (%r14,%r14,1),%r10d
  mov    %r14d,%esi
  imul   0x368(%rsp),%esi
  mov    $0x0,%r8d
  mov    $0x0,%edi
  movslq 0x360(%rsp),%r9
  lea    -0x1(%rbx),%r14d
  lea    0x8(%r12),%r11
  jmp    L50
L74:
  movslq %esi,%rax
  add    %r9,%rax
  lea    0x0(%r13,%rax,8),%rdx
  movslq %r8d,%rcx
  lea    (%r12,%rcx,8),%rax
  add    %r14,%rcx
  lea    (%r11,%rcx,8),%rcx
L37:
  movsd  (%rdx),%xmm0
  movsd  %xmm0,(%rax)
  add    $0x10,%rdx
  add    $0x8,%rax
  cmp    %rcx,%rax
  jne    L37
L0:
  add    $0x1,%edi
  add    %r10d,%esi
  add    %ebx,%r8d
  cmp    %edi,%ebp
  je     L36
L50:
  test   %ebx,%ebx
  jg     L74
  jmp    L0
L36:
  mov    %r13,%rdi
  call   <free@plt>
  mov    0x318(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L30
  add    $0x328,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L30:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: data_label: D28
data_type: string
name: retrieve_data
arguments: data_label: D37
data_type: string
name: retrieve_data
arguments: data_label: D38
data_type: string
name: retrieve_data
arguments: data_label: D30
data_type: string
name: retrieve_data
arguments: data_label: D4
data_type: string

tool: D28: gridfiles

tool: D37: %s/%s

tool: D38: nx

tool: D30: ny

tool: D4: 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_double_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);
}
```