user: 请将以下的汇编代码转换成C语言代码：

```asm
<write_elements_to_socket>:
  endbr64
  push   %r15
  push   %r14
  mov    %edi,%r14d
  push   %r13
  mov    %esi,%r13d
  push   %r12
  mov    %rdx,%r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  cmp    $0x1770,%esi
  jg     L49
  lea    D29(%rip),%rdi
  call   <puts@plt>
  lea    0x0(,%r13,8),%edx
  mov    %r12,%rsi
  mov    %r14d,%edi
  call   <write_double_array_to_socket@plt>
  test   %eax,%eax
  js     L16
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L49:
  movslq %esi,%rsi
  mov    %r13d,%eax
  lea    D10(%rip),%rdi
  xor    %ebp,%ebp
  imul   $0x57619f1,%rsi,%rsi
  sar    $0x1f,%eax
  xor    %ebx,%ebx
  sar    $0x27,%rsi
  sub    %eax,%esi
  xor    %eax,%eax
  imul   $0x1770,%esi,%r15d
  sub    %r15d,%r13d
  mov    %r13d,%edx
  mov    %r13d,0xc(%rsp)
  call   <printf@plt>
L36:
  mov    $0xbb80,%edi
  call   <malloc@plt>
  mov    %rbp,%rdx
  sub    %rax,%rdx
  mov    %rax,%r13
  lea    0xbb80(%rax),%rcx
  add    %r12,%rdx
L40:
  movsd  (%rdx,%rax,1),%xmm0
  add    $0x8,%rax
  movsd  %xmm0,-0x8(%rax)
  cmp    %rcx,%rax
  jne    L40
  mov    $0xbb80,%edx
  mov    %r13,%rsi
  mov    %r14d,%edi
  add    $0x1770,%ebx
  call   <write_double_array_to_socket@plt>
  xor    %eax,%eax
  add    $0xbb80,%rbp
  call   <sleep_funct2@plt>
  mov    %r13,%rdi
  call   <free@plt>
  cmp    %r15d,%ebx
  jne    L36
  mov    0xc(%rsp),%r13d
  lea    0x0(,%r13,8),%r15d
  mov    %r15d,%edi
  call   <malloc@plt>
  mov    %rax,%rbp
  test   %r13d,%r13d
  je     L9
  lea    -0x1(%r13),%edx
  lea    0x8(%rax,%rdx,8),%rcx
  movslq %ebx,%rdx
  shl    $0x3,%rdx
  sub    %rax,%rdx
  add    %rdx,%r12
L0:
  movsd  (%r12,%rax,1),%xmm0
  add    $0x8,%rax
  movsd  %xmm0,-0x8(%rax)
  cmp    %rcx,%rax
  jne    L0
L9:
  mov    %r14d,%edi
  mov    %r15d,%edx
  mov    %rbp,%rsi
  call   <write_double_array_to_socket@plt>
  add    $0x18,%rsp
  mov    %rbp,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10b0 <free@plt>
L16:
  add    $0x18,%rsp
  lea    D14(%rip),%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1110 <error@plt>
```

tool_calls: name: disassemble_data
arguments: data_tag: D29
data_type: string
name: disassemble_data
arguments: data_tag: D10
data_type: string
name: disassemble_data
arguments: data_tag: D14
data_type: string

tool: D29: transfer all at once..

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


tool: D14: ERROR writing to socket

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);
  }
}
```