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

```asm
<rs_parse_cmdline>:
  endbr64
  push   %r15
  push   %r14
  xor    %r14d,%r14d
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    (%rcx),%r12d
  cmp    %edi,%r12d
  jge    L121
  movslq %r12d,%rax
  mov    %rsi,%r13
  mov    %rcx,%rbx
  mov    %r9,%r15
  mov    (%rsi,%rax,8),%r14
  cmpb   $0x2d,(%r14)
  jne    L122
  movzbl 0x1(%r14),%eax
  test   %al,%al
  je     L122
  cmp    $0x2d,%al
  je     L39
  movslq (%r8),%rax
  movsbl (%r14,%rax,1),%r14d
  cmp    $0x3a,%r14b
  je     L130
  mov    %edi,%ebp
  mov    %r14d,%esi
  mov    %rdx,%rdi
  mov    %r8,0x8(%rsp)
  call   <strchr@plt>
  test   %rax,%rax
  je     L130
  movslq (%rbx),%rdi
  mov    0x8(%rsp),%r8
  cmpb   $0x3a,0x1(%rax)
  movslq (%r8),%rsi
  mov    %rdi,%rdx
  mov    0x0(%r13,%rdi,8),%rdi
  mov    %rsi,%rcx
  lea    0x1(%rdi,%rsi,1),%rsi
  movzbl (%rsi),%edi
  jne    L66
  test   %dil,%dil
  jne    L145
  add    $0x2,%edx
  mov    %edx,(%rbx)
  movl   $0x1,(%r8)
  movslq (%rbx),%rax
  cmp    %ebp,%eax
  jg     L41
  mov    -0x8(%r13,%rax,8),%rax
  mov    %rax,(%r15)
L121:
  add    $0x18,%rsp
  mov    %r14d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nop
L122:
  add    $0x1,%r12d
  mov    %r14,(%r15)
  mov    $0x23,%r14d
  mov    %r12d,(%rbx)
  movl   $0x1,(%r8)
  jmp    L121
  nopl   0x0(%rax)
L39:
  lea    D48(%rip),%rsi
  mov    %r14,%rdi
  mov    %r8,0x8(%rsp)
  call   <strcasecmp@plt>
  mov    0x8(%rsp),%r8
  test   %eax,%eax
  je     L149
  lea    D22(%rip),%rsi
  mov    %r14,%rdi
  mov    %r8,0x8(%rsp)
  call   <strcasecmp@plt>
  test   %eax,%eax
  jne    L82
  mov    0x8(%rsp),%r8
  add    $0x1,%r12d
  mov    $0x40,%r14d
  mov    %r12d,(%rbx)
  movl   $0x1,(%r8)
  jmp    L121
  nopl   0x0(%rax,%rax,1)
L66:
  add    $0x1,%ecx
  test   %dil,%dil
  jne    L24
  add    $0x1,%edx
  mov    $0x1,%ecx
  mov    %edx,(%rbx)
L24:
  mov    %ecx,(%r8)
  movq   $0x0,(%r15)
  jmp    L121
  nopl   0x0(%rax)
L130:
  mov    %r14d,%ecx
  lea    D21(%rip),%rdx
L178:
  xor    %esi,%esi
  xor    %edi,%edi
  xor    %eax,%eax
  mov    $0x3f,%r14d
  call   <rs_error@plt>
  jmp    L121
  nopl   0x0(%rax,%rax,1)
L41:
  mov    %r14d,%ecx
  lea    D36(%rip),%rdx
  jmp    L178
  nopl   0x0(%rax)
L145:
  add    $0x1,%edx
  mov    %rsi,(%r15)
  mov    %edx,(%rbx)
  movl   $0x1,(%r8)
  jmp    L121
  nopl   0x0(%rax)
L82:
  mov    %r14,%rcx
  lea    D38(%rip),%rdx
  xor    %esi,%esi
  xor    %edi,%edi
  xor    %eax,%eax
  mov    $0x3f,%r14d
  call   <rs_error@plt>
  jmp    L121
  nopl   0x0(%rax,%rax,1)
L149:
  add    $0x1,%r12d
  mov    $0x21,%r14d
  mov    %r12d,(%rbx)
  movl   $0x1,(%r8)
  jmp    L121
```

tool_calls: name: unpack_data
arguments: label: D48
type_guessed: string
name: unpack_data
arguments: label: D22
type_guessed: string
name: unpack_data
arguments: label: D21
type_guessed: string
name: unpack_data
arguments: label: D36
type_guessed: string
name: unpack_data
arguments: label: D38
type_guessed: string

tool: D48: --help

tool: D22: --version

tool: D21: unrecognized option -%c (try --help)

tool: D36: -%c: requires an argument

tool: D38: unrecognized option %s (try --help)

assistant: ```c
int rs_parse_cmdline(int argc, char **argv, const char *optstring, int *i, int *j, const char **arg) {
  char c;
  char *p;
  if (*i >= argc)
    return 0;
  if (argv[*i][0] != '-' || argv[*i][1] == 0) {
    *arg = argv[*i];
    (*i)++;
    *j = 1;
    return '#';
  }
  if (argv[*i][1] == '-') {
    if (!strcasecmp(argv[*i], "--help")) {
      (*i)++;
      *j = 1;
      return '!';
    } else if (!strcasecmp(argv[*i], "--version")) {
      (*i)++;
      *j = 1;
      return '@';
    } else {
      rs_error(NULL, NULL, "unrecognized option %s (try --help)", argv[*i]);
      return '?';
    }
  }
  c = argv[*i][*j];
  if (c == ':' || !(p = strchr(optstring, c))) {
    rs_error(NULL, NULL, "unrecognized option -%c (try --help)", c);
    return '?';
  }
  if (p[1] == ':') {
    if (argv[*i][*j + 1]) {
      *arg = &argv[*i][*j + 1];
      (*i)++;
      *j = 1;
      return c;
    } else {
      (*i) += 2;
      *j = 1;
      if (*i > argc) {
        rs_error(NULL, NULL, "-%c: requires an argument", c);
        return '?';
      }
      *arg = argv[*i - 1];
      return c;
    }
  } else {
    if (argv[*i][*j + 1]) {
      (*j)++;
    } else {
      (*i)++;
      *j = 1;
    }
    *arg = NULL;
    return c;
  }
}
```