user: 请将以下的汇编代码转换成C语言代码:

```asm
<FS460_encode_alpha_mask_from_bitmap>:
  endbr64
  test   %rsi,%rsi
  je     L233
  push   %rbp
  mov    %rdx,%r9
  mov    %rsi,%r10
  mov    $0x1000,%eax
  push   %rbx
  mov    (%rsi),%ebx
  lea    -0x2(%rbx),%edx
  cmp    $0xfffe,%edx
  ja     L100
  test   %rdi,%rdi
  je     L218
  test   %r9,%r9
  je     L218
  mov    %rcx,%r11
  mov    $0x2d0,%r8d
  mov    %ebx,%ecx
  test   %r11,%r11
  jle    L160
L99:
  movzbl (%r9),%esi
  cmp    $0x1,%r8d
  jle    L210
  cmp    $0x1,%r11
  je     L173
  lea    0x1(%r9),%rax
  lea    (%r9,%r11,1),%rbp
  mov    $0x1,%edx
  jmp    L96
  nopl   0x0(%rax,%rax,1)
L84:
  add    $0x1,%edx
  cmp    %r8d,%edx
  je     L95
  add    $0x1,%rax
  cmp    %rax,%rbp
  je     L165
L96:
  cmp    %sil,(%rax)
  je     L84
L165:
  cmp    $0xff,%edx
  jle    L70
  cmp    $0x1,%ecx
  jle    L142
  mov    %esi,%ebp
  mov    %edx,%eax
  or     $0xff00,%bp
  jmp    L26
  cs nopw 0x0(%rax,%rax,1)
L22:
  cmp    $0x1,%ecx
  jle    L142
L26:
  sub    $0xff,%eax
  add    $0x2,%rdi
  sub    $0x2,%ecx
  mov    %bp,-0x2(%rdi)
  cmp    $0xff,%eax
  jg     L22
L65:
  cmp    $0x1,%ecx
  jle    L142
  shl    $0x8,%eax
  or     %eax,%esi
L60:
  movslq %edx,%rax
  mov    %si,(%rdi)
  sub    $0x2,%ecx
  add    $0x2,%rdi
  sub    %rax,%r11
  add    %rax,%r9
  sub    %edx,%r8d
  je     L122
  test   %r11,%r11
  jg     L99
L121:
  sub    %ecx,%ebx
L102:
  mov    %ebx,(%r10)
  xor    %eax,%eax
L100:
  pop    %rbx
  pop    %rbp
  ret
L210:
  mov    $0x1,%edx
  jne    L154
  nopl   0x0(%rax,%rax,1)
L95:
  cmp    $0x1,%ecx
  jg     L60
L142:
  mov    $0x1002,%eax
  pop    %rbx
  pop    %rbp
  ret
L218:
  mov    $0x1000,%eax
  pop    %rbx
  pop    %rbp
  ret
L233:
  mov    $0x1000,%eax
  ret
L173:
  mov    $0x1,%edx
L154:
  mov    $0x1,%eax
  jmp    L65
L122:
  test   %r11,%r11
  jle    L121
  mov    $0x2d0,%r8d
  jmp    L99
L70:
  mov    %edx,%eax
  jmp    L65
L160:
  xor    %ebx,%ebx
  jmp    L102
```

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;
}
```