user: 请将以下的汇编代码转换成C语言代码:

```asm
<reg_sub_g>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x68,%rsp
  mov    %rdi,%rbx
  mov    %rdi,0x18(%rsp)
  mov    %rcx,%r12
  mov    %r9,%r14
  mov    %fs:0x28,%rax
  mov    %rax,0x58(%rsp)
  xor    %eax,%eax
  movb   $0x0,(%rcx)
  lea    0x2c(%rsp),%rdi
  call   <regcomp@plt>
  mov    D1(%rip),%rdx
  mov    %eax,(%rdx)
  test   %eax,%eax
  jne    L22
  mov    %rbx,%rdi
  call   <strlen@plt>
  mov    %rax,0x10(%rsp)
  mov    %r14,%rdi
  call   <strlen@plt>
  mov    %rax,%r15
  mov    %rbx,%rbp
  mov    $0xffffffffffffffff,%r13
  mov    $0x0,%ebx
  lea    0x30(%rsp),%rax
  mov    %rax,0x8(%rsp)
  jmp    L86
L108:
  cmp    0x38(%rsp),%rdx
  je     L10
  cmp    $0xffffffffffffffff,%rdx
  je     L68
  lea    (%r12,%rbx,1),%rdi
  mov    %rbp,%rsi
  call   <strncpy@plt>
  add    0x30(%rsp),%rbx
  lea    (%r12,%rbx,1),%rdi
  mov    %r15,%rdx
  mov    %r14,%rsi
  call   <strncpy@plt>
  add    %r15,%rbx
  mov    0x38(%rsp),%r13
  add    %r13,%rbp
L86:
  lea    0x2c(%rsp),%rdi
  mov    $0x0,%r8d
  mov    0x8(%rsp),%rcx
  mov    $0x1,%edx
  mov    %rbp,%rsi
  call   <regexec@plt>
  test   %eax,%eax
  jne    L81
  mov    0x30(%rsp),%rdx
  test   %rdx,%rdx
  jne    L108
  mov    0x10(%rsp),%rax
  cmp    %rax,0x38(%rsp)
  jne    L108
  add    %r12,%rbx
  mov    %r15,%rdx
  mov    %r14,%rsi
  mov    %rbx,%rdi
  call   <strncpy@plt>
  movb   $0x0,(%rbx,%r15,1)
  mov    %r12,%rax
  jmp    L94
L10:
  test   %rdx,%rdx
  je     L115
  mov    0x18(%rsp),%rax
  cmp    0x10(%rsp),%rdx
  jne    L94
  mov    0x10(%rsp),%rdx
  mov    %rax,%rsi
  mov    %r12,%rdi
  call   <strncpy@plt>
  mov    0x10(%rsp),%rax
  add    %r12,%rax
  mov    %r15,%rdx
  mov    %r14,%rsi
  mov    %rax,%r14
  mov    %rax,%rdi
  call   <strncpy@plt>
  movb   $0x0,(%r14,%r15,1)
  jmp    L81
L115:
  mov    %r15,%rdx
  mov    %r14,%rsi
  mov    %r12,%rdi
  call   <strncpy@plt>
  lea    (%r12,%r15,1),%rdi
  mov    0x10(%rsp),%r14
  mov    %r14,%rdx
  mov    0x18(%rsp),%rsi
  call   <strncpy@plt>
  mov    %r14,%rax
  add    %r12,%rax
  movb   $0x0,(%rax,%r15,1)
L81:
  mov    0x18(%rsp),%rdi
  mov    %rdi,%rax
  cmp    %rdi,%rbp
  je     L94
  call   <strlen@plt>
  sub    %r13,%rax
  mov    %rax,%r14
  add    %r12,%rbx
  mov    %rax,%rdx
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <strncpy@plt>
  movb   $0x0,(%rbx,%r14,1)
  mov    %r12,%rax
L94:
  mov    0x58(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L120
  add    $0x68,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L22:
  mov    $0x0,%eax
  jmp    L94
L68:
  mov    %r12,%rax
  jmp    L94
L120:
  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;
}
```