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

```asm
<read_mosaic_grid_data>:
  endbr64
  push   %r15
  mov    %rsi,%r15
  push   %r14
  mov    %rdi,%r14
  push   %r13
  mov    %ecx,%r13d
  push   %r12
  mov    %r8,%r12
  push   %rbp
  mov    %edx,%ebp
  push   %rbx
  sub    $0x358,%rsp
  mov    %r9d,0x3c(%rsp)
  lea    0x240(%rsp),%rbx
  mov    %rbx,%rsi
  mov    %fs:0x28,%rax
  mov    %rax,0x348(%rsp)
  xor    %eax,%eax
  call   <get_file_dir@plt>
  lea    0x140(%rsp),%r9
  mov    %r14,%rdi
  lea    0x3c(%rsp),%rcx
  mov    %r9,%rdx
  lea    D48(%rip),%rsi
  mov    %r9,(%rsp)
  lea    0x40(%rsp),%r14
  call   <get_string_data_level@plt>
  mov    (%rsp),%rcx
  mov    %rbx,%rdx
  mov    %r14,%rdi
  lea    D47(%rip),%rsi
  call   <sprintf@plt>
  lea    D19(%rip),%rsi
  mov    %r14,%rdi
  call   <get_dimlen@plt>
  lea    D25(%rip),%rsi
  mov    %r14,%rdi
  mov    %eax,%ebx
  call   <get_dimlen@plt>
  mov    %eax,%edx
  lea    0x0(%rbp,%rbp,1),%eax
  cmp    %ebx,%eax
  jne    L19
  lea    0x0(%r13,%r13,1),%eax
  cmp    %edx,%eax
  je     L40
L19:
  lea    D9(%rip),%rdi
  mov    %edx,(%rsp)
  call   <error_handler@plt>
  mov    (%rsp),%edx
L40:
  lea    0x1(%rbx),%r9d
  add    $0x1,%edx
  add    $0x1,%r13d
  add    $0x1,%ebp
  imul   %r9d,%edx
  mov    %r9d,0x10(%rsp)
  lea    0x0(,%rdx,8),%edi
  call   <malloc@plt>
  mov    %r15,%rsi
  mov    %r14,%rdi
  mov    %rax,%rdx
  mov    %rax,%rbx
  call   <get_var_data@plt>
  sub    0x398(%rsp),%r13d
  sub    0x390(%rsp),%ebp
  mov    %r13d,(%rsp)
  test   %r13d,%r13d
  jle    L37
  test   %ebp,%ebp
  jle    L37
  mov    0x10(%rsp),%r9d
  movslq %ebp,%rdx
  lea    -0x1(%rbp),%edi
  mov    %r12,%rcx
  lea    0x0(,%rdx,8),%rax
  mov    %edi,0x1c(%rsp)
  shl    $0x4,%rdx
  xor    %r10d,%r10d
  lea    (%r9,%r9,1),%r14d
  mov    %rax,0x8(%rsp)
  xor    %r11d,%r11d
  movslq %r14d,%rax
  mov    %r14d,0x18(%rsp)
  imul   0x398(%rsp),%r9d
  shl    $0x3,%rax
  mov    0x390(%rsp),%r14d
  mov    %rax,0x10(%rsp)
  movslq 0x390(%rsp),%rax
  movslq %r9d,%rsi
  add    %rsi,%rax
  lea    (%rbx,%rax,8),%rsi
  mov    %edi,%eax
  and    $0xfffffffe,%edi
  shr    %eax
  lea    (%rdi,%rdi,1),%r8d
  mov    %edi,0x2c(%rsp)
  lea    0x1(%rdi),%r15d
  sub    $0x1,%eax
  lea    0x2(%r8),%edi
  mov    %r8d,0x28(%rsp)
  lea    -0x8(%rdx),%r8
  add    $0x1,%rax
  mov    %edi,0x38(%rsp)
  shl    $0x5,%rax
  mov    %rax,0x20(%rsp)
  mov    %ebp,%eax
  shl    $0x3,%rax
  mov    %rax,0x30(%rsp)
  cs nopw 0x0(%rax,%rax,1)
L47:
  lea    (%r8,%rsi,1),%rax
  cmp    %rax,%rcx
  mov    0x8(%rsp),%rax
  setae  %dl
  lea    (%rcx,%rax,1),%r13
  cmp    %rsi,%r13
  setbe  %al
  or     %dl,%al
  je     L72
  mov    0x20(%rsp),%rax
  cmpl   $0x3,0x1c(%rsp)
  mov    %rcx,%rdx
  lea    (%rax,%rsi,1),%rdi
  mov    %rsi,%rax
  jbe    L72
  nopl   0x0(%rax,%rax,1)
L68:
  movupd (%rax),%xmm0
  add    $0x20,%rax
  add    $0x10,%rdx
  movhpd -0x10(%rax),%xmm0
  movups %xmm0,-0x10(%rdx)
  cmp    %rdi,%rax
  jne    L68
  mov    0x28(%rsp),%eax
  add    %r9d,%eax
  add    %r14d,%eax
  cltq
  movsd  (%rbx,%rax,8),%xmm0
  mov    0x2c(%rsp),%eax
  add    %r10d,%eax
  cltq
  movsd  %xmm0,(%r12,%rax,8)
  cmp    %r15d,%ebp
  jle    L98
  mov    0x38(%rsp),%eax
  add    %r9d,%eax
  add    %r14d,%eax
  cltq
  movsd  (%rbx,%rax,8),%xmm0
  lea    (%r10,%r15,1),%eax
  cltq
  movsd  %xmm0,(%r12,%rax,8)
L98:
  add    $0x1,%r11d
  mov    %r13,%rcx
  add    0x10(%rsp),%rsi
  add    %ebp,%r10d
  add    0x18(%rsp),%r9d
  cmp    %r11d,(%rsp)
  jne    L47
L37:
  mov    %rbx,%rdi
  call   <free@plt>
  mov    0x348(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L25
  add    $0x358,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L72:
  mov    0x30(%rsp),%rax
  mov    %rsi,%rdx
  add    %rcx,%rax
  nopl   0x0(%rax,%rax,1)
L54:
  movsd  (%rdx),%xmm0
  add    $0x8,%rcx
  add    $0x10,%rdx
  movsd  %xmm0,-0x8(%rcx)
  cmp    %rax,%rcx
  jne    L54
  jmp    L98
L25:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D48
data_type: string
name: unpack_data
arguments: tag: D47
data_type: string
name: unpack_data
arguments: tag: D19
data_type: string
name: unpack_data
arguments: tag: D25
data_type: string
name: unpack_data
arguments: tag: D9
data_type: string

tool: D48: gridfiles

tool: D47: %s/%s

tool: D19: nx

tool: D25: ny

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