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

```asm
<handle_ccn_signature>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rdi,%rbp
  mov    %rsi,%rbx
  mov    %rdx,0x8(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  mov    $0x0,%r15d
  movq   $0x0,(%rsp)
  lea    0x18(%rsp),%r12
  jmp    L53
L125:
  mov    0x18(%rsp),%edi
  cmp    $0x2,%edi
  sete   %al
  cmp    $0xe,%esi
  jne    L4
  test   %al,%al
  jne    L146
L4:
  mov    (%rbx),%r13d
  cmp    $0x36,%esi
  jne    L132
  test   %al,%al
  jne    L185
L132:
  mov    $0x0,%r9d
  mov    $0x0,%r8d
  mov    %rbx,%rcx
  mov    %rbp,%rdx
  call   <ccnl_ccnb_consume@plt>
  test   %rax,%rax
  js     L134
L53:
  lea    0x14(%rsp),%rdx
  mov    %r12,%rcx
  mov    %rbx,%rsi
  mov    %rbp,%rdi
  call   <ccnl_ccnb_dehead@plt>
  test   %rax,%rax
  jne    L162
  mov    0x14(%rsp),%esi
  test   %esi,%esi
  jne    L125
  mov    0x18(%rsp),%edi
  test   %edi,%edi
  je     L162
  mov    (%rbx),%r13d
  jmp    L132
L146:
  lea    0x1c(%rsp),%r9
  lea    0x20(%rsp),%r8
  mov    %rbx,%rcx
  mov    %rbp,%rdx
  mov    $0x2,%edi
  call   <ccnl_ccnb_consume@plt>
  test   %rax,%rax
  js     L135
  mov    0x1c(%rsp),%eax
  lea    0x1(%rax),%edi
  call   <malloc@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L135
  mov    0x1c(%rsp),%edx
  mov    0x20(%rsp),%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  movslq 0x1c(%rsp),%rax
  movb   $0x0,(%r14,%rax,1)
  mov    (%rsp),%rdi
  call   <free@plt>
  mov    %r14,(%rsp)
  jmp    L53
L135:
  mov    $0x0,%eax
  jmp    L181
L185:
  lea    0x1c(%rsp),%r9
  lea    0x20(%rsp),%r8
  mov    %rbx,%rcx
  mov    %rbp,%rdx
  mov    $0x2,%edi
  call   <ccnl_ccnb_consume@plt>
  test   %rax,%rax
  js     L39
  mov    0x1c(%rsp),%eax
  lea    0x1(%rax),%edi
  call   <malloc@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L39
  mov    0x1c(%rsp),%edx
  mov    0x20(%rsp),%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  movslq 0x1c(%rsp),%rax
  movb   $0x0,(%r14,%rax,1)
  mov    %r15,%rdi
  call   <free@plt>
  mov    %r14,%r15
  jmp    L53
L39:
  mov    $0x0,%eax
L181:
  mov    0x28(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L75
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L162:
  mov    $0x0,%eax
  mov    0x8(%rsp),%rdi
  test   %rdi,%rdi
  je     L181
  mov    (%rbx),%eax
  lea    0x4(%rax),%ecx
  lea    -0x1(%rax),%edx
  mov    %r13d,%r8d
  sub    %ecx,%r8d
  mov    %r15,%rcx
  mov    0x0(%rbp),%rsi
  call   <verify@plt>
  jmp    L181
L134:
  mov    $0x0,%eax
  jmp    L181
L75:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int handle_ccn_signature(unsigned char **buf, int *buflen, char *relay_public_key) {
  int num, typ, verified = 0, siglen;
  unsigned char *sigtype = 0, *sig = 0;
  while (ccnl_ccnb_dehead(buf, buflen, &num, &typ) == 0) {
    if (num == 0 && typ == 0)
      break;
    if (typ == 2 && num == 14) {
      char *s;
      unsigned char *valptr;
      int vallen;
      if (ccnl_ccnb_consume(typ, num, buf, buflen, &valptr, &vallen) < 0)
        goto Bail;
      s = malloc(vallen + 1);
      if (!s)
        goto Bail;
      memcpy(s, valptr, vallen);
      s[vallen] = '\0';
      free(sigtype);
      sigtype = (unsigned char *)s;
      continue;
    }
    do {
    } while (0);
    siglen = *buflen;
    if (typ == 2 && num == 54) {
      char *s;
      unsigned char *valptr;
      int vallen;
      if (ccnl_ccnb_consume(typ, num, buf, buflen, &valptr, &vallen) < 0)
        goto Bail;
      s = malloc(vallen + 1);
      if (!s)
        goto Bail;
      memcpy(s, valptr, vallen);
      s[vallen] = '\0';
      free(sig);
      sig = (unsigned char *)s;
      continue;
    }
    do {
    } while (0);
    if (ccnl_ccnb_consume(typ, num, buf, buflen, 0, 0) < 0)
      goto Bail;
  }
  siglen = siglen - ((*buflen) + 4);
  unsigned char *buf2 = *buf;
  int buflen2 = *buflen - 1;
  if (relay_public_key) {
    verified = verify(relay_public_key, buf2, buflen2, (unsigned char *)sig, siglen);
  }
Bail:
  return verified;
}
```