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

```asm
<morphological_feature_calculate_centroids>:
  endbr64
  push   %r15
  mov    %r8,%r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %ecx,%ebx
  lea    0x0(,%rbx,8),%r14d
  sub    $0x28,%rsp
  mov    %rdi,0x10(%rsp)
  mov    %r14d,%edi
  mov    %esi,0x8(%rsp)
  mov    %edx,0xc(%rsp)
  mov    %r9,0x18(%rsp)
  call   <malloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L4
L16:
  mov    %r14d,%edx
  xor    %esi,%esi
  mov    %rbp,%rdi
  call   <memset@plt>
  mov    %r14d,%edi
  call   <malloc@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L67
L47:
  mov    %r14d,%edx
  xor    %esi,%esi
  mov    %r13,%rdi
  call   <memset@plt>
  mov    %r14d,%edi
  call   <malloc@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L42
L17:
  mov    %r14d,%edx
  xor    %esi,%esi
  mov    %r12,%rdi
  call   <memset@plt>
  mov    0x10(%rsp),%r14
  pxor   %xmm1,%xmm1
  mov    %ebx,%ecx
  mov    0xc(%rsp),%edx
  mov    0x8(%rsp),%esi
  movapd %xmm1,%xmm0
  mov    %rbp,%r9
  mov    %r15,%r8
  mov    %r14,%rdi
  call   <morphological_feature_object_moment@plt>
  pxor   %xmm2,%xmm2
  mov    0xc(%rsp),%edx
  mov    %r13,%r9
  movsd  D31(%rip),%xmm0
  mov    %r15,%r8
  mov    %ebx,%ecx
  mov    %r14,%rdi
  mov    0x8(%rsp),%esi
  movapd %xmm2,%xmm1
  call   <morphological_feature_object_moment@plt>
  pxor   %xmm2,%xmm2
  mov    0xc(%rsp),%edx
  mov    %r12,%r9
  mov    D31(%rip),%rax
  mov    0x8(%rsp),%esi
  mov    %r15,%r8
  mov    %ebx,%ecx
  mov    %r14,%rdi
  movapd %xmm2,%xmm0
  movq   %rax,%xmm1
  call   <morphological_feature_object_moment@plt>
  test   %ebx,%ebx
  je     L76
  mov    0x18(%rsp),%rsi
  mov    %rbp,%r8
  mov    %r12,%rdi
  lea    0x0(%r13,%rbx,8),%r9
  mov    %r13,%rax
  sub    %r13,%r8
  sub    %r13,%rdi
  sub    %r13,%rsi
  nopl   (%rax)
L0:
  mov    (%rsi,%rax,1),%rdx
  lea    (%r8,%rax,1),%rcx
  movsd  (%rax),%xmm0
  divsd  (%rcx),%xmm0
  movsd  %xmm0,(%rdx)
  movsd  (%rdi,%rax,1),%xmm0
  add    $0x8,%rax
  divsd  (%rcx),%xmm0
  movsd  %xmm0,0x8(%rdx)
  cmp    %r9,%rax
  jne    L0
L76:
  mov    %rbp,%rdi
  call   <free@plt>
  mov    %r13,%rdi
  call   <free@plt>
  mov    %r12,%rdi
  call   <free@plt>
  add    $0x28,%rsp
  mov    $0x1,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L4:
  mov    %r14d,%esi
  lea    D37(%rip),%rdi
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
  jmp    L16
  xchg   %ax,%ax
L42:
  mov    %r14d,%esi
  lea    D37(%rip),%rdi
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
  jmp    L17
  xchg   %ax,%ax
L67:
  mov    %r14d,%esi
  lea    D37(%rip),%rdi
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
  jmp    L47
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D31
type_infered: f64
name: extract_symbolic_data
arguments: data_tag: D37
type_infered: string

tool: D31: 1

tool: D37: Cannot allocate %d bytes for memory.


assistant: ```c
int morphological_feature_calculate_centroids(int **obj_id, int width, int height, int n_object, unsigned char *image, double **centroids) {
  unsigned int i = 0;
  double *moment00 = NULL;
  moment00 = (double *)malloc(n_object * sizeof(double));
  if (moment00 == NULL) {
    printf("Cannot allocate %d bytes for memory.\n", (n_object * sizeof(double)));
    exit(-1);
  }
  memset(moment00, 0, (n_object * sizeof(double)));
  double *moment10 = NULL;
  moment10 = (double *)malloc(n_object * sizeof(double));
  if (moment10 == NULL) {
    printf("Cannot allocate %d bytes for memory.\n", (n_object * sizeof(double)));
    exit(-1);
  }
  memset(moment10, 0, (n_object * sizeof(double)));
  double *moment01 = NULL;
  moment01 = (double *)malloc(n_object * sizeof(double));
  if (moment01 == NULL) {
    printf("Cannot allocate %d bytes for memory.\n", (n_object * sizeof(double)));
    exit(-1);
  }
  memset(moment01, 0, (n_object * sizeof(double)));
  morphological_feature_object_moment(0.0, 0.0, obj_id, width, height, n_object, image, moment00);
  morphological_feature_object_moment(1.0, 0.0, obj_id, width, height, n_object, image, moment10);
  morphological_feature_object_moment(0.0, 1.0, obj_id, width, height, n_object, image, moment01);
  for (i = 0; i < n_object; i++) {
    centroids[i][0] = moment10[i] / moment00[i];
    centroids[i][1] = moment01[i] / moment00[i];
  }
  free(moment00);
  free(moment10);
  free(moment01);
  return 1;
}
```