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    D15(%rip),%rsi
  mov    %r13,%rdi
  call   <get_string_data_level@plt>
  lea    0x10(%rsp),%r13
  mov    %r15,%rcx
  mov    %r14,%rdx
  lea    D20(%rip),%rsi
  mov    %r13,%rdi
  call   <sprintf@plt>
  lea    D8(%rip),%rsi
  mov    %r13,%rdi
  call   <get_dimlen@plt>
  mov    %eax,%r14d
  lea    D45(%rip),%rsi
  mov    %r13,%rdi
  call   <get_dimlen@plt>
  mov    %eax,%r13d
  lea    (%rbx,%rbx,1),%eax
  cmp    %r14d,%eax
  jne    L18
  lea    0x0(%rbp,%rbp,1),%eax
  cmp    %r13d,%eax
  je     L36
L18:
  lea    D40(%rip),%rdi
  call   <error_handler@plt>
L36:
  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_var_data@plt>
  add    $0x1,%ebx
  sub    0x360(%rsp),%ebx
  add    $0x1,%ebp
  sub    0x368(%rsp),%ebp
  test   %ebp,%ebp
  jle    L82
  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    L48
L5:
  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
L9:
  movsd  (%rdx),%xmm0
  movsd  %xmm0,(%rax)
  add    $0x10,%rdx
  add    $0x8,%rax
  cmp    %rcx,%rax
  jne    L9
L23:
  add    $0x1,%edi
  add    %r10d,%esi
  add    %ebx,%r8d
  cmp    %edi,%ebp
  je     L82
L48:
  test   %ebx,%ebx
  jg     L5
  jmp    L23
L82:
  mov    %r13,%rdi
  call   <free@plt>
  mov    0x318(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L66
  add    $0x328,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L66:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D15
type_infered: string
name: unpack_data
arguments: tag: D20
type_infered: string
name: unpack_data
arguments: tag: D8
type_infered: string
name: unpack_data
arguments: tag: D45
type_infered: string
name: unpack_data
arguments: tag: D40
type_infered: string

tool: D15: gridfiles

tool: D20: %s/%s

tool: D8: nx

tool: D45: ny

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