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

```asm
<ConfigConvertStrWithResolvEnvToStr>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x68,%rsp
  mov    %rdi,-0x68(%rbp)
  mov    -0x68(%rbp),%rax
  mov    %rax,%rdi
  call   <strdup@plt>
  mov    %rax,-0x40(%rbp)
  cmpq   $0x0,-0x40(%rbp)
  jne    L75
  mov    $0x0,%eax
  jmp    L102
L75:
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,-0x48(%rbp)
  movq   $0x0,-0x50(%rbp)
  jmp    L173
L121:
  mov    -0x40(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x24,%al
  jne    L50
  movl   $0x0,-0x5c(%rbp)
  mov    -0x50(%rbp),%rax
  add    $0x1,%rax
  mov    %rax,-0x38(%rbp)
  mov    -0x40(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x7b,%al
  jne    L11
  movl   $0x1,-0x5c(%rbp)
  addq   $0x1,-0x50(%rbp)
  jmp    L11
L124:
  addq   $0x1,-0x50(%rbp)
  mov    -0x40(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x60,%al
  jle    L192
  mov    -0x40(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x7a,%al
  jle    L11
L192:
  mov    -0x40(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x40,%al
  jle    L55
  mov    -0x40(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x5a,%al
  jle    L11
L55:
  mov    -0x40(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  jle    L159
  mov    -0x40(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x39,%al
  jle    L11
L159:
  mov    -0x40(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x5f,%al
  jne    L44
L11:
  mov    -0x50(%rbp),%rax
  cmp    -0x48(%rbp),%rax
  jb     L124
  jmp    L145
L44:
  nop
L145:
  mov    -0x50(%rbp),%rax
  mov    %rax,-0x58(%rbp)
  mov    -0x58(%rbp),%rax
  sub    -0x38(%rbp),%rax
  add    $0x1,%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x30(%rbp)
  cmpq   $0x0,-0x30(%rbp)
  je     L50
  mov    -0x58(%rbp),%rax
  sub    -0x38(%rbp),%rax
  mov    -0x5c(%rbp),%edx
  movslq %edx,%rcx
  sub    %rcx,%rax
  mov    %rax,%rdx
  mov    -0x5c(%rbp),%eax
  movslq %eax,%rcx
  mov    -0x38(%rbp),%rax
  add    %rax,%rcx
  mov    -0x40(%rbp),%rax
  add    %rax,%rcx
  mov    -0x30(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x58(%rbp),%rax
  sub    -0x38(%rbp),%rax
  mov    -0x5c(%rbp),%edx
  movslq %edx,%rdx
  sub    %rdx,%rax
  mov    %rax,%rcx
  mov    -0x30(%rbp),%rax
  add    %rcx,%rax
  movb   $0x0,(%rax)
  cmpl   $0x1,-0x5c(%rbp)
  jne    L77
  mov    -0x58(%rbp),%rax
  add    $0x1,%rax
  cmp    %rax,-0x48(%rbp)
  jb     L77
  addq   $0x1,-0x58(%rbp)
L77:
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <getenv@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  je     L153
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  sub    -0x58(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    %rbx,%rax
  add    $0x1,%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  je     L153
  mov    -0x38(%rbp),%rax
  lea    -0x1(%rax),%rdx
  mov    -0x40(%rbp),%rcx
  mov    -0x18(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x38(%rbp),%rax
  lea    -0x1(%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  mov    -0x28(%rbp),%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  mov    -0x40(%rbp),%rdx
  mov    -0x58(%rbp),%rax
  add    %rax,%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,-0x40(%rbp)
  movq   $0x0,-0x50(%rbp)
  mov    -0x20(%rbp),%rax
  sub    $0x1,%rax
  mov    %rax,-0x48(%rbp)
L153:
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
L50:
  addq   $0x1,-0x50(%rbp)
L173:
  mov    -0x50(%rbp),%rax
  cmp    -0x48(%rbp),%rax
  jb     L121
  mov    -0x40(%rbp),%rax
L102:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

assistant: ```c
char *ConfigConvertStrWithResolvEnvToStr(const char *str) {
  size_t beg, end, i, max;
  char *env_var, *env_str, *new, *res;
  if ((res = strdup(str)) == NULL)
    return NULL;
  max = strlen(res);
  for (i = 0; i < max; i++)
    if (res[i] == '$') {
      int firstIsBlock = 0;
      beg = i + 1;
      if (res[beg] == '{') {
        firstIsBlock = 1;
        i++;
      }
      while (i < max) {
        i++;
        if (!((res[i] >= 'a' && res[i] <= 'z') || (res[i] >= 'A' && res[i] <= 'Z') || (res[i] >= '0' && res[i] <= '9') || (res[i] == '_')))
          break;
      }
      end = i;
      env_str = malloc(end - beg + 1);
      if (env_str != NULL) {
        strncpy(env_str, res + beg + firstIsBlock, end - beg - firstIsBlock);
        env_str[end - beg - firstIsBlock] = '\0';
        if (firstIsBlock == 1 && (end + 1) <= max)
          end++;
        if ((env_var = getenv(env_str))) {
          size_t len;
          len = strlen(res) - (end - beg) + strlen(env_var) + 1;
          new = malloc(len);
          if (new != NULL) {
            strncpy(new, res, beg - 1);
            new[beg - 1] = '\0';
            strcat(new, env_var);
            strcat(new, res + end);
            free(res);
            res = new;
            i = 0;
            max = len - 1;
          }
        }
        free(env_str);
      }
    }
  return (res);
}
```