user: Demonstrate the C code that generates the assembly output below:

```asm
<escape_for_shell>:
  endbr64
  push   %r13
  push   %r12
  mov    %rsi,%r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x8,%rsp
  mov    (%rdi),%rdi
  test   %rdi,%rdi
  je     L35
  call   <free@plt>
L35:
  test   %r12,%r12
  je     L55
  mov    %r12,%rdi
  call   <strlen@plt>
  mov    %eax,%ebp
  test   %eax,%eax
  je     L55
  jle    L31
  lea    -0x1(%rbp),%edx
  mov    %r12,%rax
  mov    %rdx,%r13
  lea    0x1(%r12,%rdx,1),%rsi
  xor    %edx,%edx
  nopw   0x0(%rax,%rax,1)
L9:
  xor    %ecx,%ecx
  cmpb   $0x27,(%rax)
  sete   %cl
  add    $0x1,%rax
  add    %ecx,%edx
  cmp    %rax,%rsi
  jne    L9
  test   %edx,%edx
  je     L31
  lea    (%rdx,%rdx,2),%eax
  lea    0x3(%rbp,%rax,1),%edi
  call   <malloc@plt>
  xor    %edx,%edx
  mov    %rax,(%rbx)
  movzbl (%r12),%edi
  cmp    $0x27,%dil
  je     L38
  movb   $0x27,(%rax)
  movzbl (%r12),%edi
  mov    $0x1,%edx
  mov    (%rbx),%rax
L38:
  mov    %ebp,%r10d
  xor    %ecx,%ecx
  jmp    L83
  cs nopw 0x0(%rax,%rax,1)
L110:
  mov    %dil,(%r9)
  mov    %esi,%edx
L107:
  mov    (%rbx),%rax
  add    $0x1,%rcx
  mov    %rax,%rsi
  cmp    %rcx,%r10
  je     L2
L117:
  movzbl (%r12,%rcx,1),%edi
L83:
  movslq %edx,%r8
  lea    0x1(%rdx),%esi
  lea    (%rax,%r8,1),%r9
  cmp    $0x27,%dil
  jne    L110
  mov    %ecx,%edi
  test   %rcx,%rcx
  je     L79
  movslq %esi,%r8
  movb   $0x27,(%r9)
  mov    (%rbx),%rax
  mov    %r8,%rdx
  lea    0x1(%r8),%esi
L79:
  movb   $0x5c,(%rax,%r8,1)
  mov    (%rbx),%r8
  movslq %esi,%rsi
  lea    0x2(%rdx),%eax
  movb   $0x27,(%r8,%rsi,1)
  cmp    %edi,%r13d
  je     L57
  mov    (%rbx),%rsi
  cltq
  add    $0x1,%rcx
  add    $0x3,%edx
  movb   $0x27,(%rsi,%rax,1)
  mov    (%rbx),%rax
  mov    %rax,%rsi
  cmp    %rcx,%r10
  jne    L117
L2:
  movslq %ebp,%rbp
  cmpb   $0x27,-0x1(%r12,%rbp,1)
  je     L143
  movslq %edx,%rax
  add    $0x1,%edx
  movb   $0x27,(%rsi,%rax,1)
  mov    (%rbx),%rsi
L143:
  movslq %edx,%rdx
  movb   $0x0,(%rsi,%rdx,1)
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
  xchg   %ax,%ax
L55:
  lea    D14(%rip),%rdi
  call   <strdup@plt>
  mov    %rax,(%rbx)
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
  nopw   0x0(%rax,%rax,1)
L57:
  mov    %eax,%edx
  jmp    L107
  nopw   0x0(%rax,%rax,1)
L31:
  lea    0x3(%rbp),%edi
  call   <malloc@plt>
  mov    %r12,%rdx
  lea    D12(%rip),%rsi
  mov    %rax,(%rbx)
  add    $0x8,%rsp
  mov    %rax,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  jmp    10c0 <sprintf@plt>
```

tool_calls: name: disassemble_data
arguments: tag: D14
type_guessed: string
name: disassemble_data
arguments: tag: D12
type_guessed: string

tool: D14: ''

tool: D12: '%s'

assistant: ```c
void escape_for_shell(char **p, const char *text) {
  int len, i, c;
  if (*p)
    free(*p);
  if (!text || (len = strlen(text)) == 0) {
    *p = strdup("''");
    return;
  }
  for (i = 0, c = 0; i < len; i++)
    if (text[i] == '\'')
      c++;
  if (c == 0) {
    *p = (char *)malloc(len + 3);
    sprintf(*p, "'%s'", text);
    return;
  }
  *p = (char *)malloc(len + c * 3 + 3);
  c = 0;
  if (text[0] != '\'') {
    (*p)[c++] = '\'';
  }
  for (i = 0; i < len; i++) {
    if (text[i] == '\'') {
      if (i != 0)
        (*p)[c++] = '\'';
      (*p)[c++] = '\\';
      (*p)[c++] = '\'';
      if (i != len - 1)
        (*p)[c++] = '\'';
    } else {
      (*p)[c++] = text[i];
    }
  }
  if (text[len - 1] != '\'') {
    (*p)[c++] = '\'';
  }
  (*p)[c++] = '\0';
}
```