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

```asm
<reg_sub_g>:
  endbr64
  push   %r15
  push   %r14
  mov    %r9,%r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %rcx,%rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x68,%rsp
  mov    %rdi,0x18(%rsp)
  lea    0x2c(%rsp),%r15
  mov    %r15,%rdi
  mov    %fs:0x28,%rax
  mov    %rax,0x58(%rsp)
  xor    %eax,%eax
  movb   $0x0,(%rcx)
  call   <regcomp@plt>
  mov    D5(%rip),%rdx
  mov    %eax,(%rdx)
  test   %eax,%eax
  jne    L105
  mov    %rbx,%rdi
  mov    %rbx,%r13
  xor    %ebx,%ebx
  call   <strlen@plt>
  mov    %r14,%rdi
  mov    %rax,0x10(%rsp)
  call   <strlen@plt>
  movq   $0xffffffffffffffff,0x8(%rsp)
  mov    %rax,%r12
  lea    0x30(%rsp),%rax
  mov    %rax,(%rsp)
  jmp    L112
  nopw   0x0(%rax,%rax,1)
L130:
  mov    0x30(%rsp),%rdx
  mov    0x38(%rsp),%rax
  test   %rdx,%rdx
  jne    L29
  cmp    0x10(%rsp),%rax
  je     L62
L29:
  cmp    %rax,%rdx
  je     L146
  cmp    $0xffffffffffffffff,%rdx
  je     L18
  lea    0x0(%rbp,%rbx,1),%rdi
  mov    %r13,%rsi
  call   <strncpy@plt>
  add    0x30(%rsp),%rbx
  mov    %r12,%rdx
  mov    %r14,%rsi
  lea    0x0(%rbp,%rbx,1),%rdi
  add    %r12,%rbx
  call   <strncpy@plt>
  mov    0x38(%rsp),%rax
  mov    %rax,0x8(%rsp)
  add    %rax,%r13
L112:
  mov    (%rsp),%rcx
  xor    %r8d,%r8d
  mov    $0x1,%edx
  mov    %r13,%rsi
  mov    %r15,%rdi
  call   <regexec@plt>
  test   %eax,%eax
  je     L130
L27:
  mov    0x18(%rsp),%rax
  cmp    %rax,%r13
  je     L168
  mov    %rax,%rdi
  add    %rbp,%rbx
  call   <strlen@plt>
  sub    0x8(%rsp),%rax
  mov    %r13,%rsi
  mov    %rbx,%rdi
  mov    %rax,%r12
  mov    %rax,%rdx
  call   <strncpy@plt>
  movb   $0x0,(%rbx,%r12,1)
  mov    %rbp,%rax
L122:
  mov    0x58(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L102
  add    $0x68,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L146:
  test   %rdx,%rdx
  je     L84
  cmp    0x10(%rsp),%rdx
  jne    L168
  mov    0x18(%rsp),%rsi
  mov    %rbp,%rdi
  mov    %rdx,(%rsp)
  call   <strncpy@plt>
  mov    (%rsp),%rdx
  mov    %r14,%rsi
  lea    0x0(%rbp,%rdx,1),%r15
  mov    %r12,%rdx
  mov    %r15,%rdi
  call   <strncpy@plt>
  movb   $0x0,(%r15,%r12,1)
  jmp    L27
  xchg   %ax,%ax
L18:
  mov    %rbp,%rax
  jmp    L122
  nopl   (%rax)
L168:
  mov    0x18(%rsp),%rax
  jmp    L122
L84:
  mov    %r14,%rsi
  mov    %r12,%rdx
  mov    %rbp,%rdi
  call   <strncpy@plt>
  mov    0x10(%rsp),%r14
  mov    0x18(%rsp),%rsi
  lea    0x0(%rbp,%r12,1),%rdi
  mov    %r14,%rdx
  call   <strncpy@plt>
  mov    %r14,%rax
  add    %rbp,%rax
  movb   $0x0,(%rax,%r12,1)
  jmp    L27
  nopl   0x0(%rax)
L105:
  xor    %eax,%eax
  jmp    L122
  nop
L62:
  add    %rbp,%rbx
  mov    %r12,%rdx
  mov    %r14,%rsi
  mov    %rbx,%rdi
  call   <strncpy@plt>
  movb   $0x0,(%rbx,%r12,1)
  mov    %rbp,%rax
  jmp    L122
L102:
  call   <__stack_chk_fail@plt>
```

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