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

```asm
<writeParagraph>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x438,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x428(%rsp)
  xor    %eax,%eax
  movzbl (%rdi),%eax
  movl   $0x0,0xc(%rsp)
  test   %al,%al
  je     L203
  mov    %rdi,%r14
  mov    %rsi,%rbx
  mov    %edx,%ebp
  xor    %r12d,%r12d
  lea    D51(%rip),%r13
  jmp    L169
  nop
L173:
  cmp    $0x3c,%al
  je     L28
  cmp    $0x3e,%al
  je     L129
  test   %ebp,%ebp
  lea    0x1(%r14),%r15
  sete   %dl
  cmp    $0x5b,%al
  jne    L39
  test   %dl,%dl
  jne    L268
L39:
  cmp    $0x27,%al
  je     L122
  cmp    $0x2a,%al
  jne    L111
  test   %dl,%dl
  jne    L177
L111:
  cmp    $0x5c,%al
  je     L56
  movsbl %al,%edi
  mov    %rbx,%rsi
  mov    %r14,%r15
  call   <fputc@plt>
L167:
  movzbl 0x1(%r15),%eax
  lea    0x1(%r15),%r14
  test   %al,%al
  je     L203
L169:
  cmp    $0x26,%al
  jne    L173
  mov    %r14,%r15
  mov    %rbx,%rcx
  mov    $0x5,%edx
  mov    $0x1,%esi
  lea    D55(%rip),%rdi
  lea    0x1(%r15),%r14
  call   <fwrite@plt>
  movzbl 0x1(%r15),%eax
  test   %al,%al
  jne    L169
  nopl   0x0(%rax)
L203:
  mov    0x428(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L273
  add    $0x438,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L28:
  mov    %rbx,%rcx
  mov    $0x4,%edx
  mov    $0x1,%esi
  mov    %r14,%r15
  lea    D20(%rip),%rdi
  call   <fwrite@plt>
  jmp    L167
  nopl   0x0(%rax)
L122:
  mov    %rbx,%rcx
  test   %r12d,%r12d
  jne    L89
  mov    $0x12,%edx
  mov    $0x1,%esi
  lea    D41(%rip),%rdi
  mov    %r14,%r15
  call   <fwrite@plt>
  mov    $0x1,%r12d
  jmp    L167
  nopl   0x0(%rax)
L129:
  mov    %rbx,%rcx
  mov    $0x4,%edx
  mov    $0x1,%esi
  mov    %r14,%r15
  lea    D25(%rip),%rdi
  call   <fwrite@plt>
  jmp    L167
  nopl   0x0(%rax)
L56:
  movsbl 0x1(%r14),%edi
  mov    %rbx,%rsi
  call   <fputc@plt>
  jmp    L167
  nopw   0x0(%rax,%rax,1)
L89:
  mov    $0x7,%edx
  mov    $0x1,%esi
  mov    %r13,%rdi
  mov    %r14,%r15
  call   <fwrite@plt>
  xor    %r12d,%r12d
  jmp    L167
  nopl   (%rax)
L177:
  mov    0xc(%rsp),%eax
  mov    %rbx,%rcx
  test   %eax,%eax
  jne    L51
  mov    $0x13,%edx
  mov    $0x1,%esi
  lea    D44(%rip),%rdi
  mov    %r14,%r15
  call   <fwrite@plt>
  movl   $0x1,0xc(%rsp)
  jmp    L167
  nopl   (%rax)
L268:
  movzbl 0x1(%r14),%eax
  lea    0x20(%rsp),%r14
  mov    %r14,%rdx
  cmp    $0x5d,%al
  je     L53
  nopl   0x0(%rax)
L196:
  add    $0x1,%r15
  mov    %al,(%rdx)
  add    $0x1,%rdx
  movzbl (%r15),%eax
  cmp    $0x5d,%al
  jne    L196
L53:
  movb   $0x0,(%rdx)
  mov    $0x2e,%esi
  mov    %r14,%rdi
  call   <strchr@plt>
  test   %rax,%rax
  je     L167
  movb   $0x0,(%rax)
  lea    0x1c(%rsp),%rdx
  lea    0x1(%rax),%rdi
  lea    D59(%rip),%rsi
  call   <sscanf@plt>
  cmp    $0x1,%eax
  jne    L167
  mov    0x1c(%rsp),%ecx
  mov    %r14,%r8
  mov    %r14,%rdx
  mov    %rbx,%rdi
  lea    D52(%rip),%rsi
  xor    %eax,%eax
  mov    %ecx,%r9d
  call   <fprintf@plt>
  jmp    L167
  nopw   0x0(%rax,%rax,1)
L51:
  mov    $0x7,%edx
  mov    $0x1,%esi
  mov    %r13,%rdi
  mov    %r14,%r15
  call   <fwrite@plt>
  movl   $0x0,0xc(%rsp)
  jmp    L167
L273:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: label: D51
datatype: string
name: retrieve_data
arguments: label: D55
datatype: string
name: retrieve_data
arguments: label: D20
datatype: string
name: retrieve_data
arguments: label: D41
datatype: string
name: retrieve_data
arguments: label: D25
datatype: string
name: retrieve_data
arguments: label: D44
datatype: string
name: retrieve_data
arguments: label: D59
datatype: string
name: retrieve_data
arguments: label: D52
datatype: string

tool: D51: </span>

tool: D55: &amp;

tool: D20: &lt;

tool: D41: <span class="ref">

tool: D25: &gt;

tool: D44: <span class="emph">

tool: D59: %d

tool: D52: <a href="%s.%d.html">%s(%d)</a>

assistant: ```c
void writeParagraph(const char *scan, FILE *out, int codeMode) {
  int refState = 0;
  int emphState = 0;
  for (; *scan != 0; scan++) {
    if (*scan == '&') {
      fprintf(out, "&amp;");
    } else if (*scan == '<') {
      fprintf(out, "&lt;");
    } else if (*scan == '>') {
      fprintf(out, "&gt;");
    } else if ((*scan == '[') && (!codeMode)) {
      char buffer[1024];
      scan++;
      char *put = buffer;
      while (*scan != ']') {
        *put++ = *scan++;
      };
      *put = 0;
      char *dot = strchr(buffer, '.');
      if (dot == NULL)
        continue;
      *dot = 0;
      int chapter;
      if (sscanf(dot + 1, "%d", &chapter) != 1)
        continue;
      fprintf(out, "<a href=\"%s.%d.html\">%s(%d)</a>", buffer, chapter, buffer, chapter);
    } else if (*scan == '\'') {
      refState = !refState;
      if (refState) {
        fprintf(out, "<span class=\"ref\">");
      } else {
        fprintf(out, "</span>");
      };
    } else if ((*scan == '*') && (!codeMode)) {
      emphState = !emphState;
      if (emphState) {
        fprintf(out, "<span class=\"emph\">");
      } else {
        fprintf(out, "</span>");
      };
    } else if (*scan == '\\') {
      scan++;
      fprintf(out, "%c", *scan);
    } else {
      fprintf(out, "%c", *scan);
    };
  };
}
```