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

```asm
<parsestr>:
  endbr64
  push   %r15
  push   %r14
  mov    %edi,%r14d
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdx,(%rsp)
  mov    %rcx,0x18(%rsp)
  mov    %r8d,0xc(%rsp)
  mov    %r9,0x10(%rsp)
  cmp    $0x1,%edi
  jle    L31
  lea    -0x2(%rdi),%eax
  mov    %rsi,%r13
  lea    0x8(%rsi),%r15
  lea    0x10(%rsi,%rax,8),%r12
  lea    D48(%rip),%rbx
  lea    D83(%rip),%rbp
  jmp    L233
L150:
  mov    (%r15),%rdi
  mov    %rbp,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L127
  add    $0x8,%r15
  cmp    %r12,%r15
  je     L195
L233:
  mov    (%r15),%rdi
  mov    %rbx,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L150
L127:
  mov    (%rsp),%rsi
  lea    D13(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    0xc(%rsp),%edx
  test   %edx,%edx
  jne    L92
L50:
  add    $0x28,%rsp
  mov    $0xa,%edi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10b0 <putchar@plt>
  nopl   0x0(%rax,%rax,1)
L92:
  mov    0x10(%rsp),%rsi
  lea    D66(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  jmp    L50
  nopl   (%rax)
L195:
  mov    %r14d,%ebp
  mov    $0x1,%r12d
  jmp    L214
  nopl   0x0(%rax,%rax,1)
L276:
  add    $0x1,%r12
  add    $0x1,%ebx
  cmp    %r12,%rbp
  je     L91
L214:
  mov    0x0(%r13,%r12,8),%rdi
  mov    %r12d,%ebx
  call   <strlen@plt>
  cmp    $0x2,%eax
  jle    L276
  mov    0x0(%r13,%r12,8),%rdi
  cmpb   $0x2d,(%rdi)
  jne    L276
  cmpb   $0x2d,0x1(%rdi)
  jne    L276
  mov    (%rsp),%rsi
  add    $0x2,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L276
  sub    $0x1,%r14d
  cmp    %r12d,%r14d
  je     L25
L152:
  lea    0x8(%r13,%r12,8),%rbp
  mov    0x0(%rbp),%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  cmp    $0x1388,%eax
  jg     L78
L36:
  lea    0x1(%rbx),%edi
  mov    $0x1,%esi
  call   <calloc@plt>
  mov    %rax,%rdx
  mov    0x18(%rsp),%rax
  mov    %rdx,(%rax)
  test   %rdx,%rdx
  je     L100
L77:
  mov    0x0(%rbp),%rdi
  lea    D62(%rip),%rsi
  call   <sscanf@plt>
  cmp    $0x1,%eax
  je     L194
L64:
  mov    (%rsp),%rsi
  lea    D50(%rip),%rdi
L239:
  xor    %eax,%eax
  call   <printf@plt>
  add    $0x28,%rsp
  mov    $0x1,%edi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1110 <exit@plt>
L31:
  mov    $0x1,%ebx
L91:
  cmp    %ebx,%r14d
  jne    L194
  mov    0xc(%rsp),%eax
  test   %eax,%eax
  je     L203
  mov    0x10(%rsp),%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  cmp    $0x1388,%eax
  jg     L15
L27:
  lea    0x1(%rbx),%edi
  mov    $0x1,%esi
  call   <calloc@plt>
  mov    %rax,%rdx
  mov    0x18(%rsp),%rax
  mov    %rdx,(%rax)
  test   %rdx,%rdx
  je     L4
L126:
  mov    0x10(%rsp),%rdi
  lea    D62(%rip),%rsi
  call   <sscanf@plt>
  cmp    $0x1,%eax
  jne    L64
L194:
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L78:
  mov    (%rsp),%rsi
  lea    D120(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L36
L203:
  mov    (%rsp),%rsi
  lea    D12(%rip),%rdi
  jmp    L239
L15:
  mov    (%rsp),%rsi
  lea    D120(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L27
L4:
  mov    (%rsp),%rsi
  lea    D86(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  mov    0x18(%rsp),%rax
  mov    (%rax),%rdx
  jmp    L126
L25:
  mov    (%rsp),%rsi
  lea    D3(%rip),%rdi
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L152
L100:
  mov    (%rsp),%rsi
  lea    D86(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  mov    0x18(%rsp),%rax
  mov    (%rax),%rdx
  jmp    L77
```

tool_calls: name: read_data
arguments: label: D48
type_infered: string
name: read_data
arguments: label: D83
type_infered: string
name: read_data
arguments: label: D13
type_infered: string
name: read_data
arguments: label: D66
type_infered: string
name: read_data
arguments: label: D62
type_infered: string
name: read_data
arguments: label: D50
type_infered: string
name: read_data
arguments: label: D120
type_infered: string
name: read_data
arguments: label: D12
type_infered: string
name: read_data
arguments: label: D86
type_infered: string
name: read_data
arguments: label: D3
type_infered: string

tool: D48: --help

tool: D83: -h

tool: D13: --%s <str>

tool: D66:  (DEFAULT:%s)

tool: D62: %s

tool: D50: option %s failed to parse value


tool: D120: option %s value too long


tool: D12: option %s is required


tool: D86: option %s memory error


tool: D3: option %s value missing


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