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

```asm
<string_envformat>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x118,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x108(%rsp)
  xor    %eax,%eax
  call   <strlen@plt>
  lea    0x200(%rax),%ebp
  movslq %ebp,%rbp
  mov    %rbp,%rdi
  call   <malloc@plt>
  mov    %rax,%r13
  lea    -0x1(%rax,%rbp,1),%r12
  movzbl (%rbx),%eax
  mov    %r13,%rbp
  test   %al,%al
  je     L118
  cmp    %r12,%r13
  jae    L118
  xor    %r15d,%r15d
  mov    %rsp,%r14
  jmp    L38
  nopl   0x0(%rax,%rax,1)
L24:
  movsbl (%rbx),%edi
L34:
  test   %r15,%r15
  jne    L74
  mov    %dil,0x0(%rbp)
  mov    %rbx,%rax
  add    $0x1,%rbp
L145:
  movzbl 0x1(%rax),%eax
  add    $0x1,%rbx
  test   %al,%al
  je     L41
L36:
  cmp    %r12,%rbp
  jae    L118
L38:
  cmp    $0x24,%al
  jne    L24
  movsbl 0x1(%rbx),%edi
  lea    0x1(%rbx),%rax
  cmp    $0x24,%dil
  je     L117
  mov    %dil,(%rsp)
  mov    %rax,%rbx
  mov    %r14,%r15
L74:
  call   <isalnum@plt>
  test   %rax,%rax
  je     L42
  movzbl (%rbx),%eax
  add    $0x1,%r15
  mov    %al,-0x1(%r15)
  mov    %rbx,%rax
  add    $0x1,%rbx
  movzbl 0x1(%rax),%eax
  test   %al,%al
  jne    L36
L41:
  test   %r15,%r15
  je     L118
  movb   $0x0,(%r15)
  mov    %rsp,%rdi
  call   <getenv@plt>
  mov    %r12d,%edx
  mov    %rbp,%rdi
  sub    %ebp,%edx
  mov    %rax,%r14
  mov    %rax,%rsi
  call   <strncpy@plt>
  mov    %r14,%rdi
  call   <strlen@plt>
  cltq
  add    %rax,%rbp
L118:
  movb   $0x0,0x0(%rbp)
  mov    0x108(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L85
  add    $0x118,%rsp
  mov    %r13,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L42:
  movb   $0x0,(%r15)
  mov    %r14,%rdi
  call   <getenv@plt>
  mov    %r12d,%edx
  mov    %rbp,%rdi
  mov    %rax,%r15
  sub    %ebp,%edx
  mov    %rax,%rsi
  call   <strncpy@plt>
  mov    %r15,%rdi
  call   <strlen@plt>
  cltq
  add    %rbp,%rax
  cmp    %r12,%rax
  ja     L118
  movzbl (%rbx),%edx
  lea    0x1(%rax),%rbp
  xor    %r15d,%r15d
  mov    %dl,(%rax)
  mov    %rbx,%rax
  jmp    L145
  nopl   (%rax)
L117:
  movb   $0x24,0x0(%rbp)
  mov    %rax,%rbx
  add    $0x1,%rbp
  jmp    L34
L85:
  call   <__stack_chk_fail@plt>
```

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;
}
```