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

```asm
<parsestr>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %edi,-0x14(%rbp)
  mov    %rsi,-0x20(%rbp)
  mov    %rdx,-0x28(%rbp)
  mov    %rcx,-0x30(%rbp)
  mov    %r8d,-0x18(%rbp)
  mov    %r9,-0x38(%rbp)
  movl   $0x1,-0xc(%rbp)
  jmp    L13
L32:
  mov    -0xc(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  lea    D62(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L157
  mov    -0xc(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  lea    D66(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L3
L157:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D71(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  cmpl   $0x0,-0x18(%rbp)
  je     L14
  mov    -0x38(%rbp),%rax
  mov    %rax,%rsi
  lea    D56(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
L14:
  mov    $0xa,%edi
  call   <putchar@plt>
  jmp    L24
L3:
  addl   $0x1,-0xc(%rbp)
L13:
  mov    -0xc(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jl     L32
  movl   $0x1,-0xc(%rbp)
  jmp    L15
L97:
  mov    -0xc(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cmp    $0x2,%eax
  jle    L57
  mov    -0xc(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x2d,%al
  jne    L203
  mov    -0xc(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x2d,%al
  jne    L203
  mov    -0xc(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  lea    0x2(%rax),%rdx
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  mov    %rdx,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L203
  mov    -0x14(%rbp),%eax
  sub    $0x1,%eax
  cmp    %eax,-0xc(%rbp)
  jne    L143
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D138(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L143:
  mov    -0xc(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,-0x8(%rbp)
  cmpl   $0x1388,-0x8(%rbp)
  jle    L134
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D84(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L134:
  mov    -0x8(%rbp),%eax
  add    $0x1,%eax
  mov    $0x1,%esi
  mov    %eax,%edi
  call   <calloc@plt>
  mov    -0x30(%rbp),%rdx
  mov    %rax,(%rdx)
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L54
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D136(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L54:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0xc(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,8),%rcx
  mov    -0x20(%rbp),%rax
  add    %rcx,%rax
  mov    (%rax),%rax
  lea    D103(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <sscanf@plt>
  mov    %eax,-0x4(%rbp)
  cmpl   $0x1,-0x4(%rbp)
  je     L124
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D39(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L124
L57:
  nop
  jmp    L202
L203:
  nop
L202:
  addl   $0x1,-0xc(%rbp)
L15:
  mov    -0xc(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jl     L97
  jmp    L229
L124:
  nop
L229:
  mov    -0xc(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jne    L24
  cmpl   $0x0,-0x18(%rbp)
  je     L79
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,-0x8(%rbp)
  cmpl   $0x1388,-0x8(%rbp)
  jle    L6
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D84(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L6:
  mov    -0x8(%rbp),%eax
  add    $0x1,%eax
  mov    $0x1,%esi
  mov    %eax,%edi
  call   <calloc@plt>
  mov    -0x30(%rbp),%rdx
  mov    %rax,(%rdx)
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L9
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D136(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L9:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0x38(%rbp),%rax
  lea    D103(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <sscanf@plt>
  mov    %eax,-0x4(%rbp)
  cmpl   $0x1,-0x4(%rbp)
  je     L24
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D39(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L24
L79:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  lea    D55(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L24:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: data_tag: D62
datatype: string
name: retrieve_data
arguments: data_tag: D66
datatype: string
name: retrieve_data
arguments: data_tag: D71
datatype: string
name: retrieve_data
arguments: data_tag: D56
datatype: string
name: retrieve_data
arguments: data_tag: D138
datatype: string
name: retrieve_data
arguments: data_tag: D84
datatype: string
name: retrieve_data
arguments: data_tag: D136
datatype: string
name: retrieve_data
arguments: data_tag: D103
datatype: string
name: retrieve_data
arguments: data_tag: D39
datatype: string
name: retrieve_data
arguments: data_tag: D55
datatype: string

tool: D62: --help

tool: D66: -h

tool: D71: --%s <str>

tool: D56:  (DEFAULT:%s)

tool: D138: option %s value missing


tool: D84: option %s value too long


tool: D136: option %s memory error


tool: D103: %s

tool: D39: option %s failed to parse value


tool: D55: option %s is required


assistant: ```c
void parsestr(int argc, char *argv[], const char *name, char **p, unsigned hasdef, const char *defval) {
  int i, res, slen;
  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
      printf("--%s <str>", name);
      if (hasdef)
        printf(" (DEFAULT:%s)", defval);
      printf("\n");
      return;
    }
  }
  for (i = 1; i < argc; i++) {
    if (strlen(argv[i]) < 3)
      continue;
    if (argv[i][0] != '-' || argv[i][1] != '-' || strcmp(argv[i] + 2, name) != 0)
      continue;
    if (i == argc - 1) {
      printf("option %s value missing\n", name);
      exit(1);
    }
    slen = strlen(argv[i + 1]);
    if (slen > 5000) {
      printf("option %s value too long\n", name);
      exit(1);
    }
    *p = calloc(slen + 1, sizeof(char));
    if (*p == NULL) {
      printf("option %s memory error\n", name);
      exit(1);
    }
    res = sscanf(argv[i + 1], "%s", *p);
    if (res != 1) {
      printf("option %s failed to parse value\n", name);
      exit(1);
    }
    break;
  }
  if (i == argc) {
    if (hasdef) {
      slen = strlen(defval);
      if (slen > 5000) {
        printf("option %s value too long\n", name);
        exit(1);
      }
      *p = calloc(slen + 1, sizeof(char));
      if (*p == NULL) {
        printf("option %s memory error\n", name);
        exit(1);
      }
      res = sscanf(defval, "%s", *p);
      if (res != 1) {
        printf("option %s failed to parse value\n", name);
        exit(1);
      }
    } else {
      printf("option %s is required\n", name);
      exit(1);
    }
  }
}
```