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

```asm
<reg_sub_g>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0xa0,%rsp
  mov    %rdi,-0x78(%rbp)
  mov    %rsi,-0x80(%rbp)
  mov    %edx,-0x84(%rbp)
  mov    %rcx,-0x90(%rbp)
  mov    %r8,-0x98(%rbp)
  mov    %r9,-0xa0(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x90(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x84(%rbp),%edx
  mov    -0x80(%rbp),%rcx
  lea    -0x6c(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <regcomp@plt>
  mov    D8(%rip),%rdx
  mov    %eax,(%rdx)
  mov    D8(%rip),%rax
  mov    (%rax),%eax
  test   %eax,%eax
  je     L29
  mov    $0x0,%eax
  jmp    L86
L29:
  mov    -0x78(%rbp),%rax
  mov    %rax,-0x50(%rbp)
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,-0x48(%rbp)
  mov    -0xa0(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,-0x40(%rbp)
  mov    -0x50(%rbp),%rax
  mov    %rax,-0x68(%rbp)
  movq   $0x0,-0x60(%rbp)
  movq   $0xffffffffffffffff,-0x58(%rbp)
  jmp    L72
L51:
  mov    -0x30(%rbp),%rax
  test   %rax,%rax
  jne    L24
  mov    -0x28(%rbp),%rax
  cmp    %rax,-0x48(%rbp)
  jne    L24
  mov    -0x90(%rbp),%rdx
  mov    -0x60(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x40(%rbp),%rdx
  mov    -0xa0(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <strncpy@plt>
  mov    -0x40(%rbp),%rdx
  mov    -0x60(%rbp),%rax
  add    %rax,%rdx
  mov    -0x90(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  mov    -0x90(%rbp),%rax
  jmp    L86
L24:
  mov    -0x30(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  cmp    %rax,%rdx
  jne    L67
  mov    -0x30(%rbp),%rax
  test   %rax,%rax
  jne    L104
  mov    -0x40(%rbp),%rdx
  mov    -0xa0(%rbp),%rcx
  mov    -0x90(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x90(%rbp),%rdx
  mov    -0x40(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x48(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <strncpy@plt>
  mov    -0x40(%rbp),%rdx
  mov    -0x48(%rbp),%rax
  add    %rax,%rdx
  mov    -0x90(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  jmp    L12
L104:
  mov    -0x30(%rbp),%rax
  cmp    %rax,-0x48(%rbp)
  jne    L16
  mov    -0x48(%rbp),%rdx
  mov    -0x50(%rbp),%rcx
  mov    -0x90(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x90(%rbp),%rdx
  mov    -0x48(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x40(%rbp),%rdx
  mov    -0xa0(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <strncpy@plt>
  mov    -0x40(%rbp),%rdx
  mov    -0x48(%rbp),%rax
  add    %rax,%rdx
  mov    -0x90(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  jmp    L12
L16:
  mov    -0x50(%rbp),%rax
  jmp    L86
L67:
  mov    -0x30(%rbp),%rax
  cmp    $0xffffffffffffffff,%rax
  jne    L33
  mov    -0x90(%rbp),%rax
  jmp    L86
L33:
  mov    -0x30(%rbp),%rdx
  mov    -0x90(%rbp),%rcx
  mov    -0x60(%rbp),%rax
  add    %rax,%rcx
  mov    -0x68(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <strncpy@plt>
  mov    -0x30(%rbp),%rax
  add    %rax,-0x60(%rbp)
  mov    -0x90(%rbp),%rdx
  mov    -0x60(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x40(%rbp),%rdx
  mov    -0xa0(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <strncpy@plt>
  mov    -0x40(%rbp),%rax
  add    %rax,-0x60(%rbp)
  mov    -0x28(%rbp),%rax
  add    %rax,-0x68(%rbp)
  mov    -0x28(%rbp),%rax
  mov    %rax,-0x58(%rbp)
L72:
  lea    -0x30(%rbp),%rdx
  mov    -0x68(%rbp),%rsi
  lea    -0x6c(%rbp),%rax
  mov    $0x0,%r8d
  mov    %rdx,%rcx
  mov    $0x1,%edx
  mov    %rax,%rdi
  call   <regexec@plt>
  test   %eax,%eax
  je     L51
L12:
  mov    -0x68(%rbp),%rax
  cmp    -0x50(%rbp),%rax
  je     L162
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  sub    -0x58(%rbp),%rax
  mov    %rax,-0x38(%rbp)
  mov    -0x90(%rbp),%rdx
  mov    -0x60(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x38(%rbp),%rdx
  mov    -0x68(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <strncpy@plt>
  mov    -0x38(%rbp),%rax
  add    %rax,-0x60(%rbp)
  mov    -0x90(%rbp),%rdx
  mov    -0x60(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  mov    -0x90(%rbp),%rax
  jmp    L86
L162:
  mov    -0x50(%rbp),%rax
L86:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L116
  call   <__stack_chk_fail@plt>
L116:
  leave
  ret
```

assistant: ```c
char *reg_sub_g(char *subject, char *pattern, int cflags, char *output, size_t max_size, char *rep) {
  regex_t preg;
  output[0] = 0x0;
  if ((errno = regcomp(&preg, pattern, cflags))) {
    return NULL;
  }
  char *rs_p = subject;
  size_t o_l = strlen(rs_p);
  size_t rep_l = strlen(rep);
  regmatch_t rm[2];
  char *m_p = rs_p;
  size_t rs_w = 0;
  regoff_t r_eo = -1;
  while (!regexec(&preg, m_p, 1, rm, 0)) {
    if (rm[0].rm_so == 0 && rm[0].rm_eo == o_l) {
      strncpy(&output[rs_w], rep, rep_l);
      output[rep_l + rs_w] = 0x0;
      return output;
    }
    if (rm[0].rm_so == rm[0].rm_eo) {
      if (!rm[0].rm_so) {
        strncpy(output, rep, rep_l);
        strncpy(&output[rep_l], rs_p, o_l);
        output[rep_l + o_l] = 0x0;
      } else if (rm[0].rm_so == o_l) {
        strncpy(output, rs_p, o_l);
        strncpy(&output[o_l], rep, rep_l);
        output[rep_l + o_l] = 0x0;
      } else {
        return rs_p;
      }
      break;
    }
    if (rm[0].rm_so == (regoff_t)-1) {
      return output;
    }
    strncpy(&output[rs_w], m_p, rm[0].rm_so);
    rs_w += (size_t)rm[0].rm_so;
    strncpy(&output[rs_w], rep, rep_l);
    rs_w += rep_l;
    m_p = &m_p[rm[0].rm_eo];
    r_eo = rm[0].rm_eo;
  }
  if (m_p != rs_p) {
    size_t fw_l = strlen(rs_p) - r_eo;
    strncpy(&output[rs_w], m_p, fw_l);
    rs_w += fw_l;
    output[rs_w] = 0x0;
  } else {
    return rs_p;
  }
  return output;
}
```