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

```asm
<cmd_set_path>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %rsi,-0x30(%rbp)
  mov    %edx,-0x34(%rbp)
  mov    %rcx,-0x40(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x0,-0x20(%rbp)
  movl   $0x0,-0x1c(%rbp)
  mov    $0x7d0,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  mov    -0x18(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <trim@plt>
  lea    -0x20(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  lea    D33(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strtoken@plt>
  mov    %rax,-0x10(%rbp)
  movl   $0x0,-0x1c(%rbp)
  jmp    L29
L43:
  cmpl   $0x0,-0x1c(%rbp)
  jle    L35
  mov    -0x18(%rbp),%rax
  lea    D33(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
L35:
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  lea    D24(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L37
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  jmp    L39
L37:
  mov    -0x40(%rbp),%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
L39:
  addl   $0x1,-0x1c(%rbp)
L29:
  mov    -0x20(%rbp),%eax
  cmp    %eax,-0x1c(%rbp)
  jl     L43
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  lea    D12(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcpy@plt>
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  mov    -0x18(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x20(%rbp),%edx
  mov    -0x10(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <free_array@plt>
  nop
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L44
  call   <__stack_chk_fail@plt>
L44:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: data_tag: D33
type_guessed: string
name: disassemble_data
arguments: data_tag: D24
type_guessed: string
name: disassemble_data
arguments: data_tag: D12
type_guessed: string

tool: D33: :

tool: D24: $PATH

tool: D12: PATH=

assistant: ```c
void cmd_set_path(char *cmdpath, char **envp, int path_index, char *envpath) {
  int token_len = 0, i = 0;
  char *sbushPath = (char *)malloc(2000 * sizeof(char));
  sbushPath[0] = '\0';
  char **tokens;
  trim(cmdpath);
  tokens = strtoken(cmdpath, ":", &token_len);
  for (i = 0; i < token_len; i++) {
    if (i > 0)
      strcat(sbushPath, ":");
    if (strcmp(tokens[i], "$PATH") != 0)
      strcat(sbushPath, tokens[i]);
    else
      strcat(sbushPath, envpath);
  }
  strcpy(envp[path_index], "PATH=");
  strcat(envp[path_index], sbushPath);
  free(sbushPath);
  free_array(tokens, token_len);
}
```