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

```asm
<parse_http_proto_ws>:
  endbr64
  push   %r15
  lea    D7(%rip),%r15
  push   %r14
  xor    %r14d,%r14d
  push   %r13
  lea    D9(%rip),%r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  xor    %ebp,%ebp
  push   %rbx
  sub    $0x8,%rsp
L73:
  mov    %r12,%rdi
  call   <readline_client_ws@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L85
L41:
  mov    %r13,%rsi
  mov    %rbx,%rdi
  call   <strstr@plt>
  test   %rax,%rax
  je     L40
  mov    %r13,%rdi
  call   <strlen@plt>
  cltq
  lea    (%rbx,%rax,1),%rdi
  call   <strdup@plt>
  mov    %r12,%rdi
  mov    %rax,%rbp
  call   <readline_client_ws@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  jne    L41
L85:
  test   %rbp,%rbp
  je     L110
  test   %r14,%r14
  je     L101
  lea    D13(%rip),%r13
  mov    %r13,%rdi
  call   <strlen@plt>
  mov    %r13,%rsi
  mov    %r14,%rdi
  mov    %eax,%edx
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L16
  mov    %r14,%rdi
  call   <free@plt>
  mov    %r12,%rdi
  mov    %rbp,%rsi
  call   <generate_upgrade_response_ws@plt>
  mov    %rbp,%rdi
  test   %rax,%rax
  js     L90
  call   <free@plt>
  mov    %r12,%rdi
  call   <upgrade_client_ws@plt>
  sar    $0x3f,%rax
  mov    %rax,%r12
L119:
  add    $0x8,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L40:
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   <strstr@plt>
  test   %rax,%rax
  je     L73
  mov    %r15,%rdi
  call   <strlen@plt>
  cltq
  lea    (%rbx,%rax,1),%rdi
  call   <strdup@plt>
  mov    %rax,%r14
  jmp    L73
L110:
  test   %r14,%r14
  je     L101
L16:
  mov    %r14,%rdi
  call   <free@plt>
L101:
  mov    $0xffffffff,%r12d
  test   %rbp,%rbp
  je     L119
  mov    %rbp,%rdi
  call   <free@plt>
  jmp    L119
L90:
  call   <free@plt>
  mov    $0xffffffff,%r12d
  jmp    L119
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D7
data_type: string
name: extract_symbolic_data
arguments: data_label: D9
data_type: string
name: extract_symbolic_data
arguments: data_label: D13
data_type: string

tool: D7: Sec-WebSocket-Protocol: 

tool: D9: Sec-WebSocket-Key: 

tool: D13: katcp

assistant: ```c
int parse_http_proto_ws(struct ws_client *c) {
  char *line, *key, *proto;
  key = NULL;
  proto = NULL;
  while ((line = (char *)readline_client_ws(c)) != NULL) {
    if (strstr((const char *)line, "Sec-WebSocket-Key: ") != NULL) {
      key = strdup(line + strlen("Sec-WebSocket-Key: "));
    } else if (strstr((const char *)line, "Sec-WebSocket-Protocol: ") != NULL) {
      proto = strdup(line + strlen("Sec-WebSocket-Protocol: "));
    }
  }
  if (key != NULL && proto != NULL && strncmp(proto, "katcp", strlen("katcp")) == 0) {
    if (proto != NULL) {
      free(proto);
      proto = NULL;
    }
    if (generate_upgrade_response_ws(c, key) < 0) {
      if (key != NULL) {
        free(key);
        key = NULL;
      }
      return -1;
    }
    if (key != NULL) {
      free(key);
      key = NULL;
    }
    if (upgrade_client_ws(c) < 0) {
      return -1;
    }
  } else {
    if (proto != NULL) {
      free(proto);
      proto = NULL;
    }
    if (key != NULL) {
      free(key);
      key = NULL;
    }
    return -1;
  }
  if (proto != NULL) {
    free(proto);
    proto = NULL;
  }
  if (key != NULL) {
    free(key);
    key = NULL;
  }
  return 0;
}
```