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

```asm
<write_elements_to_socket>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %edi,%r15d
  mov    %esi,%r13d
  mov    %rdx,0x8(%rsp)
  cmp    $0x1770,%esi
  jg     L31
  mov    %rdx,%rbx
  lea    D16(%rip),%rdi
  call   <puts@plt>
  lea    0x0(,%r13,8),%edx
  mov    %rbx,%rsi
  mov    %r15d,%edi
  call   <write_double_array_to_socket@plt>
  test   %eax,%eax
  jns    L20
  lea    D17(%rip),%rdi
  call   <error@plt>
  jmp    L20
L31:
  movslq %esi,%r14
  imul   $0x57619f1,%r14,%r14
  sar    $0x27,%r14
  mov    %esi,%eax
  sar    $0x1f,%eax
  sub    %eax,%r14d
  imul   $0x1770,%r14d,%eax
  sub    %eax,%r13d
  mov    %r13d,%edx
  mov    %r14d,%esi
  lea    D20(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  imul   $0x1770,%r14d,%r14d
  mov    $0x0,%r12d
  mov    $0x0,%ebp
L39:
  mov    $0xbb80,%edi
  call   <malloc@plt>
  mov    %rax,%rbx
  lea    0xbb80(%rax),%rcx
  mov    %r12,%rdx
  sub    %rax,%rdx
  add    0x8(%rsp),%rdx
L30:
  movsd  (%rdx,%rax,1),%xmm0
  movsd  %xmm0,(%rax)
  add    $0x8,%rax
  cmp    %rcx,%rax
  jne    L30
  add    $0x1770,%ebp
  mov    $0xbb80,%edx
  mov    %rbx,%rsi
  mov    %r15d,%edi
  call   <write_double_array_to_socket@plt>
  mov    $0x0,%eax
  call   <sleep_funct2@plt>
  mov    %rbx,%rdi
  call   <free@plt>
  add    $0xbb80,%r12
  cmp    %r14d,%ebp
  jne    L39
  lea    0x0(,%r13,8),%r12d
  mov    %r12d,%edi
  call   <malloc@plt>
  mov    %rax,%rbx
  test   %r13d,%r13d
  jle    L59
  mov    %r13d,%r13d
  lea    (%rax,%r13,8),%rcx
  movslq %ebp,%rbp
  mov    0x8(%rsp),%rsi
  lea    (%rsi,%rbp,8),%rdx
  sub    %rax,%rdx
L53:
  movsd  (%rdx,%rax,1),%xmm0
  movsd  %xmm0,(%rax)
  add    $0x8,%rax
  cmp    %rax,%rcx
  jne    L53
L59:
  mov    %r12d,%edx
  mov    %rbx,%rsi
  mov    %r15d,%edi
  call   <write_double_array_to_socket@plt>
  mov    %rbx,%rdi
  call   <free@plt>
L20:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D16
type_infered: string
name: extract_symbolic_data
arguments: data_tag: D17
type_infered: string
name: extract_symbolic_data
arguments: data_tag: D20
type_infered: string

tool: D16: transfer all at once..

tool: D17: ERROR writing to socket

tool: D20: server: nchunks = %d and nleftover = %d


assistant: ```c
void write_elements_to_socket(int sockfd, int nelements, double *elements_all) {
  int i, ind, nlen, nchunks, nleftover, chunk_num;
  double *elements_local;
  if (nelements <= 6000) {
    printf("transfer all at once..\n");
    nlen = write_double_array_to_socket(sockfd, elements_all, nelements * sizeof(double));
    if (nlen < 0)
      error("ERROR writing to socket");
  } else {
    nchunks = nelements / 6000;
    nleftover = nelements % 6000;
    printf("server: nchunks = %d and nleftover = %d\n", nchunks, nleftover);
    ind = 0;
    for (chunk_num = 0; chunk_num < nchunks; chunk_num++) {
      elements_local = (double *)malloc(6000 * sizeof(double));
      for (i = 0; i < 6000; i++) {
        elements_local[i] = elements_all[ind++];
      }
      nlen = write_double_array_to_socket(sockfd, elements_local, 6000 * sizeof(double));
      sleep_funct2();
      free(elements_local);
    }
    elements_local = (double *)malloc(nleftover * sizeof(double));
    for (i = 0; i < nleftover; i++) {
      elements_local[i] = elements_all[ind++];
    }
    nlen = write_double_array_to_socket(sockfd, elements_local, nleftover * sizeof(double));
    free(elements_local);
  }
}
```