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

```asm
<compute_fold_length>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%r15
  mov    %rdi,(%rsp)
  mov    %esi,%r13d
  mov    %edx,%r12d
  mov    %ecx,%ebp
  mov    %r8d,%ebx
  cmp    %ecx,%edx
  setg   %dil
  movzbl %dil,%edi
  call   <assert@plt>
  lea    (%r12,%rbp,1),%eax
  mov    %r13d,%r9d
  cmp    %r13d,%eax
  jge    L13
  mov    %ebp,%r10d
  not    %r10d
  lea    0x1(%rbp),%eax
  mov    %r12d,%r9d
  sub    %eax,%r9d
  movslq %r9d,%rax
  lea    (%r15,%rax,8),%rax
  mov    %rax,0x8(%rsp)
  mov    (%rax),%rax
  cmp    $0x20,%rax
  sete   %dl
  cmp    $0x9,%rax
  sete   %al
  or     %eax,%edx
  movzbl %dl,%edx
  mov    %ebp,%ecx
  neg    %ecx
  test   %ebp,%ebp
  je     L77
  movslq %ecx,%rcx
  movslq %r12d,%rax
  lea    (%r15,%rax,8),%r14
  mov    $0x0,%esi
  mov    $0x0,%r15d
  jmp    L21
L156:
  xor    $0x1,%eax
  movzbl %al,%eax
  lea    (%rax,%r8,2),%r13d
L38:
  cmp    %esi,%r13d
  jl     L126
  mov    %edi,%r10d
  mov    %r13d,%esi
L126:
  add    $0x1,%rcx
  test   %ecx,%ecx
  je     L202
L21:
  mov    %ecx,%edi
  mov    (%r14,%rcx,8),%r11
  cmp    $0x20,%r11
  sete   %al
  cmp    $0x9,%r11
  sete   %r8b
  or     %r8d,%eax
  mov    %edx,%r8d
  movzbl %al,%edx
  test   %ebx,%ebx
  jne    L156
  mov    %r15d,%r13d
  cmp    $0x3b,%r11
  je     L38
  jmp    L156
L202:
  test   %ebp,%ebp
  js     L216
L193:
  movslq %r12d,%rax
  mov    (%rsp),%rdi
  lea    (%rdi,%rax,8),%r14
  mov    $0x0,%ecx
  mov    $0x0,%r15d
  jmp    L225
L77:
  mov    %ebp,%esi
  jmp    L193
L175:
  xor    $0x1,%eax
  movzbl %al,%eax
  lea    (%rax,%rdi,2),%r13d
  cmp    $0x3,%r13d
  jne    L8
  mov    %r11d,%r10d
L216:
  test   %esi,%esi
  jne    L155
  mov    0x8(%rsp),%rax
  test   %r9d,%r9d
  jle    L13
L118:
  cmpq   $0x3b,(%rax)
  jne    L13
  sub    $0x8,%rax
  sub    $0x1,%r9d
  jne    L118
  jmp    L13
L226:
  mov    %r11d,%r10d
  mov    %r13d,%esi
L146:
  add    $0x1,%rcx
  cmp    %ecx,%ebp
  jl     L216
L225:
  mov    %ecx,%r11d
  mov    (%r14,%rcx,8),%r8
  cmp    $0x20,%r8
  sete   %al
  cmp    $0x9,%r8
  sete   %dil
  or     %edi,%eax
  mov    %edx,%edi
  movzbl %al,%edx
  test   %ebx,%ebx
  jne    L175
  mov    %r15d,%r13d
  cmp    $0x3b,%r8
  jne    L175
L8:
  cmp    %esi,%r13d
  jg     L226
  jne    L146
  mov    %r10d,%eax
  neg    %eax
  cmp    %ecx,%eax
  cmovge %r11d,%r10d
  cmovge %r13d,%esi
  jmp    L146
L155:
  lea    (%r10,%r12,1),%r9d
L13:
  mov    %r9d,%eax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
ptrdiff_t compute_fold_length(UChar *fold_start, ptrdiff_t line_length, ptrdiff_t target_length, int window, int allow_folding_before_semi) {
  assert(target_length > window);
  if (line_length <= target_length + window) {
    return line_length;
  } else {
    int best_category = 0;
    int best_diff = -(window + 1);
    int diff;
    UChar this_char = fold_start[target_length - (window + 1)];
    int is_space = ((this_char == ((UChar)0x20)) || (this_char == ((UChar)0x09)));
    int was_space;
    for (diff = -window; diff; diff += 1) {
      int category;
      was_space = is_space;
      this_char = fold_start[target_length + diff];
      is_space = ((this_char == ((UChar)0x20)) || (this_char == ((UChar)0x09)));
      category = (allow_folding_before_semi || (this_char != ((UChar)0x3b))) ? ((was_space * 2) + !is_space) : 0;
      if (category >= best_category) {
        best_diff = diff;
        best_category = category;
      }
    }
    for (; diff <= window; diff += 1) {
      int category;
      was_space = is_space;
      this_char = fold_start[target_length + diff];
      is_space = ((this_char == ((UChar)0x20)) || (this_char == ((UChar)0x09)));
      category = (allow_folding_before_semi || (this_char != ((UChar)0x3b))) ? ((was_space * 2) + !is_space) : 0;
      if (category == 3) {
        best_diff = diff;
        break;
      } else if (category > best_category) {
        best_diff = diff;
        best_category = category;
      } else if ((category == best_category) && (diff <= -best_diff)) {
        best_diff = diff;
        best_category = category;
      }
    }
    if (best_category) {
      return target_length + best_diff;
    } else {
      ptrdiff_t best_length;
      for (best_length = target_length - (window + 1); best_length > 0; best_length -= 1) {
        if (fold_start[best_length] != ((UChar)0x3b)) {
          break;
        }
      }
      return best_length;
    }
  }
}
```