user: 请从给定的汇编指令推导出C源代码：

```asm
<EstimateKmeans>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x818,%rsp
  mov    0x1850(%rsp),%rax
  mov    0x1858(%rsp),%r12d
  mov    %r9d,%r13d
  mov    (%rax),%r9d
  imul   0x4(%rax),%r9d
  mov    %rsi,%rbx
  imul   0x8(%rax),%r9d
  mov    %r8,%rsi
  mov    %rsp,%r8
  mov    %rdi,%r11
  mov    %ecx,%r10d
  xor    %eax,%eax
  mov    $0x100,%ecx
  mov    %r8,%rdi
  mov    %rdx,%rbp
  movapd %xmm0,%xmm5
  mov    %fs:0x28,%rdx
  mov    %rdx,0x1808(%rsp)
  xor    %edx,%edx
  rep stos %rax,%es:(%rdi)
  test   %r9d,%r9d
  jle    L398
  test   %r12d,%r12d
  jle    L181
  movsd  D110(%rip),%xmm2
  movsd  D131(%rip),%xmm4
  movslq %r9d,%rcx
  xor    %edx,%edx
  movsd  D130(%rip),%xmm6
  pxor   %xmm3,%xmm3
L14:
  movsd  (%r11,%rdx,8),%xmm0
  movapd %xmm3,%xmm7
  movapd %xmm4,%xmm1
  mulsd  %xmm2,%xmm0
  divsd  %xmm5,%xmm0
  cmplesd %xmm0,%xmm7
  andpd  %xmm7,%xmm1
  andnpd %xmm6,%xmm7
  orpd   %xmm7,%xmm1
  addsd  %xmm1,%xmm0
  cvttsd2si %xmm0,%rax
  test   %eax,%eax
  jle    L193
  movzbl 0x0(%rbp,%rdx,1),%edi
  cmp    0x1860(%rsp),%edi
  jl     L193
  mov    $0xff,%edi
  cmp    %edi,%eax
  cmovg  %edi,%eax
  cltq
  addq   $0x1,(%rsp,%rax,8)
L193:
  add    $0x1,%rdx
  cmp    %rcx,%rdx
  jne    L14
L393:
  mov    $0x8,%eax
  xor    %ecx,%ecx
  movq   $0x0,0x1000(%rsp)
  lea    0x1000(%rsp),%rdx
  nopl   0x0(%rax)
L199:
  add    (%r8,%rax,1),%rcx
  mov    %rcx,(%rdx,%rax,1)
  add    $0x8,%rax
  cmp    $0x800,%rax
  jne    L199
  movsd  D79(%rip),%xmm2
  mov    %rdx,%rax
  lea    0x1800(%rsp),%rcx
  jmp    L3
L411:
  addsd  %xmm4,%xmm0
L146:
  cvttsd2si %xmm0,%rdi
  add    $0x8,%rax
  mov    %rdi,-0x8(%rax)
  cmp    %rcx,%rax
  je     L177
L3:
  pxor   %xmm0,%xmm0
  pxor   %xmm1,%xmm1
  cvtsi2sdq (%rax),%xmm0
  cvtsi2sdq 0x17f8(%rsp),%xmm1
  mulsd  %xmm2,%xmm0
  divsd  %xmm1,%xmm0
  comisd %xmm3,%xmm0
  jae    L411
  subsd  %xmm4,%xmm0
  jmp    L146
L177:
  xor    %eax,%eax
  nopl   0x0(%rax)
L381:
  mov    (%rdx,%rax,1),%rcx
  sub    $0xb,%rcx
  cmp    $0x3d2,%rcx
  jbe    L180
  movq   $0x0,(%r8,%rax,1)
L180:
  add    $0x8,%rax
  cmp    $0x800,%rax
  jne    L381
  movsd  D54(%rip),%xmm6
  xor    %r14d,%r14d
  lea    0x800(%rsp),%rcx
  movslq %r10d,%rdi
L159:
  cmp    %r14d,%r13d
  jle    L338
  test   %r10d,%r10d
  jle    L338
  mov    %rcx,%rdx
  xor    %r15d,%r15d
  nopl   0x0(%rax,%rax,1)
L170:
  pxor   %xmm2,%xmm2
  xor    %eax,%eax
  movapd %xmm6,%xmm1
  cvtsi2sd %r15d,%xmm2
  nop
L161:
  movapd %xmm2,%xmm0
  subsd  (%rsi,%rax,8),%xmm0
  mulsd  %xmm0,%xmm0
  comisd %xmm0,%xmm1
  jbe    L224
  mov    %rax,(%rdx)
  movapd %xmm0,%xmm1
L224:
  add    $0x1,%rax
  cmp    %rdi,%rax
  jne    L161
  add    $0x1,%r15d
  add    $0x8,%rdx
  cmp    $0x100,%r15d
  jne    L170
  xor    %r15d,%r15d
  movapd %xmm3,%xmm7
L417:
  xor    %eax,%eax
  movapd %xmm3,%xmm0
  movapd %xmm3,%xmm1
  nopl   (%rax)
L112:
  cmp    %r15,(%rcx,%rax,8)
  jne    L89
  mov    (%r8,%rax,8),%rdx
  pxor   %xmm2,%xmm2
  cvtsi2sd %rdx,%xmm2
  imul   %rax,%rdx
  addsd  %xmm2,%xmm1
  pxor   %xmm2,%xmm2
  cvtsi2sd %rdx,%xmm2
  addsd  %xmm2,%xmm0
L89:
  add    $0x1,%rax
  cmp    $0x100,%rax
  jne    L112
  comisd %xmm3,%xmm1
  jbe    L298
  divsd  %xmm1,%xmm0
  movapd %xmm0,%xmm1
  subsd  (%rsi,%r15,8),%xmm1
  movsd  %xmm0,(%rsi,%r15,8)
  add    $0x1,%r15
  mulsd  %xmm1,%xmm1
  addsd  %xmm1,%xmm7
  cmp    %r15,%rdi
  jne    L417
  add    $0x1,%r14d
  comisd D48(%rip),%xmm7
  ja     L159
L338:
  movsd  D118(%rip),%xmm7
  movq   D136(%rip),%xmm6
  xor    %r8d,%r8d
  movslq %r10d,%rdi
  nopl   0x0(%rax,%rax,1)
L213:
  xor    %edx,%edx
  test   %r10d,%r10d
  jle    L20
  pxor   %xmm2,%xmm2
  xor    %eax,%eax
  movapd %xmm7,%xmm1
  xor    %edx,%edx
  cvtsi2sd %r8d,%xmm2
L173:
  movapd %xmm2,%xmm0
  subsd  (%rsi,%rax,8),%xmm0
  andpd  %xmm6,%xmm0
  comisd %xmm0,%xmm1
  minsd  %xmm1,%xmm0
  cmova  %eax,%edx
  add    $0x1,%rax
  movapd %xmm0,%xmm1
  cmp    %rax,%rdi
  jne    L173
  movslq %edx,%rdx
L20:
  mov    %rdx,(%rcx,%r8,8)
  add    $0x1,%r8
  cmp    $0x100,%r8
  jne    L213
  movapd %xmm3,%xmm1
  test   %r9d,%r9d
  jle    L305
  movsd  D110(%rip),%xmm2
  movslq %r9d,%r9
  xor    %eax,%eax
  xor    %ecx,%ecx
  movsd  D130(%rip),%xmm7
  test   %r12d,%r12d
  jg     L156
  jmp    L407
L200:
  mov    $0xff,%edi
  pxor   %xmm0,%xmm0
  cmp    %edi,%edx
  cmovg  %edi,%edx
  movslq %edx,%rdi
  cvtsi2sd %edx,%xmm0
  mov    0x800(%rsp,%rdi,8),%r8
  lea    0x1(%r8),%edi
  mov    %dil,(%rbx,%rax,1)
  subsd  (%rsi,%r8,8),%xmm0
  movzbl 0x0(%rbp,%rax,1),%edx
  mulsd  %xmm0,%xmm0
  cmp    %r12d,%edx
  cmovl  %ecx,%edi
  mov    %dil,(%rbx,%rax,1)
  add    $0x1,%rax
  addsd  %xmm0,%xmm1
  cmp    %r9,%rax
  je     L305
L156:
  movsd  (%r11,%rax,8),%xmm0
  movapd %xmm3,%xmm8
  movapd %xmm4,%xmm6
  mulsd  %xmm2,%xmm0
  divsd  %xmm5,%xmm0
  cmplesd %xmm0,%xmm8
  andpd  %xmm8,%xmm6
  andnpd %xmm7,%xmm8
  orpd   %xmm8,%xmm6
  addsd  %xmm6,%xmm0
  cvttsd2si %xmm0,%rdx
  test   %edx,%edx
  jg     L200
  movb   $0x0,(%rbx,%rax,1)
  add    $0x1,%rax
  cmp    %r9,%rax
  jne    L156
L305:
  mov    0x1808(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L310
  add    $0x1818,%rsp
  movapd %xmm1,%xmm0
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L298:
  movapd %xmm3,%xmm0
  subsd  (%rsi,%r15,8),%xmm0
  movq   $0x0,(%rsi,%r15,8)
  add    $0x1,%r15
  mulsd  %xmm0,%xmm0
  addsd  %xmm0,%xmm7
  cmp    %r15,%rdi
  jne    L417
  add    $0x1,%r14d
  comisd D48(%rip),%xmm7
  ja     L159
  jmp    L338
  nopw   0x0(%rax,%rax,1)
L344:
  mov    $0xff,%ecx
  pxor   %xmm0,%xmm0
  cmp    %ecx,%edx
  cmovg  %ecx,%edx
  movslq %edx,%rcx
  cvtsi2sd %edx,%xmm0
  mov    0x800(%rsp,%rcx,8),%rcx
  lea    0x1(%rcx),%edi
  mov    %dil,(%rbx,%rax,1)
  subsd  (%rsi,%rcx,8),%xmm0
  mulsd  %xmm0,%xmm0
  addsd  %xmm0,%xmm1
L248:
  add    $0x1,%rax
  cmp    %rax,%r9
  je     L305
L407:
  movsd  (%r11,%rax,8),%xmm6
  movapd %xmm3,%xmm8
  movapd %xmm4,%xmm0
  mulsd  %xmm2,%xmm6
  divsd  %xmm5,%xmm6
  cmplesd %xmm6,%xmm8
  andpd  %xmm8,%xmm0
  andnpd %xmm7,%xmm8
  orpd   %xmm8,%xmm0
  addsd  %xmm6,%xmm0
  cvttsd2si %xmm0,%rdx
  test   %edx,%edx
  jg     L344
  movb   $0x0,(%rbx,%rax,1)
  jmp    L248
L181:
  lea    -0x1(%r9),%eax
  mov    %r11,%rdx
  pxor   %xmm3,%xmm3
  movsd  D110(%rip),%xmm2
  movsd  D131(%rip),%xmm4
  movsd  D130(%rip),%xmm6
  lea    0x8(%r11,%rax,8),%rcx
L353:
  movsd  (%rdx),%xmm1
  movapd %xmm3,%xmm7
  movapd %xmm4,%xmm0
  mulsd  %xmm2,%xmm1
  divsd  %xmm5,%xmm1
  cmplesd %xmm1,%xmm7
  andpd  %xmm7,%xmm0
  andnpd %xmm6,%xmm7
  orpd   %xmm7,%xmm0
  addsd  %xmm1,%xmm0
  cvttsd2si %xmm0,%rax
  test   %eax,%eax
  jle    L347
  mov    $0xff,%edi
  cmp    %edi,%eax
  cmovg  %edi,%eax
  cltq
  addq   $0x1,(%rsp,%rax,8)
L347:
  add    $0x8,%rdx
  cmp    %rcx,%rdx
  jne    L353
  jmp    L393
L398:
  movsd  D131(%rip),%xmm4
  pxor   %xmm3,%xmm3
  jmp    L393
L310:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: label: D110
data_type: f64
name: retrieve_data
arguments: label: D131
data_type: f64
name: retrieve_data
arguments: label: D130
data_type: f32[2]
name: retrieve_data
arguments: label: D79
data_type: f64
name: retrieve_data
arguments: label: D54
data_type: f32[2]
name: retrieve_data
arguments: label: D48
data_type: f64[2]
name: retrieve_data
arguments: label: D118
data_type: f64
name: retrieve_data
arguments: label: D136
data_type: qword

tool: D110: 255

tool: D131: 0.5

tool: {"D130": [0.0,-1.75]}

tool: D79: 1000

tool: {"D54": [0.0,7.5]}

tool: {"D48": [1.0,0.0]}

tool: D118: 1000000000000000.0

tool: D136: 9223372036854775807

assistant: ```c
double EstimateKmeans(double *src, unsigned char *label, unsigned char *mask, int n_classes, double *mean, int ni, int *dims, int thresh_mask, int thresh_kmeans, double max_src) {
  int i, j, j0, v;
  int count;
  long histo[256], lut[256], cumsum[256], vol;
  double diff, dmin, dx, xnorm, sum;
  vol = dims[0] * dims[1] * dims[2];
  for (i = 0; i < 256; i++)
    histo[i] = 0;
  for (i = 0; i < vol; i++) {
    v = (int)((long)((255.0 * src[i] / max_src) + (((255.0 * src[i] / max_src) >= 0) ? 0.5 : (-0.5))));
    if (v < 1)
      continue;
    if ((thresh_mask > 0) && ((int)mask[i] < thresh_kmeans))
      continue;
    if (v < 0)
      v = 0;
    if (v > 255)
      v = 255;
    histo[v]++;
  }
  cumsum[0] = histo[0];
  for (i = 1; i < 256; i++)
    cumsum[i] = cumsum[i - 1] + histo[i];
  for (i = 0; i < 256; i++)
    cumsum[i] = (long)((long)((1000.0 * (double)cumsum[i] / (double)cumsum[255]) + (((1000.0 * (double)cumsum[i] / (double)cumsum[255]) >= 0) ? 0.5 : (-0.5))));
  for (i = 0; i < 256; i++)
    if ((cumsum[i] <= 10) || (cumsum[i] >= 990))
      histo[i] = 0;
  diff = 1e15;
  count = 0;
  while (diff > 1.0 && count < ni) {
    for (i = 0; i < 256; i++) {
      dmin = 256.0 * 256.0;
      for (j = 0; j < n_classes; j++) {
        dx = (double)i - mean[j];
        dx *= dx;
        if (dx < dmin) {
          lut[i] = j;
          dmin = dx;
        }
      }
    }
    diff = 0;
    for (i = 0; i < n_classes; i++) {
      xnorm = 0.0;
      sum = 0.0;
      for (j = 0; j < 256; j++)
        if (lut[j] == i) {
          xnorm += histo[j];
          sum += j * histo[j];
        }
      sum = xnorm > 0 ? sum /= xnorm : 0.0;
      dx = sum - mean[i];
      mean[i] = sum;
      dx *= dx;
      diff += dx;
    }
    count++;
  }
  for (i = 0; i < 256; i++) {
    dmin = 1e15;
    j0 = 0;
    for (j = 0; j < n_classes; j++) {
      if (fabs((double)i - mean[j]) < dmin) {
        dmin = fabs((double)i - mean[j]);
        j0 = j;
      }
    }
    lut[i] = j0;
  }
  lut[0] = 0;
  diff = 0;
  for (i = 0; i < vol; i++) {
    v = (int)((long)((255.0 * src[i] / max_src) + (((255.0 * src[i] / max_src) >= 0) ? 0.5 : (-0.5))));
    if (v >= 1) {
      if (v < 0)
        v = 0;
      if (v > 255)
        v = 255;
      label[i] = (unsigned char)(lut[v] + 1);
      diff += (((double)v - mean[lut[v]]) * ((double)v - mean[lut[v]]));
      if ((thresh_mask > 0) && ((int)mask[i] < thresh_mask))
        label[i] = 0;
    } else
      label[i] = 0;
  }
  return (diff);
}
```