user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<ti_tema>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  cvttsd2si (%rdx),%r15d
  mov    $0x1,%eax
  test   %r15d,%r15d
  jle    L57
  mov    %edi,%ebx
  mov    %rdx,%rbp
  mov    %rcx,%r13
  mov    (%rsi),%r12
  mov    (%rcx),%r14
  mov    %rdx,%rdi
  call   <ti_tema_start@plt>
  mov    %eax,%edx
  mov    $0x0,%eax
  cmp    %ebx,%edx
  jge    L57
  pxor   %xmm0,%xmm0
  cvtsi2sd %r15d,%xmm0
  movsd  D20(%rip),%xmm3
  addsd  %xmm3,%xmm0
  movsd  D4(%rip),%xmm2
  divsd  %xmm0,%xmm2
  subsd  %xmm2,%xmm3
  movsd  (%r12),%xmm0
  test   %ebx,%ebx
  jle    L41
  sub    $0x1,%r15d
  lea    (%r15,%r15,1),%esi
  lea    (%rsi,%r15,1),%edi
  lea    -0x1(%rbx),%ecx
  mov    $0x0,%eax
  pxor   %xmm5,%xmm5
  movapd %xmm5,%xmm1
  movsd  D19(%rip),%xmm6
  jmp    L37
L101:
  movapd %xmm0,%xmm1
L118:
  mulsd  %xmm3,%xmm1
  movapd %xmm2,%xmm4
  mulsd  %xmm0,%xmm4
  addsd  %xmm4,%xmm1
  cmp    %edx,%esi
  je     L85
  jle    L112
L18:
  lea    0x1(%rax),%rdx
  cmp    %rcx,%rax
  je     L41
  mov    %rdx,%rax
L37:
  mulsd  %xmm3,%xmm0
  movapd %xmm2,%xmm4
  mulsd  (%r12,%rax,8),%xmm4
  addsd  %xmm4,%xmm0
  mov    %eax,%edx
  cmp    %eax,%r15d
  je     L101
  jg     L18
  jmp    L118
L85:
  movapd %xmm1,%xmm5
L112:
  mulsd  %xmm3,%xmm5
  movapd %xmm2,%xmm4
  mulsd  %xmm1,%xmm4
  addsd  %xmm4,%xmm5
  cmp    %edx,%edi
  jg     L18
  movapd %xmm0,%xmm4
  mulsd  %xmm6,%xmm4
  movapd %xmm1,%xmm7
  mulsd  %xmm6,%xmm7
  subsd  %xmm7,%xmm4
  addsd  %xmm5,%xmm4
  movsd  %xmm4,(%r14)
  add    $0x8,%r14
  jmp    L18
L41:
  sub    0x0(%r13),%r14
  sar    $0x3,%r14
  mov    %rbp,%rdi
  call   <ti_tema_start@plt>
  sub    %eax,%ebx
  movslq %ebx,%rbx
  cmp    %r14,%rbx
  sete   %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    $0x0,%eax
L57:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: retrieve_data
arguments: label: D20
datatype: f64
name: retrieve_data
arguments: label: D4
datatype: f32[2]
name: retrieve_data
arguments: label: D19
datatype: f32[2]

tool: D20: 1

tool: {"D4": [0.0,2.0]}

tool: {"D19": [0.0,2.125]}

assistant: ```c
int ti_tema(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_tema_start(options))
    return 0;
  const double per = 2 / ((double)period + 1);
  const double per1 = 1.0 - per;
  double ema = input[0];
  double ema2 = 0;
  double ema3 = 0;
  int i;
  for (i = 0; i < size; ++i) {
    ema = ema * per1 + input[i] * per;
    if (i == period - 1) {
      ema2 = ema;
    }
    if (i >= period - 1) {
      ema2 = ema2 * per1 + ema * per;
      if (i == (period - 1) * 2) {
        ema3 = ema2;
      }
      if (i >= (period - 1) * 2) {
        ema3 = ema3 * per1 + ema2 * per;
        if (i >= (period - 1) * 3) {
          *output = 3 * ema - 3 * ema2 + ema3;
          ++output;
        }
      }
    }
  }
  assert(output - outputs[0] == size - ti_tema_start(options));
  return 0;
}
```