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

```asm
<frequency_distribution>:
  endbr64
  mov    %esi,%eax
  push   %r15
  mov    %edi,%r15d
  mov    %ecx,%edi
  push   %r14
  not    %edi
  mov    %r8d,%r14d
  push   %r13
  shr    $0x1f,%edi
  push   %r12
  push   %rbp
  mov    %esi,%ebp
  push   %rbx
  mov    %edx,%ebx
  cltd
  idiv   %ebx
  sub    $0x28,%rsp
  cmp    %ecx,%ebx
  mov    %ecx,0x14(%rsp)
  mov    %r8d,0x18(%rsp)
  mov    %r9,0x8(%rsp)
  mov    %eax,%r13d
  setg   %al
  mov    %edx,%r12d
  and    %eax,%edi
  call   <assert@plt>
  xor    %edi,%edi
  test   %r15d,%r15d
  setg   %dil
  call   <assert@plt>
  mov    %r14d,%edi
  not    %edi
  shr    $0x1f,%edi
  cmp    %r14d,%ebp
  setge  %al
  mov    %dil,0x10(%rsp)
  and    %eax,%edi
  call   <assert@plt>
  mov    0x60(%rsp),%eax
  movzbl 0x10(%rsp),%edx
  mov    0x14(%rsp),%ecx
  test   %eax,%eax
  jne    L277
  test   %ebx,%ebx
  jle    L107
  mov    0x8(%rsp),%r10
  xor    %eax,%eax
  xor    %edi,%edi
  xor    %r14d,%r14d
  movdqa D18(%rip),%xmm2
  lea    0x10(%r10),%rsi
  nopl   (%rax)
L44:
  xor    %edx,%edx
  cmp    %eax,%r12d
  setg   %dl
  add    %r13d,%edx
  cmp    %eax,%ecx
  je     L140
L226:
  add    $0x1,%eax
  add    %edx,%edi
  cmp    %eax,%ebx
  jne    L44
L280:
  cmp    0x18(%rsp),%r14d
  setle  %dl
L194:
  xor    %edi,%edi
  cmp    %r13d,%r14d
  setge  %dil
  and    %edx,%edi
  call   <assert@plt>
  test   %r12d,%r12d
  setg   %dil
  cmp    %r13d,%r14d
  sete   %al
  or     %eax,%edi
  movzbl %dil,%edi
  call   <assert@plt>
  add    $0x28,%rsp
  mov    %r14d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L277:
  cmpl   $0x1,0x60(%rsp)
  je     L13
  xor    %r14d,%r14d
  cmpl   $0x2,0x60(%rsp)
  jne    L194
  lea    -0x1(%r15,%rbp,1),%esi
  cmp    %esi,%r15d
  jg     L194
  xor    %ebp,%ebp
  mov    $0x1,%eax
  mov    %r13d,0x14(%rsp)
  mov    %r12d,0x1c(%rsp)
  mov    %eax,%r13d
  mov    %ebp,%r12d
  mov    %esi,%ebp
  mov    %ecx,0x10(%rsp)
  jmp    L110
  xchg   %ax,%ax
L141:
  cmp    $0xffffffff,%eax
  je     L172
  mov    %eax,%r12d
L163:
  mov    %r12d,%edi
  not    %edi
  shr    $0x1f,%edi
  cmp    %ebx,%r12d
  setl   %al
  sub    $0x1,%ebp
  and    %eax,%edi
  call   <assert@plt>
  cmp    %ebp,%r15d
  jg     L49
L110:
  cmp    %r12d,0x10(%rsp)
  jne    L36
  mov    0x8(%rsp),%rsi
  movslq %r14d,%rax
  add    $0x1,%r14d
  mov    %ebp,(%rsi,%rax,4)
L36:
  lea    (%r12,%r13,1),%eax
  cmp    %eax,%ebx
  jne    L141
L172:
  neg    %r13d
  jmp    L163
  nopl   0x0(%rax)
L140:
  test   %edx,%edx
  jle    L94
  lea    -0x1(%rdx),%r8d
  lea    (%r15,%rdi,1),%r11d
  cmp    $0x2,%r8d
  jbe    L240
  mov    %edx,%r9d
  movd   %r11d,%xmm4
  movdqa D12(%rip),%xmm1
  mov    %r10,%r8
  shr    $0x2,%r9d
  pshufd $0x0,%xmm4,%xmm3
  sub    $0x1,%r9d
  shl    $0x4,%r9
  add    %rsi,%r9
  nopl   0x0(%rax)
L268:
  movdqa %xmm1,%xmm0
  add    $0x10,%r8
  paddd  %xmm2,%xmm1
  paddd  %xmm3,%xmm0
  movups %xmm0,-0x10(%r8)
  cmp    %r8,%r9
  jne    L268
  mov    %edx,%r8d
  and    $0xfffffffc,%r8d
  test   $0x3,%dl
  je     L94
L216:
  movslq %r8d,%rbp
  lea    (%r8,%r11,1),%r14d
  mov    %r14d,(%r10,%rbp,4)
  lea    0x0(,%rbp,4),%r9
  lea    0x1(%r8),%ebp
  cmp    %ebp,%edx
  jle    L94
  add    %r11d,%ebp
  add    $0x2,%r8d
  mov    %ebp,0x4(%r10,%r9,1)
  cmp    %r8d,%edx
  jle    L94
  add    %r11d,%r8d
  mov    %r8d,0x8(%r10,%r9,1)
L94:
  mov    %edx,%r14d
  jmp    L226
  nopw   0x0(%rax,%rax,1)
L13:
  add    %r15d,%ebp
  cmp    %ebp,%r15d
  jge    L107
  xor    %edx,%edx
  xor    %r14d,%r14d
  lea    0x1(%rcx),%edi
L195:
  cmp    %edx,%ecx
  je     L25
  lea    0x1(%rdx),%eax
  add    $0x1,%r15d
  cltd
  idiv   %ebx
  cmp    %ebp,%r15d
  jne    L195
L23:
  cmp    %r14d,0x18(%rsp)
  setge  %dl
  jmp    L194
L107:
  xor    %r14d,%r14d
  jmp    L194
  nopl   0x0(%rax,%rax,1)
L25:
  mov    0x8(%rsp),%rax
  lea    0x1(%r14),%r9d
  mov    %r15d,(%rax,%r14,4)
  mov    %edi,%eax
  add    $0x1,%r15d
  cltd
  idiv   %ebx
  cmp    %r15d,%ebp
  je     L87
  movslq %r9d,%r14
  jmp    L195
L49:
  mov    0x14(%rsp),%r13d
  mov    0x1c(%rsp),%r12d
  jmp    L280
  nop
L87:
  mov    %r9d,%r14d
  jmp    L23
L240:
  xor    %r8d,%r8d
  jmp    L216
```

tool_calls: name: read_data
arguments: data_label: D18
datatype: byte[16]
name: read_data
arguments: data_label: D12
datatype: byte[16]

tool: {"D18": [0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00]}

tool: {"D12": [0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00]}

assistant: ```c
int frequency_distribution(int nw_low, int nw, int npes, int pe, int maxlw, int *freq_index, int type) {
  int my_n_local_w = 0;
  int min_n_local_w, n_local_w;
  int leftover_w;
  int index = 0, ipe, dpe, iw, i;
  min_n_local_w = nw / npes;
  leftover_w = nw % npes;
  assert(0 <= pe && pe < npes);
  assert(0 < nw_low);
  assert(0 <= maxlw && maxlw <= nw);
  if (type == 0) {
    for (ipe = 0; ipe < npes; ipe++) {
      n_local_w = min_n_local_w + (ipe < leftover_w ? 1 : 0);
      if (pe == ipe) {
        my_n_local_w = n_local_w;
        for (i = 0; i < my_n_local_w; i++) {
          freq_index[i] = nw_low + index + i;
        }
      }
      index += n_local_w;
    }
  } else if (type == 1) {
    ipe = 0;
    for (iw = nw_low; iw < nw + nw_low; iw++) {
      if (ipe == pe)
        freq_index[my_n_local_w++] = iw;
      ipe = (ipe + 1) % npes;
    }
  } else if (type == 2) {
    ipe = 0;
    dpe = 1;
    for (iw = nw - 1 + nw_low; iw >= nw_low; iw--) {
      if (ipe == pe)
        freq_index[my_n_local_w++] = iw;
      ipe += dpe;
      if (ipe == npes || ipe == -1) {
        dpe *= -1;
        ipe += dpe;
      }
      assert(0 <= ipe && ipe < npes);
    }
  }
  assert(min_n_local_w <= my_n_local_w && my_n_local_w <= maxlw);
  assert(leftover_w > 0 || min_n_local_w == my_n_local_w);
  return my_n_local_w;
}
```