user: Demonstrate the C code that generates the assembly output below:

```asm
<string_envformat>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x160,%rsp
  mov    %rdi,-0x158(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x158(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    $0x200,%eax
  cltq
  mov    %rax,-0x140(%rbp)
  mov    -0x140(%rbp),%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x138(%rbp)
  mov    -0x138(%rbp),%rax
  mov    %rax,-0x150(%rbp)
  mov    -0x140(%rbp),%rax
  lea    -0x1(%rax),%rdx
  mov    -0x150(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x130(%rbp)
  movq   $0x0,-0x148(%rbp)
  jmp    L97
L4:
  mov    -0x150(%rbp),%rax
  cmp    -0x130(%rbp),%rax
  jae    L19
  mov    -0x158(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x24,%al
  jne    L103
  addq   $0x1,-0x158(%rbp)
  mov    -0x158(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x24,%al
  jne    L91
  mov    -0x150(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x150(%rbp)
  movb   $0x24,(%rax)
  jmp    L103
L91:
  lea    -0x110(%rbp),%rax
  mov    %rax,-0x148(%rbp)
  mov    -0x158(%rbp),%rax
  movzbl (%rax),%edx
  mov    -0x148(%rbp),%rax
  mov    %dl,(%rax)
L103:
  cmpq   $0x0,-0x148(%rbp)
  je     L70
  mov    -0x158(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <isalnum@plt>
  test   %rax,%rax
  je     L96
  mov    -0x148(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x148(%rbp)
  mov    -0x158(%rbp),%rdx
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
  jmp    L44
L96:
  mov    -0x148(%rbp),%rax
  movb   $0x0,(%rax)
  lea    -0x110(%rbp),%rax
  mov    %rax,%rdi
  call   <getenv@plt>
  mov    %rax,-0x120(%rbp)
  mov    -0x130(%rbp),%rax
  sub    -0x150(%rbp),%rax
  mov    %eax,%edx
  mov    -0x120(%rbp),%rcx
  mov    -0x150(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x120(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cltq
  mov    %rax,-0x118(%rbp)
  mov    -0x150(%rbp),%rdx
  mov    -0x118(%rbp),%rax
  add    %rdx,%rax
  cmp    %rax,-0x130(%rbp)
  jb     L78
  mov    -0x118(%rbp),%rax
  add    %rax,-0x150(%rbp)
  movq   $0x0,-0x148(%rbp)
  mov    -0x150(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x150(%rbp)
  mov    -0x158(%rbp),%rdx
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
  jmp    L44
L70:
  mov    -0x150(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x150(%rbp)
  mov    -0x158(%rbp),%rdx
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
L44:
  addq   $0x1,-0x158(%rbp)
L97:
  mov    -0x158(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L4
  cmpq   $0x0,-0x148(%rbp)
  je     L145
  mov    -0x148(%rbp),%rax
  movb   $0x0,(%rax)
  lea    -0x110(%rbp),%rax
  mov    %rax,%rdi
  call   <getenv@plt>
  mov    %rax,-0x128(%rbp)
  mov    -0x130(%rbp),%rax
  sub    -0x150(%rbp),%rax
  mov    %eax,%edx
  mov    -0x128(%rbp),%rcx
  mov    -0x150(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x128(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cltq
  add    %rax,-0x150(%rbp)
  jmp    L139
L19:
  nop
  jmp    L139
L78:
  nop
  jmp    L139
L145:
  nop
L139:
  mov    -0x150(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x138(%rbp),%rax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L127
  call   <__stack_chk_fail@plt>
L127:
  leave
  ret
```

assistant: ```c
char *string_envformat(const char *str) {
  size_t ressize = strlen(str) + 512;
  char *begin_res = malloc(ressize);
  char *res = begin_res;
  char *resend = res + ressize - 1;
  char tvarname[256];
  char *varname = NULL;
  while (*str) {
    if (res >= resend) {
      goto end;
    }
    if (*str == '$') {
      str++;
      if (*str == '$') {
        *res++ = '$';
      } else {
        varname = tvarname;
        *varname = *str;
      }
    }
    if (varname) {
      if (isalnum(*str))
        *varname++ = *str;
      else {
        *varname = 0;
        char *env = getenv(tvarname);
        strncpy(res, env, resend - res);
        size_t lenv = strlen(env);
        if (res + lenv > resend)
          goto end;
        res += lenv;
        varname = NULL;
        *res++ = *str;
      }
    } else
      *res++ = *str;
    str++;
  }
  if (varname) {
    *varname = 0;
    char *env = getenv(tvarname);
    strncpy(res, env, resend - res);
    res += strlen(env);
  }
end:
  *res = 0;
  return begin_res;
}
```