user: Translate the below assembly code into C programming language:

```asm
<urlencode>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x828,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x818(%rsp)
  xor    %eax,%eax
  cmp    $0x2,%ecx
  jg     L106
  mov    %rdi,%r13
  mov    %rsi,%r15
  mov    %edx,%r12d
  mov    %ecx,%r14d
  test   %edx,%edx
  je     L163
  mov    $0x0,%ebx
  mov    $0x0,%ebp
  jmp    L129
L27:
  cmp    $0x2,%r14d
  jne    L42
  cmp    $0x20,%dl
  jne    L42
  mov    %ebx,%eax
  movb   $0x2b,0x10(%rsp,%rax,1)
  lea    0x1(%rbx),%ebx
L25:
  add    $0x1,%ebp
  cmp    %ebp,%r12d
  jbe    L133
  cmp    $0x7fe,%ebx
  ja     L133
L129:
  mov    %ebp,%eax
  movzbl 0x0(%r13,%rax,1),%edx
  lea    -0x3a(%rdx),%eax
  cmp    $0x6,%al
  jbe    L27
  cmp    $0x2f,%dl
  jbe    L27
  lea    -0x5b(%rdx),%eax
  cmp    $0x5,%al
  jbe    L42
  lea    -0x7b(%rdx),%eax
  cmp    $0x4,%al
  jbe    L42
  mov    %ebx,%eax
  mov    %dl,0x10(%rsp,%rax,1)
  add    $0x1,%ebx
  jmp    L25
L42:
  movzbl %dl,%edx
  lea    0xc(%rsp),%rdi
  lea    D10(%rip),%rsi
  call   <sprintf@plt>
  mov    %ebx,%eax
  movzbl 0xc(%rsp),%edx
  mov    %dl,0x10(%rsp,%rax,1)
  lea    0x1(%rbx),%eax
  movzbl 0xd(%rsp),%edx
  mov    %dl,0x10(%rsp,%rax,1)
  lea    0x2(%rbx),%eax
  movzbl 0xe(%rsp),%edx
  mov    %dl,0x10(%rsp,%rax,1)
  add    $0x3,%ebx
  jmp    L25
L133:
  cmp    $0x7fe,%ebx
  jbe    L90
  lea    -0x1(%rbx),%eax
  movb   $0x0,0x10(%rsp,%rax,1)
  jmp    L40
L163:
  mov    %edx,%ebx
L90:
  mov    %ebx,%ebx
  movb   $0x0,0x10(%rsp,%rbx,1)
L40:
  lea    0x10(%rsp),%rdi
  call   <strlen@plt>
  lea    0x1(%rax),%rsi
  mov    (%r15),%rdi
  call   <realloc@plt>
  mov    %rax,(%r15)
  test   %rax,%rax
  je     L175
L108:
  lea    0x10(%rsp),%rsi
  mov    (%r15),%rdi
  call   <strcpy@plt>
L106:
  mov    0x818(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L149
  add    $0x828,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L175:
  lea    D2(%rip),%rdi
  call   <printf@plt>
  mov    $0x0,%edi
  call   <exit@plt>
  jmp    L108
L149:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: data_tag: D10
data_type: string
name: retrieve_data
arguments: data_tag: D2
data_type: string

tool: D10: %%%2x

tool: D2: 
 Realloc failed 


assistant: ```c
void urlencode(char *src, char **dst, unsigned int size, int type) {
  unsigned int i, j = 0;
  unsigned char c;
  char newchar[4];
  char newdst[2048];
  if (type > 2)
    return;
  for (i = 0; i < size && j < (2048 - 1); i++) {
    c = src[i];
    if ((c < 48) || (c > 57 && c < 65) || (c > 90 && c < 97) || (c > 122 && c < 128)) {
      if (type == 2 && c == 32) {
        newdst[j++] = '+';
      } else {
        sprintf(newchar, "\%%%2x", c);
        newdst[j] = newchar[0];
        newdst[j + 1] = newchar[1];
        newdst[j + 2] = newchar[2];
        j = j + 3;
      }
    } else {
      newdst[j] = c;
      j++;
    }
  }
  if (j < (2048 - 1))
    newdst[j] = '\0';
  else
    newdst[j - 1] = '\0';
  *dst = realloc(*dst, strlen(newdst) + 1);
  if (*dst == NULL) {
    printf("\n Realloc failed \n");
    exit(0);
  }
  strcpy(*dst, newdst);
}
```