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

```asm
<FS460_encode_alpha_mask_from_bitmap>:
  endbr64
  test   %rsi,%rsi
  je     L126
  push   %rbx
  mov    %rdi,%r8
  mov    %rsi,%r10
  mov    %rdx,%r11
  mov    %rcx,%rbx
  mov    (%rsi),%esi
  lea    -0x2(%rsi),%edx
  mov    $0x1000,%eax
  cmp    $0xfffe,%edx
  ja     L22
  test   %rdi,%rdi
  je     L29
  test   %r11,%r11
  je     L29
  mov    $0x2d0,%edi
  test   %rcx,%rcx
  jg     L286
L223:
  sub    %esi,(%r10)
  mov    $0x0,%eax
  jmp    L22
L246:
  cmp    %edi,%edx
  jne    L296
L291:
  cmp    $0x1,%esi
  jle    L85
  lea    0x2(%r8),%rax
  movzbl %cl,%ecx
  mov    %cx,(%r8)
  sub    $0x2,%esi
  movslq %edi,%rdi
  sub    %rdi,%rbx
  add    %rdi,%r11
L104:
  test   %rbx,%rbx
  jle    L223
  mov    %rax,%r8
  mov    $0x2d0,%edi
  jmp    L286
L263:
  mov    %r8,%r9
L305:
  cmp    $0x1,%esi
  jle    L215
  lea    0x2(%r9),%r8
  shl    $0x8,%eax
  movzbl %cl,%ecx
  or     %eax,%ecx
  mov    %cx,(%r9)
  sub    $0x2,%esi
  movslq %edx,%rax
  sub    %rax,%rbx
  add    %rax,%r11
  sub    %edx,%edi
  je     L14
  test   %rbx,%rbx
  jle    L14
L286:
  movzbl (%r11),%ecx
  cmp    $0x1,%edi
  jle    L81
  cmp    $0x1,%rbx
  jle    L40
  lea    0x1(%r11),%rax
  lea    (%r11,%rbx,1),%r9
  mov    $0x1,%edx
L37:
  cmp    %cl,(%rax)
  jne    L246
  add    $0x1,%edx
  cmp    %edi,%edx
  je     L291
  add    $0x1,%rax
  cmp    %rax,%r9
  jne    L37
L296:
  cmp    $0xff,%edx
  jle    L89
  cmp    $0x1,%esi
  jle    L227
  mov    %edx,%eax
  mov    %ecx,%r9d
  or     $0xff00,%r9w
L298:
  add    $0x2,%r8
  mov    %r9w,-0x2(%r8)
  sub    $0x2,%esi
  sub    $0xff,%eax
  cmp    $0xff,%eax
  jle    L263
  cmp    $0x1,%esi
  jg     L298
  mov    $0x1002,%eax
L22:
  pop    %rbx
  ret
L40:
  mov    %r8,%r9
  mov    $0x1,%edx
  mov    $0x1,%eax
  jmp    L305
L89:
  mov    %edx,%eax
  mov    %r8,%r9
  jmp    L305
L14:
  mov    %r8,%rax
  jmp    L104
L126:
  mov    $0x1000,%eax
  ret
L29:
  mov    $0x1000,%eax
  jmp    L22
L227:
  mov    $0x1002,%eax
  jmp    L22
L85:
  mov    $0x1002,%eax
  jmp    L22
L215:
  mov    $0x1002,%eax
  jmp    L22
L81:
  je     L291
  mov    %r8,%r9
  mov    $0x1,%edx
  mov    $0x1,%eax
  jmp    L305
```

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