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

```asm
<url_encode>:
  endbr64
  push   %r15
  mov    $0xfe,%ecx
  pxor   %xmm0,%xmm0
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  mov    %esi,%ebx
  mov    %rbp,%rsi
  sub    $0x818,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x808(%rsp)
  xor    %eax,%eax
  lea    0x10(%rsp),%rdi
  movaps %xmm0,(%rsp)
  rep stos %rax,%es:(%rdi)
  lea    D1(%rip),%rdi
  call   <printf@plt>
  movzbl 0x0(%rbp),%edi
  test   %dil,%dil
  je     L91
  test   %ebx,%ebx
  jne    L182
  mov    %rsp,%r12
  mov    %rbp,%r13
  lea    D35(%rip),%rbx
  mov    %r12,%r14
  jmp    L131
  nopl   0x0(%rax,%rax,1)
L52:
  movzbl 0x0(%r13),%eax
  add    $0x1,%r14
  mov    %al,-0x1(%r14)
L164:
  movzbl 0x1(%r13),%edi
  add    $0x1,%r13
  test   %dil,%dil
  je     L35
L44:
  mov    %r14,%rax
  sub    %r12,%rax
  cmp    $0x7fb,%rax
  jg     L35
L131:
  call   <isalnum@plt>
  test   %rax,%rax
  jne    L52
  movzbl 0x0(%r13),%esi
  mov    %rbx,%rdi
  call   <strchr@plt>
  test   %rax,%rax
  jne    L52
  movzbl 0x0(%r13),%edi
  cmp    $0x20,%dil
  jne    L142
  movzbl 0x1(%r13),%edi
  movb   $0x2b,(%r14)
  add    $0x1,%r13
  add    $0x1,%r14
  test   %dil,%dil
  jne    L44
  nopw   0x0(%rax,%rax,1)
L35:
  movb   $0x0,(%r14)
  mov    %r12,%rsi
  lea    D30(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    %r12,%rcx
  mov    $0x800,%esi
  mov    %rbp,%rdi
  lea    D45(%rip),%rdx
  call   <snprintf@plt>
  mov    0x808(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L191
  add    $0x818,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L142:
  movb   $0x25,(%r14)
  shr    $0x4,%dil
  add    $0x3,%r14
  movzbl %dil,%edi
  call   <to_hex@plt>
  movzbl 0x0(%r13),%edi
  mov    %al,-0x2(%r14)
  and    $0xf,%edi
  call   <to_hex@plt>
  mov    %al,-0x1(%r14)
  jmp    L164
  nop
L182:
  mov    %rsp,%r12
  mov    %rbp,%r15
  lea    D35(%rip),%rbx
  mov    %r12,%r14
  lea    D27(%rip),%r13
  jmp    L45
  nopl   0x0(%rax)
L149:
  movzbl (%r15),%eax
  add    $0x1,%r14
  mov    %al,-0x1(%r14)
L170:
  movzbl 0x1(%r15),%edi
  add    $0x1,%r15
  test   %dil,%dil
  je     L35
  mov    %r14,%rax
  sub    %r12,%rax
  cmp    $0x7fb,%rax
  jg     L35
L45:
  call   <isalnum@plt>
  test   %rax,%rax
  jne    L149
  movzbl (%r15),%esi
  mov    %rbx,%rdi
  call   <strchr@plt>
  test   %rax,%rax
  jne    L149
  movzbl (%r15),%esi
  mov    %r13,%rdi
  call   <strchr@plt>
  test   %rax,%rax
  jne    L149
  movzbl (%r15),%eax
  cmp    $0x20,%al
  jne    L200
  movb   $0x2b,(%r14)
  add    $0x1,%r14
  jmp    L170
  xchg   %ax,%ax
L200:
  movb   $0x25,(%r14)
  shr    $0x4,%al
  add    $0x3,%r14
  movzbl %al,%edi
  call   <to_hex@plt>
  movzbl (%r15),%edi
  mov    %al,-0x2(%r14)
  and    $0xf,%edi
  call   <to_hex@plt>
  mov    %al,-0x1(%r14)
  jmp    L170
L91:
  mov    %rsp,%r12
  mov    %r12,%r14
  jmp    L35
L191:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D1
type: string
name: extract_symbolic_data
arguments: data_label: D35
type: string
name: extract_symbolic_data
arguments: data_label: D30
type: string
name: extract_symbolic_data
arguments: data_label: D45
type: string
name: extract_symbolic_data
arguments: data_label: D27
type: string

tool: D1: orignal str:%s


tool: D35: _-.~

tool: D30: encode: %s


tool: D45: %s

tool: D27: %?&=/:

assistant: ```c
int url_encode(char *str, int ext) {
  unsigned char *pstr = (unsigned char *)str;
  unsigned char buf[2048] = {0};
  unsigned char *pbuf = buf;
  printf("orignal str:%s\n", str);
  while (*pstr && (pbuf - buf + 4) < 2048) {
    if (isalnum(*pstr) || NULL != strchr("_-.~", *pstr) || (ext && NULL != strchr("%?&=/:", *pstr))) {
      *pbuf++ = *pstr;
    } else if (*pstr == ' ') {
      *pbuf++ = '+';
    } else {
      *pbuf++ = '%';
      *pbuf++ = to_hex(*pstr >> 4);
      *pbuf++ = to_hex(*pstr & 15);
    }
    pstr++;
  }
  *pbuf = '\0';
  printf("encode: %s\n", buf);
  snprintf(str, 2048, "%s", buf);
  return 0;
}
```