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    L13
  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    L118
  cmp    $0x2,%r15d
  mov    0x8(%rsp),%rsi
  jle    L69
  mov    %r15d,%eax
  sar    %eax
  lea    0x1(%rax),%esi
  test   $0x1,%r15b
  jne    L87
  imul   %eax,%esi
  pxor   %xmm0,%xmm0
  lea    -0x1(%rax),%r8d
  mov    %r15d,%edi
  movsd  D7(%rip),%xmm5
  sub    %r8d,%edi
  lea    -0x1(%r15),%r10d
  cvtsi2sd %esi,%xmm0
  mov    %eax,%esi
  divsd  %xmm0,%xmm5
  test   %edi,%edi
  jle    L74
L76:
  cmp    %edi,%r10d
  pxor   %xmm1,%xmm1
  mov    %edi,%r11d
  mov    $0x1,%edx
  cmovle %r10d,%r11d
  movapd %xmm1,%xmm2
  xor    %ecx,%ecx
  xor    %eax,%eax
  movapd %xmm1,%xmm0
  nopw   0x0(%rax,%rax,1)
L51:
  pxor   %xmm3,%xmm3
  movsd  (%rbx,%rcx,8),%xmm4
  cvtsi2sd %edx,%xmm3
  mulsd  %xmm4,%xmm3
  addsd  %xmm3,%xmm0
  cmp    %eax,%esi
  jle    L101
  addsd  %xmm4,%xmm2
L101:
  add    $0x1,%eax
  xor    %r9d,%r9d
  cmp    %ecx,%r8d
  setg   %r9b
  add    %r9d,%edx
  xor    %r9d,%r9d
  cmp    %edi,%eax
  setge  %r9b
  add    $0x1,%rcx
  sub    %r9d,%edx
  cmp    %r11d,%eax
  jl     L51
  cmp    %r10d,%eax
  jge    L7
L75:
  cltq
  nopl   0x0(%rax)
L32:
  pxor   %xmm3,%xmm3
  movsd  (%rbx,%rax,8),%xmm4
  mov    %eax,%ecx
  cvtsi2sd %edx,%xmm3
  addsd  %xmm4,%xmm1
  mulsd  %xmm4,%xmm3
  addsd  %xmm3,%xmm0
  cmp    %esi,%eax
  jge    L124
  addsd  %xmm4,%xmm2
L124:
  cmp    %r8d,%ecx
  setl   %cl
  movzbl %cl,%ecx
  add    %ecx,%edx
  lea    0x1(%rax),%ecx
  cmp    %ecx,%edi
  setle  %cl
  add    $0x1,%rax
  movzbl %cl,%ecx
  sub    %ecx,%edx
  cmp    %eax,%r10d
  jg     L32
L7:
  mov    %r10d,%eax
  sub    %r8d,%eax
  cmp    %r10d,%ebp
  jle    L45
  mov    %ebp,%ecx
  cltq
  movslq %esi,%rsi
  sub    %r15d,%ecx
  lea    (%rbx,%rax,8),%r8
  movslq %r15d,%r15
  xor    %eax,%eax
  lea    0x1(%rcx),%rdi
  lea    (%rbx,%r15,8),%rdx
  lea    (%rbx,%rsi,8),%r9
  cs nopw 0x0(%rax,%rax,1)
L11:
  addsd  -0x8(%rdx,%rax,8),%xmm0
  mov    %rax,%rsi
  movapd %xmm0,%xmm3
  mulsd  %xmm5,%xmm3
  movsd  %xmm3,(%r12,%rax,8)
  addsd  -0x8(%rdx,%rax,8),%xmm1
  addsd  %xmm1,%xmm0
  subsd  0x8(%r8,%rax,8),%xmm1
  subsd  %xmm2,%xmm0
  addsd  (%r9,%rax,8),%xmm2
  subsd  (%rbx,%rax,8),%xmm2
  add    $0x1,%rax
  cmp    %rsi,%rcx
  jne    L11
  lea    (%r12,%rdi,8),%r12
L45:
  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
  nopw   0x0(%rax,%rax,1)
L13:
  add    $0x18,%rsp
  mov    $0x1,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L118:
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L87:
  mov    %esi,%edx
  pxor   %xmm0,%xmm0
  mov    %eax,%r8d
  mov    %r15d,%edi
  imul   %esi,%edx
  movsd  D7(%rip),%xmm5
  sub    %r8d,%edi
  lea    -0x1(%r15),%r10d
  cvtsi2sd %edx,%xmm0
  divsd  %xmm0,%xmm5
  test   %edi,%edi
  jg     L76
L74:
  pxor   %xmm1,%xmm1
  mov    $0x1,%edx
  xor    %eax,%eax
  movapd %xmm1,%xmm2
  movapd %xmm1,%xmm0
  jmp    L75
  cs nopw 0x0(%rax,%rax,1)
L69:
  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: extract_symbolic_data
arguments: label: D7
type: f64

tool: D7: 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;
}
```