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

```asm
<apply_mask>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %edi,-0x14(%rbp)
  mov    %esi,-0x18(%rbp)
  mov    %rdx,-0x20(%rbp)
  mov    %rcx,-0x28(%rbp)
  mov    %r8d,-0x2c(%rbp)
  movl   $0x0,-0x8(%rbp)
  cmpl   $0x0,-0x14(%rbp)
  js     L186
  cmpl   $0x3,-0x14(%rbp)
  jg     L186
  mov    $0x1,%eax
  jmp    L148
L186:
  mov    $0x0,%eax
L148:
  mov    %eax,%edi
  call   <assert@plt>
  cmpl   $0x3,-0x14(%rbp)
  je     L181
  cmpl   $0x3,-0x14(%rbp)
  jg     L129
  cmpl   $0x2,-0x14(%rbp)
  je     L50
  cmpl   $0x2,-0x14(%rbp)
  jg     L129
  cmpl   $0x0,-0x14(%rbp)
  je     L23
  cmpl   $0x1,-0x14(%rbp)
  je     L0
  jmp    L129
L23:
  mov    -0x20(%rbp),%rax
  movb   $0x0,(%rax)
  movl   $0x0,-0x4(%rbp)
  jmp    L128
L90:
  mov    -0x4(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  mov    -0x4(%rbp),%edx
  movslq %edx,%rdx
  lea    0x1(%rdx),%rcx
  mov    -0x20(%rbp),%rdx
  add    %rcx,%rdx
  movzbl (%rax),%eax
  mov    %al,(%rdx)
  addl   $0x1,-0x4(%rbp)
L128:
  mov    -0x4(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jl     L90
  jmp    L129
L0:
  mov    -0x20(%rbp),%rax
  movb   $0x1,(%rax)
  movl   $0x0,-0x4(%rbp)
  jmp    L172
L28:
  mov    -0x4(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movzbl %al,%edx
  mov    -0x8(%rbp),%eax
  add    %edx,%eax
  movslq %eax,%rdx
  imul   $0x487ede05,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x5,%edx
  mov    %eax,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%edx
  imul   $0x71,%edx,%ecx
  sub    %ecx,%eax
  mov    %eax,%edx
  mov    -0x4(%rbp),%eax
  cltq
  lea    0x1(%rax),%rcx
  mov    -0x20(%rbp),%rax
  add    %rcx,%rax
  mov    %dl,(%rax)
  addl   $0x3,-0x8(%rbp)
  addl   $0x1,-0x4(%rbp)
L172:
  mov    -0x4(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jl     L28
  jmp    L129
L50:
  mov    -0x20(%rbp),%rax
  movb   $0x2,(%rax)
  movl   $0x0,-0x4(%rbp)
  jmp    L104
L157:
  mov    -0x4(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movzbl %al,%edx
  mov    -0x8(%rbp),%eax
  add    %edx,%eax
  movslq %eax,%rdx
  imul   $0x487ede05,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x5,%edx
  mov    %eax,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%edx
  imul   $0x71,%edx,%ecx
  sub    %ecx,%eax
  mov    %eax,%edx
  mov    -0x4(%rbp),%eax
  cltq
  lea    0x1(%rax),%rcx
  mov    -0x20(%rbp),%rax
  add    %rcx,%rax
  mov    %dl,(%rax)
  addl   $0x7,-0x8(%rbp)
  addl   $0x1,-0x4(%rbp)
L104:
  mov    -0x4(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jl     L157
  jmp    L129
L181:
  mov    -0x20(%rbp),%rax
  movb   $0x3,(%rax)
  movl   $0x0,-0x4(%rbp)
  jmp    L197
L96:
  mov    -0x4(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movzbl %al,%edx
  mov    -0x8(%rbp),%eax
  add    %edx,%eax
  movslq %eax,%rdx
  imul   $0x487ede05,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x5,%edx
  mov    %eax,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%edx
  imul   $0x71,%edx,%ecx
  sub    %ecx,%eax
  mov    %eax,%edx
  mov    -0x4(%rbp),%eax
  cltq
  lea    0x1(%rax),%rcx
  mov    -0x20(%rbp),%rax
  add    %rcx,%rax
  mov    %dl,(%rax)
  addl   $0x11,-0x8(%rbp)
  addl   $0x1,-0x4(%rbp)
L197:
  mov    -0x4(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jl     L96
  nop
L129:
  mov    -0x18(%rbp),%eax
  lea    0x1(%rax),%ecx
  mov    -0x20(%rbp),%rdx
  mov    -0x2c(%rbp),%eax
  mov    %eax,%esi
  mov    %ecx,%edi
  call   <rsencode@plt>
  nop
  leave
  ret
```

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