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

```asm
<relatepaths>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x150,%rsp
  mov    %rdi,-0x138(%rbp)
  mov    %rsi,-0x140(%rbp)
  mov    %rdx,-0x148(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  cmpq   $0x0,-0x138(%rbp)
  je     L159
  mov    -0x138(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  je     L20
L159:
  lea    D2(%rip),%rax
  mov    %rax,%rdi
  call   <fail@plt>
L20:
  cmpq   $0x0,-0x140(%rbp)
  je     L170
  mov    -0x140(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  je     L95
L170:
  lea    D3(%rip),%rax
  mov    %rax,%rdi
  call   <fail@plt>
L95:
  mov    -0x140(%rbp),%rax
  mov    %rax,-0x120(%rbp)
  mov    -0x138(%rbp),%rax
  mov    %rax,-0x118(%rbp)
  jmp    L145
L53:
  mov    -0x120(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L44
  addq   $0x1,-0x120(%rbp)
  addq   $0x1,-0x118(%rbp)
L145:
  mov    -0x120(%rbp),%rax
  movzbl (%rax),%edx
  mov    -0x118(%rbp),%rax
  movzbl (%rax),%eax
  cmp    %al,%dl
  je     L53
  jmp    L92
L44:
  nop
  jmp    L92
L96:
  subq   $0x1,-0x120(%rbp)
  subq   $0x1,-0x118(%rbp)
L92:
  mov    -0x120(%rbp),%rax
  sub    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  jne    L96
  mov    -0x120(%rbp),%rax
  sub    $0x1,%rax
  cmp    %rax,-0x140(%rbp)
  jne    L158
  mov    -0x140(%rbp),%rdx
  mov    -0x148(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcpy@plt>
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,-0x124(%rbp)
  mov    -0x124(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x148(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  je     L52
  mov    -0x124(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x124(%rbp)
  movslq %eax,%rdx
  mov    -0x148(%rbp),%rax
  add    %rdx,%rax
  movb   $0x2f,(%rax)
  mov    -0x124(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x148(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  jmp    L52
L158:
  movl   $0x0,-0x124(%rbp)
  jmp    L139
L67:
  mov    -0x124(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x148(%rbp),%rax
  add    %rdx,%rax
  movl   $0x2f2e2e,(%rax)
  addl   $0x3,-0x124(%rbp)
L139:
  lea    -0x110(%rbp),%rdx
  mov    -0x118(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <getcomponent@plt>
  mov    %rax,-0x118(%rbp)
  cmpq   $0x0,-0x118(%rbp)
  jne    L67
  jmp    L35
L106:
  mov    -0x124(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x148(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  lea    -0x110(%rbp),%rax
  mov    %rax,%rdx
  lea    D14(%rip),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <sprintf@plt>
  mov    -0x124(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x148(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    %eax,-0x124(%rbp)
L35:
  lea    -0x110(%rbp),%rdx
  mov    -0x120(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <getcomponent@plt>
  mov    %rax,-0x120(%rbp)
  cmpq   $0x0,-0x120(%rbp)
  jne    L106
L52:
  mov    -0x124(%rbp),%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L179
  call   <__stack_chk_fail@plt>
L179:
  leave
  ret
```

tool_calls: name: unpack_data
arguments: data_label: D2
datatype: string
name: unpack_data
arguments: data_label: D3
datatype: string
name: unpack_data
arguments: data_label: D14
datatype: string

tool: D2: relatepaths: from path does not start with /

tool: D3: relatepaths: to   path does not start with /

tool: D14: %s/

assistant: ```c
int relatepaths(char *from, char *to, char *outpath) {
  char *cp, *cp2;
  int len;
  char buf[256];
  if (!from || *from != '/')
    fail("relatepaths: from path does not start with /");
  if (!to || *to != '/')
    fail("relatepaths: to   path does not start with /");
  for (cp = to, cp2 = from; *cp == *cp2; cp++, cp2++)
    if (*cp == '\0')
      break;
  while (cp[-1] != '/')
    cp--, cp2--;
  if (cp - 1 == to) {
    len = strlen(strcpy(outpath, to));
    if (outpath[len] != '/') {
      outpath[len++] = '/';
      outpath[len] = '\0';
    }
  } else {
    len = 0;
    while ((cp2 = getcomponent(cp2, buf)) != 0) {
      strcpy(outpath + len, "../");
      len += 3;
    }
    while ((cp = getcomponent(cp, buf)) != 0) {
      sprintf(outpath + len, "%s/", buf);
      len += strlen(outpath + len);
    }
  }
  return len;
}
```