user: Please show me the C implementation that matches the assembly code listed below:

```asm
<gg_urlencode>:
  endbr64
  push   %rbx
  sub    $0x20,%rsp
  movdqa D1(%rip),%xmm0
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  movb   $0x0,0x10(%rsp)
  movaps %xmm0,(%rsp)
  test   %rdi,%rdi
  je     L30
  movzbl (%rdi),%eax
  mov    %rdi,%rbx
  test   %al,%al
  je     L172
  mov    %rdi,%rcx
  xor    %esi,%esi
  cs nopw 0x0(%rax,%rax,1)
L10:
  mov    %eax,%edx
  and    $0xffffffdf,%edx
  sub    $0x41,%edx
  cmp    $0x19,%dl
  jbe    L183
  lea    -0x30(%rax),%edx
  cmp    $0x9,%dl
  jbe    L183
  cmp    $0x20,%al
  jne    L54
L183:
  lea    -0x2d(%rax),%edx
  cmp    $0x1,%dl
  jbe    L54
  mov    %esi,%edi
  cmp    $0x40,%al
  jne    L8
L54:
  lea    0x2(%rsi),%edi
L8:
  movzbl 0x1(%rcx),%eax
  add    $0x1,%rcx
  lea    0x1(%rdi),%esi
  test   %al,%al
  jne    L10
  add    $0x2,%edi
L142:
  call   <malloc@plt>
  test   %rax,%rax
  je     L122
  movzbl (%rbx),%edx
  mov    %rax,%rcx
  test   %dl,%dl
  je     L198
  movabs $0xffffc0000007e004,%rdi
  xchg   %ax,%ax
L171:
  lea    -0x61(%rdx),%esi
  cmp    $0x19,%sil
  jbe    L153
  lea    -0x2d(%rdx),%esi
  cmp    $0x2d,%sil
  jbe    L84
  cmp    $0x20,%dl
  je     L112
L5:
  movb   $0x25,(%rcx)
  movzbl (%rbx),%edx
  add    $0x1,%rbx
  add    $0x2,%rcx
  shr    $0x4,%dl
  and    $0xf,%edx
  movzbl (%rsp,%rdx,1),%edx
  mov    %dl,-0x1(%rcx)
  movzbl -0x1(%rbx),%edx
  and    $0xf,%edx
  movzbl (%rsp,%rdx,1),%edx
  mov    %dl,(%rcx)
  movzbl (%rbx),%edx
  add    $0x1,%rcx
  test   %dl,%dl
  jne    L171
  xchg   %ax,%ax
L198:
  movb   $0x0,(%rcx)
L32:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L116
  add    $0x20,%rsp
  pop    %rbx
  ret
  nopl   0x0(%rax)
L84:
  bt     %rsi,%rdi
  jb     L5
L153:
  add    $0x1,%rbx
  mov    %dl,(%rcx)
  add    $0x1,%rcx
  movzbl (%rbx),%edx
  test   %dl,%dl
  jne    L171
  jmp    L198
  nopl   (%rax)
L30:
  mov    $0x1,%edi
  call   <malloc@plt>
  mov    %rax,%rcx
  test   %rax,%rax
  jne    L198
L122:
  xor    %eax,%eax
  jmp    L32
  cs nopw 0x0(%rax,%rax,1)
L112:
  add    $0x1,%rbx
  movb   $0x2b,(%rcx)
  add    $0x1,%rcx
  movzbl (%rbx),%edx
  test   %dl,%dl
  jne    L171
  jmp    L198
L172:
  mov    $0x1,%edi
  jmp    L142
L116:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: label: D1
type_guessed: byte[16]

tool: {"D1": [0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x61,0x62,0x63,0x64,0x65,0x66]}

assistant: ```c
char *gg_urlencode(const char *str) {
  char *q, *buf, hex[] = "0123456789abcdef";
  const char *p;
  unsigned int size = 0;
  if (!str)
    str = "";
  for (p = str; *p; p++, size++) {
    if (!((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || *p == ' ') || (*p == '@') || (*p == '.') || (*p == '-'))
      size += 2;
  }
  if (!(buf = malloc(size + 1)))
    return NULL;
  for (p = str, q = buf; *p; p++, q++) {
    if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || (*p == '@') || (*p == '.') || (*p == '-'))
      *q = *p;
    else {
      if (*p == ' ')
        *q = '+';
      else {
        *q++ = '%';
        *q++ = hex[*p >> 4 & 15];
        *q = hex[*p & 15];
      }
    }
  }
  *q = 0;
  return buf;
}
```