user: Please show me the C implementation that matches the assembly code listed below:

```asm
<chunk_creation_servers>:
  endbr64
  push   %r15
  push   %r14
  mov    %esi,%r14d
  push   %r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0xc(%rsp),%rsi
  call   <matocsserv_getservers_wrandom@plt>
  mov    %eax,%r13d
  test   %eax,%eax
  jne    L399
  mov    0xc(%rsp),%edx
  xor    %eax,%eax
  test   %edx,%edx
  setg   %al
  mov    %eax,(%rbx)
L332:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L347
  add    $0x28,%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nop
L399:
  mov    %r14d,%edi
  call   <labelset_get_create_mode@plt>
  mov    %r14d,%edi
  mov    %eax,%ebp
  call   <labelset_get_create_goal@plt>
  cmp    %eax,%r13d
  jge    L51
  mov    0xc(%rsp),%edx
  add    %r13d,%edx
  cmp    %eax,%edx
  jge    L180
L51:
  movl   $0x0,(%rbx)
  mov    %r14d,%edi
  call   <labelset_has_create_labels@plt>
  test   %rax,%rax
  je     L332
  mov    %r14d,%edi
  lea    0x10(%rsp),%rsi
  call   <labelset_get_create_labelmasks@plt>
  mov    %r13d,%ecx
  shr    $0x1f,%ecx
  mov    %eax,%r14d
  add    %r13d,%ecx
  sar    %ecx
  cmp    $0x1,%r13d
  jle    L446
  movslq %r13d,%rsi
  mov    %ecx,%eax
  lea    -0x1(%r13),%r15d
  shl    $0x2,%rsi
  shl    $0x2,%rax
  mov    %rsi,%rdx
  sub    %rax,%rdx
  cmp    %rax,%rdx
  jl     L186
  cmp    $0x3,%r13d
  jle    L186
  cmp    $0x7,%r13d
  jle    L210
  mov    %ecx,%edi
  mov    %r12,%rax
  lea    -0x10(%r12,%rsi,1),%rdx
  shr    $0x2,%edi
  sub    $0x1,%edi
  shl    $0x4,%rdi
  lea    0x10(%r12,%rdi,1),%rdi
  nopl   0x0(%rax,%rax,1)
L248:
  movdqu (%rdx),%xmm2
  movdqu (%rax),%xmm0
  add    $0x10,%rax
  sub    $0x10,%rdx
  pshufd $0x1b,%xmm2,%xmm1
  pshufd $0x1b,%xmm0,%xmm0
  movups %xmm1,-0x10(%rax)
  movups %xmm0,0x10(%rdx)
  cmp    %rdi,%rax
  jne    L248
  mov    %ecx,%eax
  and    $0xfffffffc,%eax
  mov    %eax,%edi
  cmp    %eax,%ecx
  je     L301
L325:
  sub    %eax,%ecx
  cmp    $0x1,%ecx
  je     L408
  shl    $0x2,%rax
  sub    $0x8,%rsi
  sub    %rax,%rsi
  lea    (%r12,%rax,1),%rdx
  lea    (%r12,%rsi,1),%rax
  movq   (%rdx),%xmm0
  movq   (%rax),%xmm1
  pshufd $0xe1,%xmm0,%xmm0
  pshufd $0xe1,%xmm1,%xmm1
  movq   %xmm1,(%rdx)
  movq   %xmm0,(%rax)
  mov    %ecx,%eax
  and    $0xfffffffe,%eax
  add    %eax,%edi
  cmp    %eax,%ecx
  je     L301
L408:
  movslq %edi,%rax
  lea    (%r12,%rax,4),%rdx
  mov    %r15d,%eax
  sub    %edi,%eax
  mov    (%rdx),%ecx
  cltq
  lea    (%r12,%rax,4),%rax
  mov    (%rax),%esi
  mov    %esi,(%rdx)
  mov    %ecx,(%rax)
L301:
  mov    0x10(%rsp),%rdx
  mov    %r14d,%edi
  mov    %r12,%rcx
  mov    %r13d,%esi
  call   <do_perfect_match@plt>
  mov    %rax,%rdi
  cmp    $0x2,%ebp
  je     L194
L172:
  test   %r14d,%r14d
  jle    L106
  lea    0x0(%r13,%r14,1),%r10d
  movslq %r14d,%r8
  xor    %ecx,%ecx
  xor    %esi,%esi
  movslq %r10d,%rax
  lea    -0x4(%rdi,%rax,4),%r11
  jmp    L300
  nopl   (%rax)
L426:
  add    $0x1,%esi
L98:
  add    $0x1,%rcx
  cmp    %rcx,%r8
  je     L264
L300:
  mov    (%rdi,%rcx,4),%eax
  mov    %ecx,%r9d
  test   %eax,%eax
  jns    L426
  test   %r13d,%r13d
  jle    L264
  mov    %r11,%rdx
  mov    %r10d,%eax
  jmp    L391
  nopl   0x0(%rax,%rax,1)
L410:
  sub    $0x4,%rdx
  cmp    %r14d,%eax
  je     L264
L391:
  mov    (%rdx),%r15d
  sub    $0x1,%eax
  test   %r15d,%r15d
  jns    L410
  mov    %eax,(%rdi,%rcx,4)
  mov    %r9d,(%rdx)
  mov    (%rdi,%rcx,4),%r9d
  test   %r9d,%r9d
  jns    L98
  nopl   0x0(%rax,%rax,1)
L264:
  cmp    %r14d,%esi
  jge    L106
  cmp    $0x1,%ebp
  jne    L106
  add    0xc(%rsp),%esi
  cmp    %r14d,%esi
  jge    L180
L106:
  lea    -0x1(%r13),%eax
  test   %eax,%eax
  jle    L332
L258:
  xor    %edx,%edx
  movslq %r14d,%r8
  xor    %ecx,%ecx
  xchg   %ax,%ax
L161:
  add    %r8,%rcx
  lea    (%rdi,%rcx,4),%rcx
  nopw   0x0(%rax,%rax,1)
L70:
  mov    (%rcx),%esi
  test   %esi,%esi
  js     L275
  add    $0x1,%edx
  add    $0x4,%rcx
  cmp    %eax,%edx
  jl     L70
L366:
  cmp    $0x2,%ebp
  jne    L332
L15:
  mov    %edx,%r13d
  cmp    %edx,%r14d
  jle    L332
  mov    0xc(%rsp),%eax
  add    %edx,%eax
  cmp    %r14d,%eax
  jl     L332
  nopl   (%rax)
L180:
  movl   $0x1,(%rbx)
  xor    %r13d,%r13d
  jmp    L332
  cs nopw 0x0(%rax,%rax,1)
L275:
  cmp    %edx,%eax
  jle    L366
  movslq %eax,%rcx
  add    %r8,%rcx
  lea    (%rdi,%rcx,4),%rcx
  jmp    L284
L81:
  sub    $0x1,%eax
  sub    $0x4,%rcx
  cmp    %edx,%eax
  je     L366
L284:
  mov    (%rcx),%esi
  test   %esi,%esi
  js     L81
  lea    (%r14,%rdx,1),%r9d
  movslq %r9d,%r9
  lea    (%rdi,%r9,4),%r9
  mov    (%r9),%r10d
  mov    %esi,(%r9)
  movslq %eax,%rsi
  lea    (%r12,%rsi,4),%rsi
  mov    %r10d,(%rcx)
  movslq %edx,%rcx
  mov    (%rsi),%r11d
  lea    (%r12,%rcx,4),%r9
  mov    (%r9),%r10d
  mov    %r11d,(%r9)
  mov    %r10d,(%rsi)
  cmp    %edx,%eax
  jg     L161
  jmp    L366
  nopl   0x0(%rax)
L194:
  mov    %r15d,%eax
  jmp    L258
L186:
  movslq %r15d,%rax
  lea    (%r12,%rax,4),%rdx
  xor    %eax,%eax
  nopl   0x0(%rax)
L147:
  mov    (%rdx),%edi
  mov    (%r12,%rax,4),%esi
  sub    $0x4,%rdx
  mov    %edi,(%r12,%rax,4)
  add    $0x1,%rax
  mov    %esi,0x4(%rdx)
  cmp    %eax,%ecx
  jg     L147
  jmp    L301
L446:
  mov    0x10(%rsp),%rdx
  mov    %eax,%edi
  mov    %r12,%rcx
  mov    %r13d,%esi
  call   <do_perfect_match@plt>
  xor    %edx,%edx
  mov    %rax,%rdi
  cmp    $0x2,%ebp
  jne    L172
  jmp    L15
L210:
  xor    %eax,%eax
  xor    %edi,%edi
  jmp    L325
L347:
  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;
}
```