user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<variable_substitute>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %rsi,%rbp
  push   %rbx
  sub    $0x128,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x118(%rsp)
  xor    %eax,%eax
  movzbl (%rdi),%eax
  test   %al,%al
  je     L129
  mov    %edx,%ebx
  cmp    $0x1,%edx
  jbe    L129
  mov    %rdi,%r14
  lea    0x10(%rsp),%r13
  jmp    L146
  nopl   0x0(%rax,%rax,1)
L124:
  movzbl (%r14),%edi
L202:
  sub    $0x1,%ebx
  add    $0x1,%r14
  mov    %dil,0x0(%rbp)
  cmp    $0x1,%ebx
  seta   %r12b
  add    $0x1,%rbp
L157:
  movzbl (%r14),%eax
  test   %al,%al
  je     L129
L170:
  test   %r12b,%r12b
  je     L129
L146:
  cmp    $0x24,%al
  jne    L124
  movsbl 0x1(%r14),%edi
  lea    0x1(%r14),%r12
  cmp    $0x24,%dil
  je     L270
  cmp    $0x7b,%dil
  je     L24
  mov    %r12,%r15
  test   %dil,%dil
  jne    L8
  jmp    L184
  nopl   (%rax)
L244:
  mov    %rax,%r15
L8:
  call   <isalnum@plt>
  test   %rax,%rax
  jne    L98
  cmpb   $0x5f,(%r15)
  jne    L155
L98:
  movsbl 0x1(%r15),%edi
  lea    0x1(%r15),%rax
  test   %dil,%dil
  jne    L244
  sub    %r14,%r15
  mov    $0xff,%edx
  mov    %rax,%r14
  cmp    %rdx,%r15
  cmovle %r15,%rdx
L56:
  mov    %r12,%rsi
  mov    %r13,%rdi
  mov    %edx,0xc(%rsp)
  call   <strncpy@plt>
  mov    0xc(%rsp),%edx
  xor    %eax,%eax
  cmpb   $0x7d,(%r14)
  sete   %al
  mov    %r13,%rdi
  movb   $0x0,0x10(%rsp,%rdx,1)
  add    %rax,%r14
  call   <getenv@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L196
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%edx
  cmp    %ebx,%eax
  jae    L222
  sub    %eax,%ebx
  cmp    $0x1,%ebx
  seta   %r12b
L136:
  mov    %rbp,%rdi
  mov    %r15,%rsi
  mov    %edx,0xc(%rsp)
  call   <strncpy@plt>
  mov    0xc(%rsp),%edx
  movzbl (%r14),%eax
  add    %rdx,%rbp
  test   %al,%al
  jne    L170
  nopl   0x0(%rax)
L129:
  movb   $0x0,0x0(%rbp)
  mov    0x118(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L135
  add    $0x128,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L270:
  mov    %r12,%r14
  jmp    L202
L196:
  cmp    $0x1,%ebx
  seta   %r12b
  jmp    L157
  nopl   0x0(%rax)
L222:
  lea    -0x1(%rbx),%edx
  xor    %r12d,%r12d
  mov    $0x1,%ebx
  jmp    L136
  nopl   (%rax)
L24:
  movzbl 0x2(%r14),%eax
  lea    0x2(%r14),%r12
  mov    %r12,%r14
  test   %al,%al
  je     L72
  cmp    $0x7d,%al
  jne    L85
  jmp    L72
  cs nopw 0x0(%rax,%rax,1)
L234:
  cmp    $0x7d,%al
  je     L144
L85:
  movzbl 0x1(%r14),%eax
  add    $0x1,%r14
  test   %al,%al
  jne    L234
L144:
  mov    %r14,%rdx
  mov    $0xff,%eax
  sub    %r12,%rdx
  cmp    %rax,%rdx
  cmovg  %rax,%rdx
  jmp    L56
  nopl   0x0(%rax,%rax,1)
L155:
  mov    %r15,%rdx
  mov    $0xff,%eax
  mov    %r15,%r14
  sub    %r12,%rdx
  cmp    %rax,%rdx
  cmovg  %rax,%rdx
  jmp    L56
L72:
  xor    %edx,%edx
  jmp    L56
L184:
  mov    %r12,%r14
  xor    %edx,%edx
  jmp    L56
L135:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void variable_substitute(const char *s, char *dest, unsigned int n) {
  while (*s && n > 1) {
    if (*s == '$') {
      s++;
      if (*s != '$') {
        char buf[256];
        const char *a, *var;
        unsigned int len;
        if (*s == '{') {
          s++;
          a = s;
          while (*s && *s != '}')
            s++;
        } else {
          a = s;
          while (*s && (isalnum((int)*s) || *s == '_'))
            s++;
        }
        len = (s - a > 255) ? 255 : (s - a);
        strncpy(buf, a, len);
        buf[len] = '\0';
        if (*s == '}')
          s++;
        var = getenv(buf);
        if (var) {
          len = strlen(var);
          if (len >= n)
            len = n - 1;
          strncpy(dest, var, len);
          dest += len;
          n -= len;
        }
        continue;
      }
    }
    *dest++ = *s++;
    n--;
  }
  *dest = '\0';
}
```