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

```asm
<permut_genes_among_indiv_within_pop>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %edi,%r13d
  mov    %edi,0x1c(%rsp)
  mov    %esi,%ebp
  mov    %esi,0x28(%rsp)
  mov    %edx,%ebx
  mov    %edx,0x14(%rsp)
  mov    %r8,%r14
  mov    %r9d,0x18(%rsp)
  mov    0x70(%rsp),%r12
  mov    0x78(%rsp),%r15
  mov    %edi,%eax
  imul   %edx,%eax
  mov    %eax,0x2c(%rsp)
  mov    %eax,%esi
  mov    $0x0,%edi
  call   <ivector@plt>
  mov    %rax,(%rsp)
  test   %ebp,%ebp
  jle    L109
  lea    -0x1(%rbx),%eax
  lea    0x4(,%rax,4),%rbp
  mov    $0x8,%ebx
  movl   $0x1,0x24(%rsp)
  lea    0x1(%r13),%eax
  mov    %eax,0x20(%rsp)
  jmp    L188
L18:
  add    $0x4,%rdx
  cmp    %rdx,%rbp
  je     L187
L61:
  mov    (%r12,%rax,8),%rcx
  mov    (%rcx,%rbx,1),%rcx
  mov    (%rcx,%rdx,1),%ecx
  test   %ecx,%ecx
  je     L18
  add    $0x1,%esi
  movslq %esi,%rdi
  mov    %ecx,(%r9,%rdi,4)
  jmp    L18
L187:
  add    $0x1,%rax
  cmp    %r8,%rax
  je     L222
L176:
  cmp    %r13d,(%r14,%rax,4)
  jne    L187
  cmpl   $0x0,0x14(%rsp)
  jle    L187
  mov    $0x0,%edx
  jmp    L61
L90:
  mov    (%r15,%rax,8),%rcx
  mov    (%rcx,%rbx,1),%rcx
  movl   $0x0,(%rcx,%rdx,1)
L111:
  add    $0x4,%rdx
  cmp    %rdx,%rbp
  je     L48
L86:
  mov    (%r12,%rax,8),%rcx
  mov    (%rcx,%rbx,1),%rcx
  cmpl   $0x0,(%rcx,%rdx,1)
  je     L90
  add    $0x1,%esi
  movslq %esi,%rcx
  mov    (%r8,%rcx,4),%r9d
  mov    (%r15,%rax,8),%rcx
  mov    (%rcx,%rbx,1),%rcx
  mov    %r9d,(%rcx,%rdx,1)
  jmp    L111
L48:
  add    $0x1,%rax
  cmp    %rdi,%rax
  je     L216
L171:
  cmp    %r13d,(%r14,%rax,4)
  jne    L48
  cmpl   $0x0,0x14(%rsp)
  jle    L48
  mov    $0x0,%edx
  jmp    L86
L216:
  add    $0x1,%r13d
  cmp    %r13d,0x18(%rsp)
  jl     L161
L175:
  mov    0x20(%rsp),%eax
  mov    %rax,0x8(%rsp)
  mov    $0x1,%eax
  mov    $0x0,%esi
  mov    (%rsp),%r9
  mov    0x8(%rsp),%r8
  cmpl   $0x0,0x1c(%rsp)
  jg     L176
  mov    0x80(%rsp),%rcx
  mov    $0x0,%edx
  mov    $0x1,%esi
  mov    (%rsp),%rdi
  call   <resample_shuffle@plt>
  jmp    L216
L161:
  addl   $0x1,0x24(%rsp)
  mov    0x24(%rsp),%eax
  add    $0x8,%rbx
  cmp    %eax,0x28(%rsp)
  jl     L109
L188:
  mov    $0x1,%r13d
  cmpl   $0x0,0x18(%rsp)
  jg     L175
  jmp    L161
L109:
  mov    0x2c(%rsp),%edx
  mov    $0x0,%esi
  mov    (%rsp),%rdi
  call   <free_ivector@plt>
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L222:
  mov    0x80(%rsp),%rcx
  mov    %esi,%edx
  mov    $0x1,%esi
  mov    (%rsp),%rdi
  call   <resample_shuffle@plt>
  mov    $0x1,%eax
  mov    $0x0,%esi
  mov    (%rsp),%r8
  mov    0x8(%rsp),%rdi
  jmp    L171
```

assistant: ```c
void permut_genes_among_indiv_within_pop(int n, int m, int ploidy, int *ploidyi, int *popi, int Npop, int ***gilc, int ***gilcmix, long *seed) {
  int i, l, c, Nvalidgene, p;
  int *gene;
  gene = ivector(0, n * ploidy);
  for (l = 1; l <= m; l++) {
    for (p = 1; p <= Npop; p++) {
      Nvalidgene = 0;
      for (i = 1; i <= n; i++)
        if (popi[i] == p) {
          for (c = 0; c < ploidy; c++)
            if (gilc[i][l][c]) {
              Nvalidgene++;
              gene[Nvalidgene] = gilc[i][l][c];
            }
        }
      resample_shuffle(gene, 1, Nvalidgene, seed);
      Nvalidgene = 0;
      for (i = 1; i <= n; i++)
        if (popi[i] == p) {
          for (c = 0; c < ploidy; c++) {
            if (gilc[i][l][c]) {
              Nvalidgene++;
              gilcmix[i][l][c] = gene[Nvalidgene];
            } else
              gilcmix[i][l][c] = 0;
          }
        }
    }
  }
  free_ivector(gene, 0, n * ploidy);
}
```