user: Converte this assembly snippet into its equivalent C code:

```asm
<fill_table_color>:
  endbr64
  push   %r15
  mov    %edi,%eax
  push   %r14
  shl    $0x8,%eax
  mov    $0xffffff80,%r14d
  push   %r13
  push   %r12
  mov    $0x1,%r12d
  push   %rbp
  lea    (%rsi,%rax,4),%rbp
  push   %rbx
  mov    %rdx,-0x10(%rsp)
  mov    %rcx,-0x8(%rsp)
  movq   $0x0,-0x18(%rsp)
L82:
  mov    -0x18(%rsp),%rax
  mov    -0x10(%rsp),%rbx
  lea    (%rbx,%rax,4),%r13
  mov    -0x8(%rsp),%rbx
  add    %rax,%rbx
  lea    0x200(%rbp),%rax
  mov    %rbx,-0x28(%rsp)
  mov    %rax,-0x20(%rsp)
L95:
  mov    -0x28(%rsp),%r11
  mov    %r13,%rbx
  mov    %rbp,%r10
  xor    %r9d,%r9d
  nopl   0x0(%rax,%rax,1)
L108:
  lea    0x1(%r11),%rdi
  mov    %rbx,%rax
  xor    %esi,%esi
  nopl   0x0(%rax)
L58:
  test   %esi,%esi
  jne    L30
  movb   $0x1,(%rdi)
  add    $0x1,%rax
  add    $0x2,%rdi
  mov    $0x1,%esi
  movb   $0x8,-0x3(%rdi)
  movb   $0x82,-0x1(%rax)
  movb   $0x84,0xf(%rax)
  movb   $0x86,0x1f(%rax)
  movb   $0x88,0x2f(%rax)
  movb   $0x7e,0x3f(%rax)
  movb   $0x7c,0x4f(%rax)
  movb   $0x7a,0x5f(%rax)
  movb   $0x78,0x6f(%rax)
L30:
  lea    -0x1(%rsi),%edx
  mov    (%r10),%ecx
  cmp    $0x1,%edx
  jbe    L109
  lea    -0x3(%rsi),%edx
  cmp    $0x2,%edx
  jbe    L69
  lea    -0x6(%rsi),%edx
  cmp    $0x3,%edx
  jbe    L27
  lea    -0xa(%rsi),%edx
  cmp    $0x2,%edx
  jbe    L76
  mov    %ecx,%edx
  and    $0x7,%ecx
  shr    $0x3,%edx
  and    $0x7,%edx
  cmp    $0xf,%esi
  cmovne %edx,%ecx
L87:
  mov    %r12d,%edx
  mov    %r9d,%r15d
  mov    %cl,(%rdi)
  add    $0x1,%esi
  shl    %cl,%edx
  sub    %ecx,%r15d
  add    $0x2,%rdi
  add    $0x1,%rax
  lea    -0x80(%rdx),%ecx
  mov    %r15b,-0x3(%rdi)
  lea    (%rdx,%rdx,2),%r8d
  mov    %cl,-0x1(%rax)
  lea    -0x80(%rdx,%rdx,1),%ecx
  mov    %cl,0xf(%rax)
  lea    -0x80(%r8),%ecx
  mov    %cl,0x1f(%rax)
  lea    -0x80(,%rdx,4),%ecx
  mov    %cl,0x2f(%rax)
  mov    %r14d,%ecx
  sub    %edx,%ecx
  mov    %cl,0x3f(%rax)
  lea    -0x40(%rdx),%ecx
  sub    $0x20,%edx
  neg    %ecx
  neg    %edx
  add    %ecx,%ecx
  shl    $0x2,%edx
  mov    %cl,0x4f(%rax)
  mov    %r14d,%ecx
  sub    %r8d,%ecx
  mov    %dl,0x6f(%rax)
  mov    %cl,0x5f(%rax)
  cmp    $0x10,%esi
  jne    L58
  add    $0x1,%r9d
  add    $0x20,%r11
  add    $0x4,%r10
  sub    $0xffffffffffffff80,%rbx
  cmp    $0x8,%r9d
  jne    L108
  addq   $0x100,-0x28(%rsp)
  add    $0x20,%rbp
  add    $0x400,%r13
  cmp    -0x20(%rsp),%rbp
  jne    L95
  addq   $0x1000,-0x18(%rsp)
  mov    -0x18(%rsp),%rax
  cmp    $0x2000,%rax
  jne    L82
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L109:
  shr    $0xf,%ecx
  and    $0x7,%ecx
  jmp    L87
L76:
  shr    $0x6,%ecx
  and    $0x7,%ecx
  jmp    L87
L27:
  shr    $0x9,%ecx
  and    $0x7,%ecx
  jmp    L87
L69:
  shr    $0xc,%ecx
  and    $0x7,%ecx
  jmp    L87
```

assistant: ```c
void fill_table_color(unsigned int version, const unsigned int *romtable, unsigned char *p0004, unsigned char *p8004) {
  const unsigned int *table;
  unsigned char *p0, *p8;
  int i, j, k;
  int dl, bit, pw;
  romtable += version * 256;
  for (i = 0; i < 2; i++) {
    table = romtable + i * 128;
    for (dl = 0; dl < 16; dl++) {
      p0 = p0004 + (i << 14) + (dl << 10);
      p8 = p8004 + (i << 12) + (dl << 8);
      for (j = 0; j < 8; j++, table++, p0 += 128) {
        for (k = 0; k < 16; k++) {
          if (k == 0)
            bit = 1;
          else if (k >= 1 && k < 3)
            bit = (table[0] >> 15) & 7;
          else if (k >= 3 && k < 6)
            bit = (table[0] >> 12) & 7;
          else if (k >= 6 && k < 10)
            bit = (table[0] >> 9) & 7;
          else if (k >= 10 && k < 13)
            bit = (table[0] >> 6) & 7;
          else if (k >= 13 && k < 15)
            bit = (table[0] >> 3) & 7;
          else
            bit = (table[0]) & 7;
          if (k == 0)
            *(unsigned char *)p8++ = 8;
          else
            *(unsigned char *)p8++ = j - bit;
          *(unsigned char *)p8++ = bit;
          pw = 1 << bit;
          p0[k + 0x00] = (1 * pw) + 0x80;
          p0[k + 0x10] = (2 * pw) + 0x80;
          p0[k + 0x20] = (3 * pw) + 0x80;
          p0[k + 0x30] = (4 * pw) + 0x80;
          p0[k + 0x40] = (-pw) + 0x80;
          p0[k + 0x50] = (2 * -pw) + 0x80;
          p0[k + 0x60] = (3 * -pw) + 0x80;
          p0[k + 0x70] = (4 * -pw) + 0x80;
        }
      }
    }
  }
}
```