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

```asm
<ti_trima>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rsi,0x8(%rsp)
  cvttsd2si (%rdx),%r12d
  mov    $0x1,%eax
  test   %r12d,%r12d
  jle    L116
  mov    %edi,%ebp
  mov    %rdx,%r14
  mov    %rcx,%r15
  mov    (%rsi),%rbx
  mov    (%rcx),%r13
  mov    %rdx,%rdi
  call   <ti_trima_start@plt>
  mov    %eax,%edx
  mov    $0x0,%eax
  cmp    %ebp,%edx
  jge    L116
  cmp    $0x2,%r12d
  jle    L124
  test   $0x1,%r12b
  je     L90
  mov    %r12d,%eax
  shr    $0x1f,%eax
  add    %r12d,%eax
  sar    %eax
  mov    %eax,%ecx
  add    $0x1,%eax
  imul   %eax,%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  movsd  D6(%rip),%xmm5
  divsd  %xmm0,%xmm5
L36:
  lea    -0x1(%r12),%r9d
  lea    -0x1(%r12),%r8d
  mov    $0x0,%eax
  mov    $0x1,%edx
  pxor   %xmm1,%xmm1
  movapd %xmm1,%xmm2
  movapd %xmm1,%xmm0
  mov    %r12d,%edi
  sub    %ecx,%edi
  jmp    L56
L124:
  mov    %r15,%rcx
  mov    %r14,%rdx
  mov    0x8(%rsp),%rsi
  mov    %ebp,%edi
  call   <ti_sma@plt>
  jmp    L116
L90:
  mov    %r12d,%ecx
  shr    $0x1f,%ecx
  add    %r12d,%ecx
  sar    %ecx
  lea    0x1(%rcx),%eax
  imul   %ecx,%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  movsd  D6(%rip),%xmm5
  divsd  %xmm0,%xmm5
  sub    $0x1,%ecx
  jmp    L36
L87:
  cmp    %esi,%ecx
  setg   %sil
  movzbl %sil,%esi
  add    %esi,%edx
  lea    0x1(%rax),%esi
  cmp    %esi,%edi
  setle  %sil
  movzbl %sil,%esi
  sub    %esi,%edx
  add    $0x1,%rax
  cmp    %rax,%r8
  je     L71
L56:
  movsd  (%rbx,%rax,8),%xmm4
  pxor   %xmm3,%xmm3
  cvtsi2sd %edx,%xmm3
  mulsd  %xmm4,%xmm3
  addsd  %xmm3,%xmm0
  mov    %eax,%esi
  cmp    %eax,%edi
  jg     L97
  addsd  %xmm4,%xmm2
L97:
  cmp    %esi,%ecx
  jl     L87
  addsd  %xmm4,%xmm1
  jmp    L87
L71:
  mov    %r9d,%eax
  sub    %ecx,%eax
  cmp    %r9d,%ebp
  jle    L111
  mov    %ebp,%edx
  sub    %r12d,%edx
  lea    0x1(%rdx),%rsi
  movslq %r12d,%r12
  lea    (%rbx,%r12,8),%rdi
  cltq
  lea    (%rbx,%rax,8),%r8
  movslq %ecx,%rcx
  lea    (%rbx,%rcx,8),%r9
  mov    $0x0,%eax
L85:
  addsd  -0x8(%rdi,%rax,8),%xmm0
  movapd %xmm5,%xmm3
  mulsd  %xmm0,%xmm3
  movsd  %xmm3,0x0(%r13,%rax,8)
  addsd  -0x8(%rdi,%rax,8),%xmm2
  addsd  %xmm2,%xmm0
  subsd  %xmm1,%xmm0
  subsd  0x8(%r8,%rax,8),%xmm2
  addsd  0x8(%r9,%rax,8),%xmm1
  subsd  (%rbx,%rax,8),%xmm1
  mov    %rax,%rcx
  add    $0x1,%rax
  cmp    %rcx,%rdx
  jne    L85
  lea    0x0(%r13,%rsi,8),%r13
L111:
  sub    (%r15),%r13
  sar    $0x3,%r13
  mov    %r14,%rdi
  call   <ti_trima_start@plt>
  sub    %eax,%ebp
  movslq %ebp,%rbp
  cmp    %r13,%rbp
  sete   %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    $0x0,%eax
L116:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: extract_symbolic_data
arguments: label: D6
data_type: 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;
}
```