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

```asm
<in_flush>:
  endbr64
  push   %r15
  mov    %edx,%r15d
  push   %r14
  push   %r13
  mov    %r8,%r13
  push   %r12
  mov    %rcx,%r12
  push   %rbp
  mov    %edi,%ebp
  mov    %r8,%rdi
  push   %rbx
  mov    %esi,%ebx
  sub    $0x958,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x948(%rsp)
  xor    %eax,%eax
  call   <write_type_count@plt>
  test   %ebx,%ebx
  je     L124
  lea    -0x1(%r15),%r8d
  lea    0x10(%rsp),%r14
  test   %r15d,%r15d
  jne    L103
  jmp    L52
  nopl   (%rax)
L26:
  cmp    $0x1,%ebx
  je     L77
  sub    $0x1,%r8d
  jb     L52
L103:
  cmp    $0x2,%ebx
  je     L36
  cmp    $0x3,%ebx
  jne    L26
  mov    %r12,%rcx
  mov    $0x920,%edx
  mov    $0x1,%esi
  mov    %r14,%rdi
  mov    %r8d,0xc(%rsp)
  call   <fread@plt>
  mov    %ebp,%edi
  mov    $0x920,%edx
  mov    %r14,%rsi
  call   <edc_computeblock@plt>
  lea    0x14(%rsp),%rdi
  mov    %r13,%rcx
  mov    $0x918,%edx
  mov    %eax,%ebp
L111:
  mov    $0x1,%esi
  call   <fwrite@plt>
  mov    %r12,%rdi
  call   <ftell@plt>
  mov    %eax,%edi
  call   <setcounter_encode@plt>
  mov    0xc(%rsp),%r8d
  sub    $0x1,%r8d
  jae    L103
L52:
  mov    0x948(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L108
  add    $0x958,%rsp
  mov    %ebp,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L36:
  mov    %r12,%rcx
  mov    $0x920,%edx
  mov    $0x1,%esi
  mov    %r14,%rdi
  mov    %r8d,0xc(%rsp)
  call   <fread@plt>
  mov    %ebp,%edi
  mov    $0x920,%edx
  mov    %r14,%rsi
  call   <edc_computeblock@plt>
  lea    0x14(%rsp),%rdi
  mov    %r13,%rcx
  mov    $0x804,%edx
  mov    %eax,%ebp
  jmp    L111
  nopl   (%rax)
L77:
  mov    %r12,%rcx
  mov    $0x930,%edx
  mov    $0x1,%esi
  mov    %r14,%rdi
  mov    %r8d,0xc(%rsp)
  call   <fread@plt>
  mov    %ebp,%edi
  mov    $0x930,%edx
  mov    %r14,%rsi
  call   <edc_computeblock@plt>
  lea    0x1c(%rsp),%rdi
  mov    %r13,%rcx
  mov    $0x3,%edx
  mov    $0x1,%esi
  mov    %eax,%ebp
  call   <fwrite@plt>
  lea    0x20(%rsp),%rdi
  mov    %r13,%rcx
  mov    $0x800,%edx
  jmp    L111
  nopl   0x0(%rax)
L124:
  test   %r15d,%r15d
  je     L52
  lea    0x10(%rsp),%r14
  cs nopw 0x0(%rax,%rax,1)
L37:
  mov    $0x930,%ebx
  mov    %r12,%rcx
  mov    $0x1,%esi
  mov    %r14,%rdi
  cmp    %ebx,%r15d
  cmovbe %r15d,%ebx
  mov    %ebx,%edx
  sub    %ebx,%r15d
  call   <fread@plt>
  mov    %ebp,%edi
  mov    %ebx,%edx
  mov    %r14,%rsi
  call   <edc_computeblock@plt>
  mov    %r13,%rcx
  mov    %ebx,%edx
  mov    $0x1,%esi
  mov    %r14,%rdi
  mov    %eax,%ebp
  call   <fwrite@plt>
  mov    %r12,%rdi
  call   <ftell@plt>
  mov    %eax,%edi
  call   <setcounter_encode@plt>
  test   %r15d,%r15d
  jne    L37
  jmp    L52
L108:
  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;
}
```