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

```asm
<sega_lz77>:
  endbr64
  push   %r13
  xor    %r11d,%r11d
  xor    %eax,%eax
  push   %r12
  mov    %rdx,%r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  mov    %esi,%edi
  mov    $0x1,%esi
  test   %edi,%edi
  jle    L283
  nopl   0x0(%rax)
L215:
  movslq %r11d,%rdx
  jmp    L36
  nopl   (%rax)
L263:
  lea    -0x2(%rsi),%r10d
  mov    %r8d,%ecx
  mov    %r9d,%esi
L138:
  mov    %ecx,%r8d
  mov    %ecx,%r9d
  shr    %r8b
  and    $0x1,%r9d
  je     L296
  xor    %ecx,%ecx
  cmp    %edi,%eax
  jge    L103
  movslq %eax,%rcx
  add    $0x1,%eax
  movzbl (%rbx,%rcx,1),%ecx
L103:
  mov    %cl,(%r12,%rdx,1)
  add    $0x1,%rdx
L36:
  mov    %esi,%r9d
  mov    %edx,%ebp
  movslq %edx,%r11
  sub    $0x1,%r9d
  jne    L263
  cmp    %edi,%eax
  jge    L140
  movslq %eax,%rcx
  mov    $0x7,%r10d
  add    $0x1,%eax
  mov    $0x8,%esi
  movzbl (%rbx,%rcx,1),%ecx
  jmp    L138
  xchg   %ax,%ax
L140:
  xor    %r8d,%r8d
  mov    $0x6,%r10d
L219:
  mov    %r8d,%edx
  mov    %r10d,%esi
  shr    %r8b
  and    $0x1,%edx
  mov    %r8d,%r9d
  add    %edx,%edx
  sub    $0x1,%esi
  jne    L38
  cmp    %eax,%edi
  jle    L56
  movslq %eax,%rcx
  mov    $0x8,%esi
  add    $0x1,%eax
  movzbl (%rbx,%rcx,1),%r8d
  mov    %r8d,%ecx
  shr    %r8b
  and    $0x1,%ecx
  lea    0x2(%rdx,%rcx,1),%edx
L54:
  cmp    %edi,%eax
  jge    L113
L193:
  movslq %eax,%rcx
  add    $0x1,%eax
  movzbl (%rbx,%rcx,1),%ecx
  sub    $0x100,%ecx
L284:
  cmp    %eax,%edi
  jg     L215
  jmp    L248
  nopl   (%rax)
L296:
  test   %r10d,%r10d
  jne    L270
  cmp    %edi,%eax
  jge    L313
  movslq %eax,%rdx
  add    $0x1,%eax
  movzbl (%rbx,%rdx,1),%ecx
  mov    %ecx,%r8d
  shr    %r8b
  test   $0x1,%cl
  je     L232
  mov    $0x8,%r10d
L187:
  cmp    %eax,%edi
  jle    L283
  movslq %eax,%rdx
  lea    0x1(%rax),%r9d
  movzbl (%rbx,%rdx,1),%edx
  mov    %edx,%esi
  cmp    %r9d,%edi
  jle    L332
  movslq %r9d,%r9
  movzbl (%rbx,%r9,1),%ecx
  lea    0x2(%rax),%r9d
  mov    %ecx,%r13d
  or     %edx,%r13d
L203:
  test   %r13b,%r13b
  je     L236
  shr    $0x3,%edx
  shl    $0x5,%ecx
  lea    -0x2000(%rdx,%rcx,1),%ecx
  and    $0x7,%esi
  je     L266
  add    $0x2,%esi
  mov    %r9d,%eax
  movzbl %sil,%edx
  mov    %r10d,%esi
  jmp    L284
L270:
  mov    %r8d,%edx
  shr    $0x2,%cl
  and    $0x1,%edx
  mov    %ecx,%r8d
  test   %dl,%dl
  jne    L187
  sub    $0x1,%r10d
  jne    L219
  cmp    %edi,%eax
  jge    L72
  movslq %eax,%rdx
  add    $0x1,%eax
  movzbl (%rbx,%rdx,1),%edx
  mov    %edx,%ecx
  mov    %edx,%r8d
  and    $0x1,%edx
  shr    %cl
  shr    $0x2,%r8b
  and    $0x1,%ecx
  lea    0x2(%rcx,%rdx,2),%edx
L184:
  mov    $0x7,%esi
  cmp    %edi,%eax
  jl     L193
L113:
  mov    $0xffffff00,%ecx
L248:
  lea    -0x1(%rdx),%eax
  lea    0x1(%r12,%r11,1),%rdi
  add    %rax,%rdi
  lea    (%rcx,%rbp,1),%esi
  lea    (%r12,%r11,1),%rax
  sub    %eax,%esi
  nopl   0x0(%rax,%rax,1)
L216:
  lea    (%rsi,%rax,1),%ecx
  add    $0x1,%rax
  movzbl (%r12,%rcx,1),%ecx
  mov    %cl,-0x1(%rax)
  cmp    %rdi,%rax
  jne    L216
  lea    (%rdx,%rbp,1),%r11d
L283:
  pop    %rbx
  mov    %r11d,%eax
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
  nopw   0x0(%rax,%rax,1)
L266:
  cmp    %r9d,%edi
  jle    L135
  lea    0x1(%r9),%eax
  movslq %r9d,%r9
  mov    %r10d,%esi
  movzbl (%rbx,%r9,1),%edx
  add    $0xa,%edx
  jmp    L284
  nopl   0x0(%rax)
L313:
  mov    $0x6,%esi
  xor    %edx,%edx
L38:
  mov    %r9d,%ecx
  mov    %r9d,%r8d
  and    $0x1,%ecx
  shr    %r8b
  lea    0x2(%rdx,%rcx,1),%edx
  jmp    L54
  nopl   0x0(%rax)
L332:
  mov    %edx,%r13d
  xor    %ecx,%ecx
  jmp    L203
L72:
  xor    %r8d,%r8d
  mov    $0x2,%edx
  jmp    L184
L56:
  add    $0x2,%edx
  jmp    L113
L135:
  mov    $0xa,%edx
  jmp    L248
L236:
  test   %edx,%edx
  jne    L248
  jmp    L283
L232:
  mov    %ecx,%edx
  and    $0x1,%r8d
  shr    $0x3,%cl
  mov    $0x6,%esi
  shr    $0x2,%dl
  and    $0x1,%edx
  lea    0x2(%rdx,%r8,2),%edx
  mov    %ecx,%r8d
  jmp    L54
```

assistant: ```c
int sega_lz77(unsigned char *Buf, int File_Size, unsigned char *Buf2) {
  int SrcPos;
  unsigned char CurByte;
  int BitCounter;
  unsigned char GetByte_00E1F580(void) {
    unsigned char RESULT;
    if (SrcPos >= File_Size)
      return (0);
    RESULT = Buf[SrcPos];
    SrcPos++;
    return (RESULT);
  }
  unsigned char GetBit_00E1F5D0(void) {
    unsigned char RESULT;
    BitCounter--;
    if (!BitCounter) {
      CurByte = GetByte_00E1F580();
      BitCounter = 8;
    }
    RESULT = CurByte & 1;
    CurByte >>= 1;
    return (RESULT);
  }
  unsigned int _EBP_m_4 = 0, _EBP_m_8 = 0;
  int DstPos;
  unsigned char _EAX;
  SrcPos = 0;
  DstPos = 0;
  BitCounter = 1;
  while (SrcPos < File_Size) {
    for (;;) {
      _EAX = GetBit_00E1F5D0();
      if (!_EAX)
        break;
      Buf2[DstPos++] = GetByte_00E1F580();
    }
    if (GetBit_00E1F5D0()) {
      _EBP_m_4 = GetByte_00E1F580();
      _EBP_m_8 = GetByte_00E1F580();
      _EAX = _EBP_m_8 | _EBP_m_4;
      if (!_EAX)
        break;
      _EBP_m_8 = (_EBP_m_8 << 5) + (_EBP_m_4 >> 3) - 0x2000;
      _EBP_m_4 &= 7;
      if (_EBP_m_4) {
        _EBP_m_4 += 2;
      } else {
        _EBP_m_4 = GetByte_00E1F580() + 0x0A;
      }
    } else {
      _EBP_m_4 = GetBit_00E1F5D0() * 2;
      _EBP_m_4 += GetBit_00E1F5D0() + 2;
      _EBP_m_8 = GetByte_00E1F580() - 0x100;
    }
  }
  while (_EBP_m_4 > 0) {
    Buf2[DstPos] = Buf2[DstPos + _EBP_m_8];
    DstPos++;
    _EBP_m_4--;
  }
  return (DstPos);
}
```