user: Please show me the C implementation that matches the assembly code listed below:

```asm
<construct_include_directive_marker>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %rdi,%r13
  mov    %rsi,%rdi
  push   %r12
  mov    %rsi,%r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  call   <strlen@plt>
  lea    0x12(%rax),%edi
  mov    %rax,%rbx
  mov    %eax,%r15d
  call   <malloc@plt>
  mov    %rax,0x0(%r13)
  mov    %rax,%rcx
  movzbl (%r12),%eax
  test   %ebx,%ebx
  jle    L134
  test   %al,%al
  je     L134
  mov    $0x1,%ebx
  xor    %r8d,%r8d
  xor    %ebp,%ebp
  xor    %r14d,%r14d
  xor    %esi,%esi
  mov    $0x1,%edx
  lea    D8(%rip),%r9
  jmp    L121
  nopw   0x0(%rax,%rax,1)
L168:
  mov    %al,(%rdi)
  mov    0x0(%r13),%rcx
  mov    %edx,%r14d
  movslq %edx,%rsi
  xor    %ebp,%ebp
  add    $0x1,%edx
L160:
  movzbl (%r12,%rbx,1),%eax
  test   %al,%al
  setne  %r10b
  cmp    %ebx,%r15d
  setg   %dil
  add    $0x1,%rbx
  test   %dil,%r10b
  je     L96
L121:
  lea    (%rcx,%rsi,1),%rdi
  test   %ebp,%ebp
  jne    L168
  cmp    $0x40,%al
  je     L124
  jg     L39
  cmp    $0x25,%al
  je     L130
  cmp    $0x3f,%al
  jne    L52
L130:
  movb   $0x25,(%rdi)
  mov    0x0(%r13),%rax
  movslq %edx,%rdx
  add    $0x1,%r8d
  add    $0x2,%r14d
  movb   $0x73,(%rax,%rdx,1)
  cmp    $0x3,%r8d
  jg     L115
  mov    0x0(%r13),%rcx
  movslq %r14d,%rsi
  lea    0x1(%r14),%edx
  jmp    L160
  nop
L39:
  cmp    $0x5c,%al
  jne    L52
  mov    $0x1,%ebp
  jmp    L160
  nopl   0x0(%rax,%rax,1)
L124:
  movb   $0x20,(%rdi)
  mov    %edx,%r14d
  movslq %edx,%rsi
  mov    0x0(%r13),%rcx
  add    $0x1,%edx
  jmp    L160
  nopl   (%rax)
L52:
  mov    %al,(%rdi)
  mov    %edx,%r14d
  movslq %edx,%rsi
  mov    0x0(%r13),%rcx
  add    $0x1,%edx
  jmp    L160
  nopl   0x0(%rax)
L96:
  add    %rsi,%rcx
  movslq %edx,%rdx
L77:
  movb   $0xa,(%rcx)
  mov    0x0(%r13),%rax
  movb   $0x0,(%rax,%rdx,1)
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L115:
  mov    %r9,%rdi
  mov    %r8d,0xc(%rsp)
  call   <bug@plt>
  mov    0x0(%r13),%rcx
  movslq %r14d,%rsi
  lea    0x1(%r14),%edx
  mov    0xc(%rsp),%r8d
  lea    D8(%rip),%r9
  jmp    L160
  nopl   0x0(%rax)
L134:
  mov    $0x1,%edx
  jmp    L77
```

tool_calls: name: read_data
arguments: label: D8
type: string

tool: D8: only 3 substitutions allowed in -includemarker

assistant: ```c
void construct_include_directive_marker(char **include_directive_marker, char *includemarker_input) {
  int len = (int)strlen(includemarker_input);
  char ch;
  int in_idx = 0, out_idx = 0;
  int quoted = 0, num_repl = 0;
  *include_directive_marker = malloc(len + 18);
  ch = *includemarker_input;
  while (ch != '\0' && in_idx < len) {
    if (quoted) {
      *(*include_directive_marker + out_idx) = ch;
      out_idx++;
      quoted = 0;
    } else {
      switch (ch) {
      case '\\':
        quoted = 1;
        break;
      case '@':
        *(*include_directive_marker + out_idx) = ' ';
        out_idx++;
        break;
      case '%':
      case '?':
        *(*include_directive_marker + out_idx) = '%';
        out_idx++;
        *(*include_directive_marker + out_idx) = 's';
        out_idx++;
        if (++num_repl > 3)
          bug("only 3 substitutions allowed in -includemarker");
        break;
      default:
        *(*include_directive_marker + out_idx) = ch;
        out_idx++;
      }
    }
    in_idx++;
    ch = *(includemarker_input + in_idx);
  }
  *(*include_directive_marker + out_idx) = '\n';
  out_idx++;
  *(*include_directive_marker + out_idx) = '\0';
}
```