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

```asm
<cmd_add>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdx,0x8(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  movl   $0xffffffff,0x24(%rsp)
  movl   $0xffffffff,0x28(%rsp)
  movl   $0xffffffff,0x2c(%rsp)
  movl   $0xffffffff,0x30(%rsp)
  movl   $0xffffffff,0x34(%rsp)
  test   %edi,%edi
  js     L96
  lea    0x2c(%rsp),%r14
  lea    0x28(%rsp),%r15
  mov    %rsi,%r12
  lea    0x24(%rsp),%rbx
  sub    $0x8,%rsp
  mov    %r14,%r8
  mov    %r15,%rcx
  lea    0x3c(%rsp),%rax
  mov    %rbx,%rdx
  push   %rax
  lea    0x40(%rsp),%r9
  call   <check_option_add@plt>
  pop    %rsi
  pop    %rdi
  mov    0x30(%rsp),%r8d
  mov    %eax,%ebp
  test   %r8d,%r8d
  jns    L55
  mov    0x2c(%rsp),%eax
  mov    0x34(%rsp),%edx
  not    %eax
  not    %edx
  shr    $0x1f,%eax
  shr    $0x1f,%edx
  add    %edx,%eax
  cmp    %ebp,%eax
  jl     L18
  xor    %r13d,%r13d
L52:
  mov    %rbx,%r8
  mov    %r15,%rcx
  mov    %r14,%rdx
  mov    %r12,%rsi
  mov    %ebp,%edi
  call   <check_args@plt>
  test   %rax,%rax
  jne    L67
  push   0x8(%rsp)
  mov    %r12,%rsi
  mov    %ebp,%edi
  push   %r13
  mov    0x44(%rsp),%r9d
  mov    0x34(%rsp),%r8d
  mov    0x3c(%rsp),%ecx
  mov    0x38(%rsp),%edx
  call   <action_add@plt>
  pop    %rdx
  pop    %rcx
  mov    %eax,%r12d
  cmp    $0xffffffff,%eax
  je     L12
  mov    0x30(%rsp),%eax
  xor    %r12d,%r12d
  test   %eax,%eax
  js     L125
  mov    %r13,%rdi
  call   <free@plt>
L125:
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L91
  add    $0x48,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L55:
  mov    %eax,%edi
  call   <malloc@plt>
  lea    -0x1(%rbp),%r8d
  mov    %rax,%r13
  movslq 0x30(%rsp),%rax
  mov    %rax,%rcx
  shl    $0x3,%rax
  lea    (%r12,%rax,1),%rdi
  mov    (%rdi),%r9
  cmp    %r8d,%ecx
  jl     L89
  mov    0x2c(%rsp),%r11d
L105:
  mov    %r8d,%edi
  mov    %r11d,%ecx
  mov    %r9,%rdx
  mov    %r13,%rsi
  mov    %r8d,0x10(%rsp)
  call   <check_type_args@plt>
  mov    0x10(%rsp),%r8d
  test   %rax,%rax
  js     L87
  mov    %r8d,%ebp
  jmp    L52
  nopw   0x0(%rax,%rax,1)
L89:
  lea    0x1(%rcx),%edx
  cmp    %edx,%ebp
  jle    L76
  sub    %ecx,%ebp
  lea    0x8(%r12,%rax,1),%rsi
  mov    %r9,0x18(%rsp)
  lea    -0x2(%rbp),%edx
  mov    %r8d,0x14(%rsp)
  lea    0x8(,%rdx,8),%rdx
  mov    %ecx,0x10(%rsp)
  call   <memmove@plt>
  mov    0x10(%rsp),%ecx
  mov    0x14(%rsp),%r8d
  mov    0x18(%rsp),%r9
L76:
  mov    0x24(%rsp),%eax
  xor    %edx,%edx
  mov    0x2c(%rsp),%r11d
  cmp    %eax,%ecx
  setl   %dl
  sub    %edx,%eax
  xor    %edx,%edx
  mov    %eax,0x24(%rsp)
  mov    0x28(%rsp),%eax
  cmp    %eax,%ecx
  setl   %dl
  sub    %edx,%eax
  xor    %edx,%edx
  mov    %eax,0x28(%rsp)
  mov    0x34(%rsp),%eax
  cmp    %eax,%ecx
  setl   %dl
  sub    %edx,%eax
  mov    %eax,0x34(%rsp)
  xor    %eax,%eax
  cmp    %r11d,%ecx
  setl   %al
  sub    %eax,%r11d
  mov    %r11d,0x2c(%rsp)
  jmp    L105
L67:
  lea    D3(%rip),%rdi
  mov    $0xffffffff,%r12d
  call   <printf@plt>
  jmp    L125
L96:
  lea    D48(%rip),%rdi
  mov    $0xffffffff,%r12d
  call   <printf@plt>
  jmp    L125
L18:
  lea    D37(%rip),%rdi
  mov    $0xffffffff,%r12d
  call   <printf@plt>
  jmp    L125
L12:
  lea    D32(%rip),%rdi
  call   <printf@plt>
  jmp    L125
L87:
  lea    D4(%rip),%rdi
  mov    $0xffffffff,%r12d
  call   <printf@plt>
  mov    %r13,%rdi
  call   <free@plt>
  jmp    L125
L91:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: data_tag: D3
type_guessed: string
name: retrieve_data
arguments: data_tag: D48
type_guessed: string
name: retrieve_data
arguments: data_tag: D37
type_guessed: string
name: retrieve_data
arguments: data_tag: D32
type_guessed: string
name: retrieve_data
arguments: data_tag: D4
type_guessed: string

tool: D3: check path args failed


tool: D48: error no args for add


tool: D37: check_type_args failed


tool: D32: error action add


tool: D4: check_args_no_op failed


assistant: ```c
int cmd_add(int argc, char **argv, char *daz) {
  int f_date = -1, f_compound = -1, f_dz = -1, f_type = -1, f_input = -1;
  char *type_args = NULL;
  if (argc < 0) {
    printf("error no args for add\n");
    return -1;
  }
  argc = check_option_add(argc, argv, &f_date, &f_compound, &f_dz, &f_type, &f_input);
  if (f_type >= 0) {
    type_args = (char *)malloc(sizeof(*type_args) * argc);
    char *tmp = argv[f_type];
    if (f_type < (argc - 1)) {
      int i;
      for (i = (f_type + 1); i < (argc); i++) {
        argv[i - 1] = argv[i];
      }
      f_date = (f_date > f_type ? f_date - 1 : f_date);
      f_compound = (f_compound > f_type ? f_compound - 1 : f_compound);
      f_input = (f_input > f_type ? f_input - 1 : f_input);
      f_dz = (f_dz > f_type ? f_dz - 1 : f_dz);
    }
    argc--;
    if (check_type_args(argc, type_args, tmp, f_dz) < 0) {
      printf("check_args_no_op failed\n");
      free(type_args);
      return -1;
    }
  } else if (argc > (f_dz >= 0 ? 1 : 0) + (f_input >= 0 ? 1 : 0)) {
    printf("check_type_args failed\n");
    return -1;
  }
  if (check_args(argc, argv, &f_dz, &f_compound, &f_date)) {
    printf("check path args failed\n");
    return -1;
  }
  if (action_add(argc, argv, f_compound, f_dz, f_date, f_input, type_args, daz) == -1) {
    printf("error action add\n");
    return -1;
  }
  if (f_type >= 0) {
    free(type_args);
  }
  return 0;
}
```