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

```asm
<FS460_encode_alpha_mask_from_bitmap>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %rcx,-0x50(%rbp)
  cmpq   $0x0,-0x40(%rbp)
  je     L70
  mov    -0x40(%rbp),%rax
  mov    (%rax),%eax
  cmp    $0x10000,%eax
  jg     L70
  mov    -0x40(%rbp),%rax
  mov    (%rax),%eax
  cmp    $0x1,%eax
  jle    L70
  cmpq   $0x0,-0x38(%rbp)
  je     L70
  cmpq   $0x0,-0x48(%rbp)
  jne    L119
L70:
  mov    $0x1000,%eax
  jmp    L231
L119:
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x48(%rbp),%rax
  mov    %rax,-0x8(%rbp)
  mov    -0x40(%rbp),%rax
  mov    (%rax),%eax
  mov    %eax,-0x14(%rbp)
  jmp    L262
L12:
  movl   $0x2d0,-0x18(%rbp)
  jmp    L233
L230:
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  mov    %al,-0x21(%rbp)
  movl   $0x1,-0x20(%rbp)
L45:
  mov    -0x20(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jge    L227
  mov    -0x20(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x50(%rbp),%rax
  sub    %rdx,%rax
  test   %rax,%rax
  jle    L139
  mov    -0x20(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    %al,-0x21(%rbp)
  jne    L26
  addl   $0x1,-0x20(%rbp)
  jmp    L45
L227:
  nop
  jmp    L6
L139:
  nop
  jmp    L6
L26:
  nop
L6:
  mov    -0x20(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jne    L235
  cmpl   $0x1,-0x14(%rbp)
  jg     L174
  mov    $0x1002,%eax
  jmp    L231
L174:
  mov    -0x10(%rbp),%rax
  lea    0x2(%rax),%rdx
  mov    %rdx,-0x10(%rbp)
  movzbl -0x21(%rbp),%edx
  mov    %dx,(%rax)
  subl   $0x2,-0x14(%rbp)
  jmp    L152
L235:
  mov    -0x20(%rbp),%eax
  mov    %eax,-0x1c(%rbp)
  jmp    L220
L7:
  cmpl   $0x1,-0x14(%rbp)
  jg     L201
  mov    $0x1002,%eax
  jmp    L231
L201:
  movzbl -0x21(%rbp),%eax
  or     $0xff00,%ax
  mov    %eax,%ecx
  mov    -0x10(%rbp),%rax
  lea    0x2(%rax),%rdx
  mov    %rdx,-0x10(%rbp)
  mov    %ecx,%edx
  mov    %dx,(%rax)
  subl   $0x2,-0x14(%rbp)
  subl   $0xff,-0x1c(%rbp)
L220:
  cmpl   $0xff,-0x1c(%rbp)
  jg     L7
  cmpl   $0x1,-0x14(%rbp)
  jg     L68
  mov    $0x1002,%eax
  jmp    L231
L68:
  mov    -0x1c(%rbp),%eax
  shl    $0x8,%eax
  mov    %eax,%edx
  movzbl -0x21(%rbp),%eax
  mov    %edx,%ecx
  or     %eax,%ecx
  mov    -0x10(%rbp),%rax
  lea    0x2(%rax),%rdx
  mov    %rdx,-0x10(%rbp)
  mov    %ecx,%edx
  mov    %dx,(%rax)
  subl   $0x2,-0x14(%rbp)
L152:
  mov    -0x20(%rbp),%eax
  sub    %eax,-0x18(%rbp)
  mov    -0x20(%rbp),%eax
  cltq
  sub    %rax,-0x50(%rbp)
  mov    -0x20(%rbp),%eax
  cltq
  add    %rax,-0x8(%rbp)
L233:
  cmpl   $0x0,-0x18(%rbp)
  je     L262
  cmpq   $0x0,-0x50(%rbp)
  jg     L230
L262:
  cmpq   $0x0,-0x50(%rbp)
  jg     L12
  mov    -0x40(%rbp),%rax
  mov    (%rax),%eax
  sub    -0x14(%rbp),%eax
  mov    %eax,%edx
  mov    -0x40(%rbp),%rax
  mov    %edx,(%rax)
  mov    $0x0,%eax
L231:
  pop    %rbp
  ret
```

assistant: ```c
int FS460_encode_alpha_mask_from_bitmap(unsigned short *p_alpha_mask, int *p_mask_size, const unsigned char *p_alpha_values, long alpha_value_count) {
  unsigned short *p_m;
  const unsigned char *p_a;
  int count, c, remainder;
  int mask_size;
  unsigned char to_match;
  if (!p_mask_size || (*p_mask_size > 0x10000) || (*p_mask_size < 2) || !p_alpha_mask || !p_alpha_values)
    return 0x1000;
  p_m = p_alpha_mask;
  p_a = p_alpha_values;
  mask_size = *p_mask_size;
  while (alpha_value_count > 0) {
    remainder = 720;
    while (remainder && (alpha_value_count > 0)) {
      to_match = *p_a;
      for (count = 1; 1; count++) {
        if (count >= remainder)
          break;
        if (alpha_value_count - count <= 0)
          break;
        if (to_match != p_a[count])
          break;
      }
      {}
      if (count == remainder) {
        if (mask_size < 2)
          return 0x1002;
        *(p_m++) = to_match;
        mask_size -= 2;
      } else {
        c = count;
        while (c > 255) {
          if (mask_size < 2)
            return 0x1002;
          *(p_m++) = (0xFF00 | to_match);
          mask_size -= 2;
          c -= 255;
        }
        {
          if (mask_size < 2)
            return 0x1002;
          *(p_m++) = ((0xFF00 & (c << 8)) | to_match);
          mask_size -= 2;
        }
      }
      remainder -= count;
      alpha_value_count -= count;
      p_a += count;
    }
  }
  *p_mask_size -= mask_size;
  return 0;
}
```