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

```asm
<in_flush>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x958,%rsp
  mov    %edi,%ebx
  mov    %esi,%ebp
  mov    %edx,%r12d
  mov    %rcx,%r14
  mov    %r8,%r15
  mov    %fs:0x28,%rax
  mov    %rax,0x948(%rsp)
  xor    %eax,%eax
  mov    %r8,%rdi
  call   <write_type_count@plt>
  test   %ebp,%ebp
  je     L92
  lea    -0x1(%r12),%r13d
  lea    0x10(%rsp),%rax
  mov    %rax,0x8(%rsp)
  test   %r12d,%r12d
  jne    L63
  jmp    L36
L92:
  test   %r12d,%r12d
  je     L36
  lea    0x10(%rsp),%r13
L79:
  mov    $0x930,%ebp
  cmp    %ebp,%r12d
  cmovbe %r12d,%ebp
  mov    %r14,%rcx
  mov    %ebp,%edx
  mov    $0x1,%esi
  mov    %r13,%rdi
  call   <fread@plt>
  mov    %ebp,%edx
  mov    %r13,%rsi
  mov    %ebx,%edi
  call   <edc_computeblock@plt>
  mov    %eax,%ebx
  mov    %r15,%rcx
  mov    %ebp,%edx
  mov    $0x1,%esi
  mov    %r13,%rdi
  call   <fwrite@plt>
  sub    %ebp,%r12d
  mov    %r14,%rdi
  call   <ftell@plt>
  mov    %eax,%edi
  call   <setcounter_encode@plt>
  test   %r12d,%r12d
  jne    L79
L36:
  mov    0x948(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L116
  mov    %ebx,%eax
  add    $0x958,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L110:
  mov    %r14,%rcx
  mov    $0x920,%edx
  mov    $0x1,%esi
  mov    0x8(%rsp),%r12
  mov    %r12,%rdi
  call   <fread@plt>
  mov    $0x920,%edx
  mov    %r12,%rsi
  mov    %ebx,%edi
  call   <edc_computeblock@plt>
  mov    %eax,%ebx
  lea    0x14(%rsp),%rdi
  mov    %r15,%rcx
  mov    $0x804,%edx
  mov    $0x1,%esi
  call   <fwrite@plt>
  mov    %r14,%rdi
  call   <ftell@plt>
  mov    %eax,%edi
  call   <setcounter_encode@plt>
L115:
  sub    $0x1,%r13d
  cmp    $0xffffffff,%r13d
  je     L36
L63:
  cmp    $0x2,%ebp
  je     L110
  cmp    $0x3,%ebp
  je     L52
  cmp    $0x1,%ebp
  jne    L115
  mov    %r14,%rcx
  mov    $0x930,%edx
  mov    $0x1,%esi
  mov    0x8(%rsp),%r12
  mov    %r12,%rdi
  call   <fread@plt>
  mov    $0x930,%edx
  mov    %r12,%rsi
  mov    %ebx,%edi
  call   <edc_computeblock@plt>
  mov    %eax,%ebx
  lea    0x1c(%rsp),%rdi
  mov    %r15,%rcx
  mov    $0x3,%edx
  mov    $0x1,%esi
  call   <fwrite@plt>
  lea    0x20(%rsp),%rdi
  mov    %r15,%rcx
  mov    $0x800,%edx
  mov    $0x1,%esi
  call   <fwrite@plt>
  mov    %r14,%rdi
  call   <ftell@plt>
  mov    %eax,%edi
  call   <setcounter_encode@plt>
  jmp    L115
L52:
  mov    %r14,%rcx
  mov    $0x920,%edx
  mov    $0x1,%esi
  mov    0x8(%rsp),%r12
  mov    %r12,%rdi
  call   <fread@plt>
  mov    $0x920,%edx
  mov    %r12,%rsi
  mov    %ebx,%edi
  call   <edc_computeblock@plt>
  mov    %eax,%ebx
  lea    0x14(%rsp),%rdi
  mov    %r15,%rcx
  mov    $0x918,%edx
  mov    $0x1,%esi
  call   <fwrite@plt>
  mov    %r14,%rdi
  call   <ftell@plt>
  mov    %eax,%edi
  call   <setcounter_encode@plt>
  jmp    L115
L116:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
unsigned in_flush(unsigned edc, unsigned type, unsigned count, FILE *in, FILE *out) {
  unsigned char buf[2352];
  write_type_count(out, type, count);
  if (!type) {
    while (count) {
      unsigned b = count;
      if (b > 2352)
        b = 2352;
      fread(buf, 1, b, in);
      edc = edc_computeblock(edc, buf, b);
      fwrite(buf, 1, b, out);
      count -= b;
      setcounter_encode(ftell(in));
    }
    return edc;
  }
  while (count--) {
    switch (type) {
    case 1:
      fread(buf, 1, 2352, in);
      edc = edc_computeblock(edc, buf, 2352);
      fwrite(buf + 0x00C, 1, 0x003, out);
      fwrite(buf + 0x010, 1, 0x800, out);
      setcounter_encode(ftell(in));
      break;
    case 2:
      fread(buf, 1, 2336, in);
      edc = edc_computeblock(edc, buf, 2336);
      fwrite(buf + 0x004, 1, 0x804, out);
      setcounter_encode(ftell(in));
      break;
    case 3:
      fread(buf, 1, 2336, in);
      edc = edc_computeblock(edc, buf, 2336);
      fwrite(buf + 0x004, 1, 0x918, out);
      setcounter_encode(ftell(in));
      break;
    }
  }
  return edc;
}
```