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

```asm
<expand_envars>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  mov    %rdi,%r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x48,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  call   <strlen@plt>
  mov    $0x1,%edi
  add    %eax,%eax
  mov    %eax,%esi
  mov    %eax,-0x4c(%rbp)
  call   <calloc@plt>
  mov    %rax,-0x60(%rbp)
  movzbl (%r15),%eax
  test   %al,%al
  je     L193
  xor    %ebx,%ebx
  jmp    L92
  nopl   0x0(%rax)
L137:
  movzbl (%r15),%eax
  mov    -0x60(%rbp),%rcx
  mov    -0x58(%rbp),%r15
  mov    %al,(%rcx,%r10,1)
  movslq %ebx,%rax
  movb   $0x0,(%rcx,%rax,1)
L252:
  movzbl (%r15),%eax
  test   %al,%al
  je     L257
L92:
  lea    0x1(%r15),%rdx
  mov    %rdx,-0x58(%rbp)
  cmp    $0x24,%al
  je     L271
L46:
  movslq %ebx,%r10
L60:
  add    $0x1,%ebx
  cmp    -0x4c(%rbp),%ebx
  jl     L137
  shll   -0x4c(%rbp)
  mov    -0x60(%rbp),%rdi
  mov    -0x4c(%rbp),%esi
  mov    %r10,-0x48(%rbp)
  call   <realloc@plt>
  mov    -0x48(%rbp),%r10
  mov    %rax,-0x60(%rbp)
  jmp    L137
  nop
L271:
  movsbl 0x1(%r15),%edi
  cmp    $0x7b,%dil
  je     L32
  mov    %rdx,-0x48(%rbp)
  movl   $0x0,-0x68(%rbp)
  test   %dil,%dil
  je     L322
L89:
  xor    %r14d,%r14d
  cs nopw 0x0(%rax,%rax,1)
L183:
  mov    %r14d,%r12d
  mov    %r14d,%r13d
  call   <isalnum@plt>
  test   %rax,%rax
  jne    L268
  mov    -0x48(%rbp),%rax
  movzbl (%rax,%r14,1),%eax
  cmp    $0x5f,%al
  jne    L315
L268:
  mov    -0x48(%rbp),%rax
  add    $0x1,%r14
  lea    0x1(%r12),%r13d
  movsbl (%rax,%r14,1),%edi
  test   %dil,%dil
  jne    L183
  mov    -0x68(%rbp),%eax
  movslq %ebx,%r10
  test   %eax,%eax
  jne    L60
  movq   $0x0,-0x68(%rbp)
  lea    0x2(%r12),%eax
  cltq
L308:
  add    $0xf,%rax
  mov    %rsp,%rdi
  mov    %rsp,%r12
  mov    %rax,%rsi
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rdi
  and    $0xfffffffffffffff0,%rsi
  cmp    %rdi,%rsp
  je     L301
L214:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rdi,%rsp
  jne    L214
L301:
  and    $0xfff,%esi
  sub    %rsi,%rsp
  test   %rsi,%rsi
  jne    L4
L11:
  mov    -0x48(%rbp),%rsi
  mov    %rsp,%r10
  mov    %r13d,%edx
  mov    %rsp,%rdi
  mov    %r10,-0x70(%rbp)
  call   <strncpy@plt>
  movslq %r13d,%rdx
  lea    D6(%rip),%rsi
  mov    %rsp,%rdi
  movb   $0x0,(%rsp,%rdx,1)
  call   <strcmp@plt>
  mov    -0x70(%rbp),%r10
  test   %rax,%rax
  je     L296
  movzbl (%rsp),%eax
  sub    $0x30,%eax
  cmp    $0x9,%al
  jbe    L296
  movslq %ebx,%r10
L324:
  mov    %r12,%rsp
  jmp    L60
  cs nopw 0x0(%rax,%rax,1)
L257:
  movslq %ebx,%rbx
  add    -0x60(%rbp),%rbx
L314:
  movb   $0x0,(%rbx)
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L222
  mov    -0x60(%rbp),%rax
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L296:
  mov    %r10,%rdi
  call   <getenv@plt>
  mov    %rax,%r13
  test   %rax,%rax
  jne    L160
  mov    -0x60(%rbp),%rax
  movslq %ebx,%r10
  movb   $0x0,(%rax,%r10,1)
  jmp    L324
  xchg   %ax,%ax
L32:
  movsbl 0x2(%r15),%edi
  lea    0x2(%r15),%rax
  movl   $0x1,-0x68(%rbp)
  mov    %rax,-0x48(%rbp)
  test   %dil,%dil
  jne    L89
  jmp    L46
  nopw   0x0(%rax,%rax,1)
L315:
  mov    -0x68(%rbp),%edx
  test   %edx,%edx
  je     L327
  cmp    $0x7d,%al
  jne    L46
  lea    0x1(%r14),%eax
  movq   $0x2,-0x68(%rbp)
  cltq
  jmp    L308
L4:
  orq    $0x0,-0x8(%rsp,%rsi,1)
  jmp    L11
  nopl   (%rax)
L160:
  mov    %rax,%rdi
  call   <strlen@plt>
  add    %eax,%ebx
  cmp    -0x4c(%rbp),%ebx
  jge    L275
L326:
  mov    -0x60(%rbp),%rdi
  mov    %r13,%rsi
  call   <strcat@plt>
  mov    -0x68(%rbp),%rax
  mov    %r12,%rsp
  lea    0x1(%r14,%rax,1),%rax
  add    %rax,%r15
  jmp    L252
L327:
  lea    0x1(%r14),%eax
  movq   $0x0,-0x68(%rbp)
  cltq
  jmp    L308
L193:
  mov    -0x60(%rbp),%rbx
  jmp    L314
L275:
  mov    -0x4c(%rbp),%esi
  mov    -0x60(%rbp),%rdi
  lea    (%rax,%rsi,2),%eax
  mov    %eax,%esi
  mov    %eax,-0x4c(%rbp)
  call   <realloc@plt>
  mov    %rax,-0x60(%rbp)
  jmp    L326
L322:
  movq   $0x0,-0x68(%rbp)
  mov    $0x1,%eax
  xor    %r13d,%r13d
  xor    %r14d,%r14d
  jmp    L308
L222:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D6
datatype: string

tool: D6: ONDIRWD

assistant: ```c
char *expand_envars(const char *in) {
  int inlen = strlen(in), outmax = inlen * 2, outlen = 0;
  char *out = calloc(1, outmax);
  while (*in) {
    const char *mark = in;
    if (*in == '$') {
      int bracketed = 0, varlen = 0;
      const char *varstart;
      ++in;
      if (*in == '{') {
        ++in;
        bracketed = 1;
      }
      varstart = in;
      while (in[varlen] && (isalnum(in[varlen]) || in[varlen] == '_'))
        ++varlen;
      if (bracketed && in[varlen] != '}')
        in = mark;
      else {
        char var[varlen + 1];
        const char *val;
        strncpy(var, varstart, varlen);
        var[varlen] = 0;
        if (strcmp(var, "ONDIRWD") && (var[0] < '0' || var[0] > '9')) {
          in = mark;
        } else {
          val = getenv(var);
          if (val) {
            int vallen = strlen(val);
            if (outlen + vallen >= outmax) {
              outmax = outmax * 2 + vallen;
              out = realloc(out, outmax);
            }
            strcat(out, val);
            outlen += vallen;
            in = mark + varlen + bracketed * 2 + 1;
            continue;
          } else {
            in = mark;
            out[outlen] = 0;
          }
        }
      }
    }
    if (outlen + 1 >= outmax) {
      outmax *= 2;
      out = realloc(out, outmax);
    }
    out[outlen++] = *in++;
    out[outlen] = 0;
  }
  out[outlen] = 0;
  return out;
}
```