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

```asm
<f_set_date>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    0x80(%rsp),%rbx
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  test   %edi,%edi
  js     L296
  mov    %rsi,%r12
  lea    0x18(%rsp),%rcx
  lea    0x14(%rsp),%rdx
  lea    0x10(%rsp),%rsi
  sub    $0x8,%rsp
  lea    0x2c(%rsp),%rax
  push   %rax
  lea    0x30(%rsp),%r9
  lea    0x2c(%rsp),%r8
  mov    %r12,%rdi
  call   <reftime@plt>
  movzbl (%rbx),%eax
  sub    $0x2b,%eax
  add    $0x10,%rsp
  test   $0xfd,%al
  jne    L195
  lea    0x2e(%rsp),%rcx
  lea    0x28(%rsp),%rdx
  lea    0x1(%rbx),%rdi
  lea    D27(%rip),%rsi
  mov    $0x0,%eax
  call   <sscanf@plt>
  cmp    $0x2,%eax
  jne    L138
  cmpl   $0x0,0x28(%rsp)
  jns    L207
L138:
  lea    D48(%rip),%rsi
  lea    D33(%rip),%rdi
  call   <fatal_error@plt>
L207:
  lea    0x2e(%rsp),%rdi
  lea    D30(%rip),%rsi
  call   <strcmp@plt>
  mov    %rax,%rdx
  mov    $0x1,%eax
  test   %rdx,%rdx
  jne    L281
L275:
  cmpb   $0x2b,(%rbx)
  je     L157
  lea    0x1c(%rsp),%rcx
  lea    0x18(%rsp),%rdx
  lea    0x14(%rsp),%rsi
  lea    0x10(%rsp),%rdi
  push   %rax
  mov    0x30(%rsp),%eax
  push   %rax
  lea    0x34(%rsp),%r9
  lea    0x30(%rsp),%r8
  call   <sub_dt@plt>
  add    $0x10,%rsp
  jmp    L84
L281:
  lea    0x2e(%rsp),%rdi
  lea    D132(%rip),%rsi
  call   <strcmp@plt>
  mov    %rax,%rdx
  mov    $0x2,%eax
  test   %rdx,%rdx
  je     L275
  lea    0x2e(%rsp),%rdi
  lea    D5(%rip),%rsi
  call   <strcmp@plt>
  mov    %rax,%rdx
  mov    $0x3,%eax
  test   %rdx,%rdx
  je     L275
  lea    0x2e(%rsp),%rdi
  lea    D8(%rip),%rsi
  call   <strcmp@plt>
  mov    %rax,%rdx
  mov    $0x4,%eax
  test   %rdx,%rdx
  je     L275
  lea    0x2e(%rsp),%rdi
  lea    D50(%rip),%rsi
  call   <strcmp@plt>
  mov    %rax,%rdx
  mov    $0x0,%eax
  test   %rdx,%rdx
  je     L275
  lea    0x2e(%rsp),%rsi
  lea    D46(%rip),%rdi
  call   <fatal_error@plt>
  mov    $0xffffffff,%eax
  jmp    L275
L157:
  lea    0x1c(%rsp),%rcx
  lea    0x18(%rsp),%rdx
  lea    0x14(%rsp),%rsi
  lea    0x10(%rsp),%rdi
  push   %rax
  mov    0x30(%rsp),%eax
  push   %rax
  lea    0x34(%rsp),%r9
  lea    0x30(%rsp),%r8
  call   <add_dt@plt>
  add    $0x10,%rsp
  jmp    L84
L195:
  mov    %rbx,%rdi
  call   <strlen@plt>
  lea    -0x4(%rax),%edx
  cmp    $0xa,%edx
  ja     L69
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  and    $0x1,%eax
  sub    %edx,%eax
  cmp    $0x1,%eax
  jne    L28
L69:
  mov    %rbx,%rsi
  lea    D67(%rip),%rdi
  call   <fatal_error@plt>
L28:
  lea    0x14(%rsp),%rcx
  lea    0x10(%rsp),%rdx
  lea    0x24(%rsp),%rax
  push   %rax
  lea    0x28(%rsp),%rax
  push   %rax
  lea    0x2c(%rsp),%r9
  lea    0x28(%rsp),%r8
  lea    D106(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sscanf@plt>
  add    $0x10,%rsp
  test   %eax,%eax
  jle    L131
L110:
  mov    0x18(%rsp),%edx
  mov    0x14(%rsp),%esi
  mov    0x10(%rsp),%edi
  call   <check_datecode@plt>
  test   %rax,%rax
  jne    L214
  cmpl   $0x17,0x1c(%rsp)
  jbe    L186
L214:
  mov    %rbx,%rsi
  lea    D67(%rip),%rdi
  call   <fatal_error@plt>
L84:
  sub    $0x8,%rsp
  mov    0x8(%r12),%rax
  add    $0xc,%rax
  push   %rax
  mov    0x34(%rsp),%r9d
  mov    0x30(%rsp),%r8d
  mov    0x2c(%rsp),%ecx
  mov    0x28(%rsp),%edx
  mov    0x24(%rsp),%esi
  mov    0x20(%rsp),%edi
  call   <save_time@plt>
  mov    %r12,%rdi
  call   <stat_proc_n_time_ranges_index@plt>
  add    $0x10,%rsp
  test   %eax,%eax
  js     L296
  movslq %eax,%r13
  mov    0x20(%r12),%rdx
  movzbl (%rdx,%r13,1),%ebp
  sub    $0x7,%eax
  mov    %eax,0xc(%rsp)
  mov    %r12,%rdi
  call   <code_table_4_4@plt>
  mov    %eax,%ebx
  mov    %r12,%rdi
  call   <forecast_time_in_units@plt>
  mov    %eax,0x28(%rsp)
  lea    0x1c(%rsp),%rcx
  lea    0x18(%rsp),%rdx
  lea    0x14(%rsp),%rsi
  lea    0x10(%rsp),%rdi
  push   %rbx
  push   %rax
  lea    0x34(%rsp),%r9
  lea    0x30(%rsp),%r8
  call   <add_time@plt>
  add    $0x10,%rsp
  test   %bpl,%bpl
  je     L232
  lea    0x6(%r13),%rbx
  movzbl %bpl,%ebp
  lea    -0x1(%rbp),%eax
  lea    (%rax,%rax,2),%rax
  lea    0x12(%r13,%rax,4),%r14
  lea    D109(%rip),%r15
  jmp    L270
L131:
  mov    %rbx,%rsi
  lea    D67(%rip),%rdi
  call   <fatal_error@plt>
  jmp    L110
L186:
  cmpl   $0x3b,0x20(%rsp)
  ja     L214
  cmpl   $0x3b,0x24(%rsp)
  ja     L214
  jmp    L84
L136:
  lea    0x1c(%rsp),%rcx
  lea    0x18(%rsp),%rdx
  lea    0x14(%rsp),%rsi
  lea    0x10(%rsp),%rdi
  movzbl %r13b,%r13d
  push   %r13
  push   %rax
  lea    0x34(%rsp),%r9
  lea    0x30(%rsp),%r8
  call   <add_time@plt>
  add    $0x10,%rsp
L228:
  add    $0xc,%rbx
  cmp    %r14,%rbx
  je     L232
L270:
  mov    0x20(%r12),%rax
  movzbl (%rax,%rbx,1),%ebp
  movzbl 0x1(%rax,%rbx,1),%r13d
  lea    0x2(%rax,%rbx,1),%rdi
  call   <int4@plt>
  mov    %eax,0x28(%rsp)
  movzbl %bpl,%edx
  lea    -0x3(%rdx),%ecx
  cmp    $0x1,%ecx
  jbe    L228
  sub    $0x1,%edx
  cmp    $0x1,%edx
  jbe    L136
  movzbl %bpl,%esi
  mov    %r15,%rdi
  call   <fatal_error_i@plt>
  jmp    L228
L232:
  sub    $0x8,%rsp
  movslq 0x14(%rsp),%rax
  add    0x20(%r12),%rax
  push   %rax
  mov    0x34(%rsp),%r9d
  mov    0x30(%rsp),%r8d
  mov    0x2c(%rsp),%ecx
  mov    0x28(%rsp),%edx
  mov    0x24(%rsp),%esi
  mov    0x20(%rsp),%edi
  call   <save_time@plt>
  add    $0x10,%rsp
L296:
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L2
  mov    $0x0,%eax
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L2:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: data_label: D27
type_guessed: string
name: unpack_data
arguments: data_label: D48
type_guessed: string
name: unpack_data
arguments: data_label: D33
type_guessed: string
name: unpack_data
arguments: data_label: D30
type_guessed: string
name: unpack_data
arguments: data_label: D132
type_guessed: string
name: unpack_data
arguments: data_label: D5
type_guessed: string
name: unpack_data
arguments: data_label: D8
type_guessed: string
name: unpack_data
arguments: data_label: D50
type_guessed: string
name: unpack_data
arguments: data_label: D46
type_guessed: string
name: unpack_data
arguments: data_label: D67
type_guessed: string
name: unpack_data
arguments: data_label: D106
type_guessed: string
name: unpack_data
arguments: data_label: D109
type_guessed: string

tool: D27: %d%2s

tool: 

tool: D33: set_date: delta-time: (+|-)(int)(hr|dy|mo|yr)

tool: D30: hr

tool: D132: dy

tool: D5: mo

tool: D8: yr

tool: D50: mn

tool: D46: set_date: unsupported time unit %s

tool: D67: set_date: bad date code %s

tool: D106: %4d%2d%2d%2d%2d%2d

tool: D109: set_date: code 4.11=%d is not supported

assistant: ```c
int f_set_date(int mode, unsigned char **sec, float *data, unsigned int ndata, char *inv_out, void **local, const char *arg1) {
  int year, month, day, hour, minute, second, i, j, units, n;
  int code_4_11, idx;
  int dtime, dt_unit;
  char string[10];
  if (mode < 0)
    return 0;
  reftime(sec, &year, &month, &day, &hour, &minute, &second);
  if (arg1[0] == '+' || arg1[0] == '-') {
    i = sscanf(arg1 + 1, "%d%2s", &dtime, string);
    if (i != 2 || dtime < 0)
      fatal_error("set_date: delta-time: (+|-)(int)(hr|dy|mo|yr)", "");
    dt_unit = -1;
    if (strcmp(string, "hr") == 0)
      dt_unit = 1;
    else if (strcmp(string, "dy") == 0)
      dt_unit = 2;
    else if (strcmp(string, "mo") == 0)
      dt_unit = 3;
    else if (strcmp(string, "yr") == 0)
      dt_unit = 4;
    else if (strcmp(string, "mn") == 0)
      dt_unit = 0;
    if (dt_unit == -1)
      fatal_error("set_date: unsupported time unit %s", string);
    if (arg1[0] == '+')
      i = add_dt(&year, &month, &day, &hour, &minute, &second, dtime, dt_unit);
    else
      i = sub_dt(&year, &month, &day, &hour, &minute, &second, dtime, dt_unit);
  } else {
    i = strlen(arg1);
    if (i < 4 || i > 14 || i % 2 == 1)
      fatal_error("set_date: bad date code %s", arg1);
    i = sscanf(arg1, "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &minute, &second);
    if (i < 1)
      fatal_error("set_date: bad date code %s", arg1);
    if (check_datecode(year, month, day) != 0 || hour < 0 || hour >= 24 || minute < 0 || minute >= 60 || second < 0 || second >= 60)
      fatal_error("set_date: bad date code %s", arg1);
  }
  save_time(year, month, day, hour, minute, second, sec[1] + 12);
  idx = stat_proc_n_time_ranges_index(sec);
  if (idx < 0)
    return 0;
  n = (int)sec[4][idx];
  j = idx + 35 - 42;
  units = code_table_4_4(sec);
  dtime = forecast_time_in_units(sec);
  add_time(&year, &month, &day, &hour, &minute, &second, (unsigned int)dtime, units);
  for (i = 0; i < n; i++) {
    code_4_11 = (int)sec[4][47 - 34 + j + i * 12];
    units = (int)sec[4][48 - 34 + j + i * 12];
    dtime = int4(sec[4] + 49 - 34 + j + i * 12);
    if (code_4_11 == 3 || code_4_11 == 4)
      continue;
    if (code_4_11 == 1 || code_4_11 == 2) {
      add_time(&year, &month, &day, &hour, &minute, &second, (unsigned int)dtime, units);
    } else {
      fatal_error_i("set_date: code 4.11=%d is not supported", code_4_11);
    }
  }
  save_time(year, month, day, hour, minute, second, sec[4] + j);
  return 0;
}
```