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    $0x838,%rsp
  mov    %rsi,0x8(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x828(%rsp)
  xor    %eax,%eax
  cmp    $0x2,%ecx
  jg     L178
  mov    %edx,%r14d
  test   %edx,%edx
  je     L86
  mov    %rdi,%r15
  xor    %ebx,%ebx
  lea    D19(%rip),%r12
  xor    %ebp,%ebp
  jmp    L33
  nopl   0x0(%rax)
L171:
  lea    -0x5b(%rdx),%eax
  cmp    $0x5,%al
  jbe    L173
  lea    -0x7b(%rdx),%eax
  cmp    $0x4,%al
  jbe    L173
  mov    %ebx,%eax
  mov    %dl,0x20(%rsp,%rax,1)
  mov    %ebx,%eax
  mov    %r13d,%ebx
L95:
  add    $0x1,%ebp
  cmp    %ebp,%r14d
  jbe    L189
L57:
  cmp    $0x7fe,%ebx
  ja     L63
L33:
  mov    %ebp,%eax
  lea    0x1(%rbx),%r13d
  movzbl (%r15,%rax,1),%edx
  lea    -0x3a(%rdx),%eax
  cmp    $0x6,%al
  jbe    L147
  cmp    $0x2f,%dl
  ja     L171
L147:
  cmp    $0x2,%ecx
  jne    L173
  cmp    $0x20,%dl
  jne    L173
  mov    %ebx,%eax
  add    $0x1,%ebp
  movb   $0x2b,0x20(%rsp,%rax,1)
  mov    %ebx,%eax
  mov    %r13d,%ebx
  cmp    %ebp,%r14d
  ja     L57
L189:
  cmp    $0x7fe,%ebx
  ja     L63
L101:
  movb   $0x0,0x20(%rsp,%rbx,1)
  jmp    L96
  nopl   0x0(%rax)
L173:
  lea    0x1c(%rsp),%rdi
  mov    %r12,%rsi
  mov    %ecx,0x4(%rsp)
  call   <sprintf@plt>
  movzbl 0x1c(%rsp),%edx
  mov    %ebx,%eax
  mov    0x4(%rsp),%ecx
  movzbl 0x1e(%rsp),%edi
  mov    %dl,0x20(%rsp,%rax,1)
  movzbl 0x1d(%rsp),%eax
  lea    0x2(%rbx),%edx
  add    $0x3,%ebx
  mov    %al,0x20(%rsp,%r13,1)
  mov    %rdx,%rax
  mov    %dil,0x20(%rsp,%rdx,1)
  jmp    L95
  nopw   0x0(%rax,%rax,1)
L63:
  movb   $0x0,0x20(%rsp,%rax,1)
L96:
  lea    0x20(%rsp),%rbp
  mov    %rbp,%rdi
  call   <strlen@plt>
  mov    0x8(%rsp),%rbx
  lea    0x1(%rax),%rsi
  mov    (%rbx),%rdi
  call   <realloc@plt>
  mov    %rax,(%rbx)
  mov    %rax,%rdi
  test   %rax,%rax
  je     L71
L154:
  mov    %rbp,%rsi
  call   <strcpy@plt>
L178:
  mov    0x828(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L93
  add    $0x838,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L71:
  lea    D15(%rip),%rdi
  call   <printf@plt>
  xor    %edi,%edi
  call   <exit@plt>
  mov    0x8(%rsp),%rax
  mov    (%rax),%rdi
  jmp    L154
  nopl   (%rax)
L86:
  xor    %ebx,%ebx
  jmp    L101
L93:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: tag: D19
type_guessed: string
name: disassemble_data
arguments: tag: D15
type_guessed: string

tool: D19: %%%2x

tool: D15: 
 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);
}
```