user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<ti_trima>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  cvttsd2si (%rdx),%r15d
  test   %r15d,%r15d
  jle    L27
  mov    %edi,%ebp
  mov    %rdx,%rdi
  mov    %rsi,0x8(%rsp)
  mov    (%rsi),%rbx
  mov    (%rcx),%r12
  mov    %rdx,%r13
  mov    %rcx,%r14
  call   <ti_trima_start@plt>
  cmp    %ebp,%eax
  jge    L49
  cmp    $0x2,%r15d
  mov    0x8(%rsp),%rsi
  jle    L84
  mov    %r15d,%eax
  sar    %eax
  lea    0x1(%rax),%esi
  test   $0x1,%r15b
  jne    L99
  imul   %eax,%esi
  pxor   %xmm0,%xmm0
  movsd  D6(%rip),%xmm5
  lea    -0x1(%rax),%edi
  cvtsi2sd %esi,%xmm0
  mov    %eax,%esi
  divsd  %xmm0,%xmm5
L63:
  pxor   %xmm1,%xmm1
  lea    -0x1(%r15),%r8d
  mov    %r15d,%ecx
  xor    %eax,%eax
  mov    %r8,%r9
  sub    %edi,%ecx
  movapd %xmm1,%xmm2
  mov    $0x1,%edx
  movapd %xmm1,%xmm0
  nop
L81:
  pxor   %xmm3,%xmm3
  movsd  (%rbx,%rax,8),%xmm4
  mov    %eax,%r10d
  cvtsi2sd %edx,%xmm3
  mulsd  %xmm4,%xmm3
  addsd  %xmm3,%xmm0
  cmp    %ecx,%eax
  jl     L93
  addsd  %xmm4,%xmm2
L93:
  cmp    %esi,%r10d
  jge    L6
  addsd  %xmm4,%xmm1
L6:
  cmp    %edi,%r10d
  setl   %r10b
  movzbl %r10b,%r10d
  add    %r10d,%edx
  lea    0x1(%rax),%r10d
  cmp    %ecx,%r10d
  setge  %r10b
  add    $0x1,%rax
  movzbl %r10b,%r10d
  sub    %r10d,%edx
  cmp    %rax,%r8
  jne    L81
  mov    %r9d,%eax
  sub    %edi,%eax
  cmp    %r9d,%ebp
  jle    L18
  mov    %ebp,%edi
  cltq
  movslq %esi,%rsi
  sub    %r15d,%edi
  lea    (%rbx,%rax,8),%r9
  movslq %r15d,%r15
  xor    %eax,%eax
  lea    0x1(%rdi),%r8
  lea    (%rbx,%r15,8),%rdx
  lea    (%rbx,%rsi,8),%rsi
  nopl   0x0(%rax,%rax,1)
L97:
  addsd  -0x8(%rdx,%rax,8),%xmm0
  mov    %rax,%rcx
  movapd %xmm0,%xmm3
  mulsd  %xmm5,%xmm3
  movsd  %xmm3,(%r12,%rax,8)
  addsd  -0x8(%rdx,%rax,8),%xmm2
  addsd  %xmm2,%xmm0
  subsd  0x8(%r9,%rax,8),%xmm2
  subsd  %xmm1,%xmm0
  addsd  (%rsi,%rax,8),%xmm1
  subsd  (%rbx,%rax,8),%xmm1
  add    $0x1,%rax
  cmp    %rcx,%rdi
  jne    L97
  lea    (%r12,%r8,8),%r12
L18:
  mov    %r13,%rdi
  sub    (%r14),%r12
  call   <ti_trima_start@plt>
  sar    $0x3,%r12
  xor    %edi,%edi
  sub    %eax,%ebp
  movslq %ebp,%rbp
  cmp    %r12,%rbp
  sete   %dil
  call   <assert@plt>
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L27:
  add    $0x18,%rsp
  mov    $0x1,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L49:
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L99:
  mov    %esi,%edx
  pxor   %xmm0,%xmm0
  movsd  D6(%rip),%xmm5
  mov    %eax,%edi
  imul   %esi,%edx
  cvtsi2sd %edx,%xmm0
  divsd  %xmm0,%xmm5
  jmp    L63
L84:
  add    $0x18,%rsp
  mov    %r14,%rcx
  mov    %r13,%rdx
  mov    %ebp,%edi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1090 <ti_sma@plt>
```

tool_calls: name: retrieve_data
arguments: tag: D6
datatype: f64

tool: D6: 1

assistant: ```c
int ti_trima(int size, double const *const *inputs, double const *options, double *const *outputs) {
  const double *input = inputs[0];
  const int period = (int)options[0];
  double *output = outputs[0];
  if (period < 1)
    return 1;
  if (size <= ti_trima_start(options))
    return 0;
  if (period <= 2)
    return ti_sma(size, inputs, options, outputs);
  double weights = 1 / (double)((period % 2) ? ((period / 2 + 1) * (period / 2 + 1)) : ((period / 2 + 1) * (period / 2)));
  double weight_sum = 0;
  double lead_sum = 0;
  double trail_sum = 0;
  const int lead_period = period % 2 ? period / 2 : period / 2 - 1;
  const int trail_period = lead_period + 1;
  int i, w = 1;
  for (i = 0; i < period - 1; ++i) {
    weight_sum += input[i] * w;
    if (i + 1 > period - lead_period)
      lead_sum += input[i];
    if (i + 1 <= trail_period)
      trail_sum += input[i];
    if (i + 1 < trail_period)
      ++w;
    if (i + 1 >= period - lead_period)
      --w;
  }
  int lsi = (period - 1) - lead_period + 1;
  int tsi1 = (period - 1) - period + 1 + trail_period;
  int tsi2 = (period - 1) - period + 1;
  for (i = period - 1; i < size; ++i) {
    weight_sum += input[i];
    *output++ = weight_sum * weights;
    lead_sum += input[i];
    weight_sum += lead_sum;
    weight_sum -= trail_sum;
    lead_sum -= input[lsi++];
    trail_sum += input[tsi1++];
    trail_sum -= input[tsi2++];
  }
  assert(output - outputs[0] == size - ti_trima_start(options));
  return 0;
}
```