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

```asm
<Mx1_rewrap>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x138,%rsp
  mov    %rdi,0x18(%rsp)
  mov    %rsi,%r12
  mov    %rdx,%r13
  mov    %rcx,0x10(%rsp)
  mov    %r8,%rbx
  mov    %r9,(%rsp)
  mov    0x170(%rsp),%r14
  mov    %fs:0x28,%rax
  mov    %rax,0x128(%rsp)
  xor    %eax,%eax
  mov    (%rsi),%rax
  mov    %rax,0x8(%rsp)
  mov    (%rdx),%r15
  mov    $0x7d,%esi
  mov    %rax,%rdi
  call   <strchr@plt>
  test   %rax,%rax
  je     L97
  mov    %rax,%rbp
  mov    0x8(%rsp),%rsi
  sub    %rsi,%rbp
  testb  $0x2,0x178(%rsp)
  jne    L48
  mov    %ebp,%ebx
  test   %ebp,%ebp
  jg     L53
L28:
  mov    %r15,%rdx
  sub    0x10(%rsp),%rdx
  movslq %ebx,%rax
  add    %rdx,%rax
  mov    %rax,0x8(%rsp)
  mov    (%rsp),%rdi
  call   <strlen@plt>
  cltq
  add    0x8(%rsp),%rax
  mov    %rax,0x8(%rsp)
  mov    %r14,%rdi
  call   <strlen@plt>
  cltq
  add    0x8(%rsp),%rax
  cmp    $0xff,%rax
  jg     L118
  mov    (%rsp),%rsi
  mov    %r15,%rdi
  call   <strcpy@plt>
  mov    (%rsp),%rdi
  call   <strlen@plt>
  cltq
  add    %rax,%r15
  test   %ebx,%ebx
  jg     L102
L64:
  movslq %ebx,%rbx
  add    %r15,%rbx
  mov    %r14,%rsi
  mov    %rbx,%rdi
  call   <strcpy@plt>
  mov    %r14,%rdi
  call   <strlen@plt>
  add    %rbp,(%r12)
  cltq
  add    %rax,%rbx
  mov    %rbx,0x0(%r13)
  mov    $0x1,%eax
L19:
  mov    0x128(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L6
  add    $0x138,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L97:
  lea    0x20(%rsp),%rbp
  mov    %rbx,%rdx
  lea    D17(%rip),%rsi
  mov    %rbp,%rdi
  call   <sprintf@plt>
  mov    $0x0,%edx
  mov    %rbp,%rsi
  mov    0x18(%rsp),%rdi
  call   <Mx1_report_error@plt>
  mov    $0xffffffff,%eax
  jmp    L19
L53:
  lea    0x20(%rsp),%rdx
  mov    $0x1,%r9d
  mov    %ebp,%r8d
  mov    $0x0,%ecx
  mov    0x18(%rsp),%rdi
  call   <Mx1_substitute@plt>
  test   %eax,%eax
  jle    L19
  lea    0x20(%rsp),%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  jmp    L28
L48:
  mov    $0x0,%ebx
  jmp    L28
L118:
  mov    $0x0,%edx
  lea    D18(%rip),%rsi
  mov    0x18(%rsp),%rdi
  call   <Mx1_report_error@plt>
  mov    $0xffffffff,%eax
  jmp    L19
L102:
  lea    0x20(%rsp),%rsi
  mov    %ebx,%edx
  mov    %r15,%rdi
  call   <strncpy@plt>
  jmp    L64
L6:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: data_label: D17
type_guessed: string
name: unpack_data
arguments: data_label: D18
type_guessed: string

tool: D17: No closing bracket found for '%s'

tool: D18: Line length overflow while text substitution

assistant: ```c
int Mx1_rewrap(struct Mx1 *m, char **read_pt, char **write_pt, char *write_base, char *envelope, char *front, char *back, int flag) {
  char *rpt, *wpt, *ept, content[256], msg[256];
  int l, ret;
  rpt = *read_pt;
  wpt = *write_pt;
  ept = strchr(rpt, '}');
  if (ept == NULL) {
    sprintf(msg, "No closing bracket found for '%s'", envelope);
    Mx1_report_error(m, msg, 0);
    return (-1);
  }
  l = ept - rpt;
  if (flag & 2)
    l = 0;
  if (l > 0) {
    ret = Mx1_substitute(m, rpt, content, 0, l, 1);
    if (ret <= 0)
      return (ret);
    l = strlen(content);
  }
  if ((wpt - write_base) + l + strlen(front) + strlen(back) > 255) {
    Mx1_report_error(m, "Line length overflow while text substitution", 0);
    return (-1);
  }
  strcpy(wpt, front);
  wpt += strlen(front);
  if (l > 0)
    strncpy(wpt, content, l);
  wpt += l;
  strcpy(wpt, back);
  wpt += strlen(back);
  (*read_pt) += ept - rpt;
  (*write_pt) = wpt;
  return (1);
}
```