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

```asm
<chunk_creation_servers>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,%rbp
  mov    %esi,%ebx
  mov    %rdx,%r13
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0xc(%rsp),%rsi
  call   <matocsserv_getservers_wrandom@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  jne    L26
  cmpl   $0x0,0xc(%rsp)
  setg   %al
  movzbl %al,%eax
  mov    %eax,0x0(%r13)
L261:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L1
  mov    %r12d,%eax
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L26:
  mov    %ebx,%edi
  call   <labelset_get_create_mode@plt>
  mov    %eax,%r14d
  mov    %ebx,%edi
  call   <labelset_get_create_goal@plt>
  cmp    %eax,%r12d
  jge    L43
  mov    %r12d,%edx
  add    0xc(%rsp),%edx
  cmp    %eax,%edx
  jge    L124
L43:
  movl   $0x0,0x0(%r13)
  mov    %ebx,%edi
  call   <labelset_has_create_labels@plt>
  test   %rax,%rax
  je     L261
  lea    0x10(%rsp),%rsi
  mov    %ebx,%edi
  call   <labelset_get_create_labelmasks@plt>
  mov    %eax,%ebx
  mov    %r12d,%edi
  shr    $0x1f,%edi
  add    %r12d,%edi
  sar    %edi
  cmp    $0x1,%r12d
  jle    L48
  movslq %r12d,%rax
  lea    0x0(%rbp,%rax,4),%rdx
  mov    $0x0,%eax
L247:
  mov    0x0(%rbp,%rax,4),%ecx
  mov    -0x4(%rdx),%esi
  mov    %esi,0x0(%rbp,%rax,4)
  mov    %ecx,-0x4(%rdx)
  add    $0x1,%rax
  sub    $0x4,%rdx
  cmp    %eax,%edi
  jg     L247
  mov    %rbp,%rcx
  mov    0x10(%rsp),%rdx
  mov    %r12d,%esi
  mov    %ebx,%edi
  call   <do_perfect_match@plt>
  mov    %rax,%r8
  cmp    $0x2,%r14d
  je     L223
L73:
  test   %ebx,%ebx
  jle    L101
  mov    %ebx,%r11d
  movslq %r12d,%rax
  movslq %ebx,%rdx
  add    %rdx,%rax
  lea    -0x4(%r8,%rax,4),%r15
  mov    $0x0,%ecx
  mov    $0x0,%r9d
  jmp    L0
L124:
  movl   $0x1,0x0(%r13)
  mov    $0x0,%r12d
  jmp    L261
L48:
  mov    %rbp,%rcx
  mov    0x10(%rsp),%rdx
  mov    %r12d,%esi
  mov    %eax,%edi
  call   <do_perfect_match@plt>
  mov    %rax,%r8
  cmp    $0x2,%r14d
  jne    L73
  lea    -0x1(%r12),%ecx
  test   %ecx,%ecx
  jg     L165
  mov    $0x0,%eax
  jmp    L13
L10:
  test   %r12d,%r12d
  jle    L297
  lea    (%r12,%rbx,1),%edx
  mov    %r15,%rax
L172:
  mov    %edx,%esi
  cmpl   $0x0,(%rax)
  js     L324
  sub    $0x1,%edx
  sub    $0x4,%rax
  cmp    %ebx,%edx
  jne    L172
L297:
  cmp    %ebx,%r9d
  jge    L132
  cmp    $0x1,%r14d
  je     L364
L132:
  lea    -0x1(%r12),%ecx
  test   %ecx,%ecx
  jle    L261
L165:
  movslq %ebx,%rax
  lea    (%r8,%rax,4),%r9
  mov    $0x0,%eax
  jmp    L22
L324:
  sub    $0x1,%esi
  mov    %esi,(%r8,%rcx,4)
  mov    %r10d,(%rax)
  cmpl   $0x0,(%r8,%rcx,4)
  js     L297
L177:
  add    $0x1,%rcx
  cmp    %r11,%rcx
  je     L297
L0:
  mov    %ecx,%r10d
  cmpl   $0x0,(%r8,%rcx,4)
  js     L10
  add    $0x1,%r9d
  jmp    L177
L101:
  mov    $0x0,%r9d
  jmp    L297
L364:
  add    0xc(%rsp),%r9d
  cmp    %ebx,%r9d
  jl     L132
  movl   $0x1,0x0(%r13)
  mov    $0x0,%r12d
  jmp    L261
L246:
  cmp    %ecx,%eax
  jge    L89
  movslq %ecx,%rdx
L271:
  mov    %edx,%ecx
  cmpl   $0x0,(%r9,%rdx,4)
  jns    L3
  sub    $0x1,%rdx
  cmp    %edx,%eax
  jl     L271
L89:
  cmp    $0x2,%r14d
  jne    L261
L13:
  mov    %eax,%r12d
  cmp    %eax,%ebx
  jle    L261
  mov    %eax,%edx
  add    0xc(%rsp),%edx
  cmp    %ebx,%edx
  jl     L261
  movl   $0x1,0x0(%r13)
  mov    $0x0,%r12d
  jmp    L261
L3:
  cmp    %edx,%eax
  jge    L89
  lea    (%rbx,%rdx,1),%edx
  movslq %edx,%rdx
  lea    (%r8,%rdx,4),%rdx
  mov    (%rdx),%r10d
  mov    %r10d,(%rdi)
  mov    %esi,(%rdx)
  movslq %eax,%rdx
  lea    0x0(%rbp,%rdx,4),%rsi
  mov    (%rsi),%edi
  movslq %ecx,%rdx
  lea    0x0(%rbp,%rdx,4),%rdx
  mov    (%rdx),%r10d
  mov    %r10d,(%rsi)
  mov    %edi,(%rdx)
L22:
  lea    (%rbx,%rax,1),%edx
  movslq %edx,%rdx
  lea    (%r8,%rdx,4),%rdi
  mov    (%rdi),%esi
  test   %esi,%esi
  js     L246
  add    $0x1,%eax
  cmp    %ecx,%eax
  jl     L22
  jmp    L89
L223:
  lea    -0x1(%r12),%ecx
  jmp    L165
L1:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
uint16_t chunk_creation_servers(uint16_t csids[10000], uint8_t lsetid, uint8_t *olflag) {
  int32_t *matching;
  uint32_t **labelmasks;
  uint8_t labelcnt;
  uint8_t create_mode;
  uint16_t servcount;
  uint16_t goodlabelscount;
  uint16_t overloaded;
  uint32_t i, j;
  int32_t x;
  servcount = matocsserv_getservers_wrandom(csids, &overloaded);
  if (servcount == 0) {
    *olflag = (overloaded > 0) ? 1 : 0;
    return 0;
  }
  create_mode = labelset_get_create_mode(lsetid);
  labelcnt = labelset_get_create_goal(lsetid);
  if (servcount < labelcnt && servcount + overloaded >= labelcnt) {
    *olflag = 1;
    return 0;
  } else {
    *olflag = 0;
  }
  if (labelset_has_create_labels(lsetid)) {
    labelcnt = labelset_get_create_labelmasks(lsetid, &labelmasks);
    for (i = 0; i < servcount / 2; i++) {
      x = csids[i];
      csids[i] = csids[servcount - 1 - i];
      csids[servcount - 1 - i] = x;
    }
    matching = do_perfect_match(labelcnt, servcount, labelmasks, csids);
    if (create_mode != 2) {
      goodlabelscount = 0;
      for (i = 0; i < labelcnt; i++) {
        if (matching[i] < 0) {
          for (j = 0; j < servcount; j++) {
            if (matching[labelcnt + servcount - j - 1] < 0) {
              matching[i] = labelcnt + servcount - j - 1;
              matching[labelcnt + servcount - j - 1] = i;
              break;
            }
          }
        } else {
          goodlabelscount++;
        }
        if (matching[i] < 0) {
          break;
        }
      }
      if (create_mode == 1) {
        if (goodlabelscount < labelcnt && goodlabelscount + overloaded >= labelcnt) {
          *olflag = 1;
          return 0;
        }
      }
    }
    i = 0;
    j = servcount - 1;
    while (i < j) {
      while (i < j && matching[labelcnt + i] >= 0) {
        i++;
      }
      while (i < j && matching[labelcnt + j] < 0) {
        j--;
      }
      if (i < j) {
        x = matching[labelcnt + i];
        matching[labelcnt + i] = matching[labelcnt + j];
        matching[labelcnt + j] = x;
        x = csids[i];
        csids[i] = csids[j];
        csids[j] = x;
      }
    }
    if (create_mode == 2) {
      if (i < labelcnt && i + overloaded >= labelcnt) {
        *olflag = 1;
        return 0;
      }
      return i;
    }
  }
  return servcount;
}
```