user: 请从给定的汇编指令推导出C源代码:

```asm
<apply_mask>:
  endbr64
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %edi,%r14d
  mov    %esi,%r12d
  mov    %rdx,%rbx
  mov    %rcx,%rbp
  mov    %r8d,%r13d
  cmp    $0x3,%edi
  setbe  %dil
  movzbl %dil,%edi
  call   <assert@plt>
  cmp    $0x2,%r14d
  je     L112
  jg     L141
  test   %r14d,%r14d
  je     L56
  cmp    $0x1,%r14d
  jne    L126
  movb   $0x1,(%rbx)
  test   %r12d,%r12d
  jle    L126
  mov    %r12d,%edi
  mov    $0x0,%ecx
L125:
  movzbl 0x0(%rbp,%rcx,1),%edx
  lea    (%rcx,%rcx,2),%eax
  add    %eax,%edx
  movslq %edx,%rax
  imul   $0x487ede05,%rax,%rax
  sar    $0x25,%rax
  mov    %edx,%esi
  sar    $0x1f,%esi
  sub    %esi,%eax
  imul   $0x71,%eax,%eax
  sub    %eax,%edx
  mov    %dl,0x1(%rbx,%rcx,1)
  add    $0x1,%rcx
  cmp    %rcx,%rdi
  jne    L125
  jmp    L126
L141:
  cmp    $0x3,%r14d
  jne    L126
  movb   $0x3,(%rbx)
  test   %r12d,%r12d
  jle    L126
  mov    %r12d,%edi
  shl    $0x4,%edi
  add    %r12d,%edi
  mov    $0x0,%esi
  mov    $0x0,%ecx
L104:
  movzbl 0x0(%rbp,%rsi,1),%edx
  add    %ecx,%edx
  movslq %edx,%rax
  imul   $0x487ede05,%rax,%rax
  sar    $0x25,%rax
  mov    %edx,%r8d
  sar    $0x1f,%r8d
  sub    %r8d,%eax
  imul   $0x71,%eax,%eax
  sub    %eax,%edx
  mov    %dl,0x1(%rbx,%rsi,1)
  add    $0x11,%ecx
  add    $0x1,%rsi
  cmp    %edi,%ecx
  jne    L104
  jmp    L126
L56:
  movb   $0x0,(%rbx)
  test   %r12d,%r12d
  jle    L126
  mov    %r12d,%ecx
  mov    $0x0,%eax
L78:
  movzbl 0x0(%rbp,%rax,1),%edx
  mov    %dl,0x1(%rbx,%rax,1)
  add    $0x1,%rax
  cmp    %rax,%rcx
  jne    L78
L126:
  lea    0x1(%r12),%edi
  mov    %rbx,%rdx
  mov    %r13d,%esi
  call   <rsencode@plt>
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
L112:
  movb   $0x2,(%rbx)
  test   %r12d,%r12d
  jle    L126
  lea    0x0(,%r12,8),%edi
  sub    %r12d,%edi
  mov    $0x0,%esi
  mov    $0x0,%ecx
L44:
  movzbl 0x0(%rbp,%rsi,1),%edx
  add    %ecx,%edx
  movslq %edx,%rax
  imul   $0x487ede05,%rax,%rax
  sar    $0x25,%rax
  mov    %edx,%r8d
  sar    $0x1f,%r8d
  sub    %r8d,%eax
  imul   $0x71,%eax,%eax
  sub    %eax,%edx
  mov    %dl,0x1(%rbx,%rsi,1)
  add    $0x7,%ecx
  add    $0x1,%rsi
  cmp    %edi,%ecx
  jne    L44
  jmp    L126
```

assistant: ```c
void apply_mask(const int mask, const int data_length, unsigned char *masked_codeword_array, const unsigned char *codeword_array, const int ecc_length) {
  int weight = 0;
  int j;
  assert(mask >= 0 && mask <= 3);
  switch (mask) {
  case 0:
    masked_codeword_array[0] = 0;
    for (j = 0; j < data_length; j++) {
      masked_codeword_array[j + 1] = codeword_array[j];
    }
    break;
  case 1:
    masked_codeword_array[0] = 1;
    for (j = 0; j < data_length; j++) {
      masked_codeword_array[j + 1] = (weight + codeword_array[j]) % 113;
      weight += 3;
    }
    break;
  case 2:
    masked_codeword_array[0] = 2;
    for (j = 0; j < data_length; j++) {
      masked_codeword_array[j + 1] = (weight + codeword_array[j]) % 113;
      weight += 7;
    }
    break;
  case 3:
    masked_codeword_array[0] = 3;
    for (j = 0; j < data_length; j++) {
      masked_codeword_array[j + 1] = (weight + codeword_array[j]) % 113;
      weight += 17;
    }
    break;
  }
  rsencode(data_length + 1, ecc_length, masked_codeword_array);
}
```