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

```asm
<ti_di>:
  endbr64
  push   %r15
  mov    $0x1,%eax
  push   %r14
  mov    %rdx,%r14
  mov    %rcx,%rdx
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  cvttsd2si (%r14),%ecx
  test   %ecx,%ecx
  mov    %ecx,0x8(%rsp)
  jle    L86
  mov    (%rsi),%rbx
  mov    0x8(%rsi),%rbp
  mov    %edi,%r12d
  mov    %r14,%rdi
  mov    0x10(%rsi),%r13
  mov    0x8(%rdx),%rsi
  mov    %rdx,0x18(%rsp)
  mov    (%rdx),%r15
  mov    %rsi,0x10(%rsp)
  call   <ti_di_start@plt>
  mov    %eax,%r8d
  xor    %eax,%eax
  cmp    %r12d,%r8d
  jge    L86
  mov    0x8(%rsp),%ecx
  pxor   %xmm0,%xmm0
  mov    0x10(%rsp),%rsi
  mov    0x18(%rsp),%rdx
  cvtsi2sd %ecx,%xmm0
  cmp    $0x1,%ecx
  movapd %xmm0,%xmm5
  subsd  D22(%rip),%xmm5
  divsd  %xmm0,%xmm5
  je     L101
  lea    -0x1(%rcx),%r8d
  cmp    $0x2,%ecx
  je     L145
  mov    %r8d,%edi
  pxor   %xmm15,%xmm15
  pxor   %xmm6,%xmm6
  xor    %eax,%eax
  shr    %edi
  movapd %xmm15,%xmm3
  movapd %xmm15,%xmm2
  movapd D50(%rip),%xmm7
  shl    $0x4,%rdi
  movapd %xmm15,%xmm1
  pcmpeqd %xmm8,%xmm8
  nop
L172:
  movupd 0x8(%rbx,%rax,1),%xmm9
  movupd 0x0(%r13,%rax,1),%xmm0
  movdqa %xmm8,%xmm13
  movupd 0x8(%rbp,%rax,1),%xmm4
  movupd 0x0(%r13,%rax,1),%xmm14
  movapd %xmm9,%xmm10
  movapd %xmm9,%xmm11
  subpd  %xmm0,%xmm10
  subpd  %xmm4,%xmm11
  movapd %xmm4,%xmm0
  subpd  %xmm14,%xmm0
  movupd 0x0(%rbp,%rax,1),%xmm14
  andpd  %xmm7,%xmm10
  subpd  %xmm4,%xmm14
  maxpd  %xmm11,%xmm10
  andpd  %xmm7,%xmm0
  movapd %xmm14,%xmm4
  maxpd  %xmm10,%xmm0
  addsd  %xmm0,%xmm1
  unpckhpd %xmm0,%xmm0
  addsd  %xmm0,%xmm1
  movupd (%rbx,%rax,1),%xmm0
  add    $0x10,%rax
  subpd  %xmm0,%xmm9
  cmpltpd %xmm9,%xmm4
  movapd %xmm9,%xmm0
  cmpltpd %xmm6,%xmm0
  pxor   %xmm4,%xmm13
  por    %xmm0,%xmm13
  movapd %xmm0,%xmm12
  pandn  %xmm4,%xmm0
  movapd %xmm14,%xmm4
  andnpd %xmm9,%xmm12
  movapd %xmm0,%xmm11
  cmpltpd %xmm6,%xmm4
  andnpd %xmm12,%xmm11
  movdqa %xmm13,%xmm10
  andpd  %xmm0,%xmm9
  orpd   %xmm11,%xmm9
  movapd %xmm0,%xmm11
  pand   %xmm4,%xmm10
  pandn  %xmm13,%xmm4
  andnpd %xmm14,%xmm11
  por    %xmm0,%xmm4
  movapd %xmm9,%xmm0
  andpd  %xmm10,%xmm12
  cmpltpd %xmm11,%xmm0
  movdqa %xmm4,%xmm13
  pand   %xmm0,%xmm13
  pandn  %xmm4,%xmm0
  movapd %xmm10,%xmm4
  andnpd %xmm9,%xmm4
  orpd   %xmm4,%xmm12
  movapd %xmm9,%xmm4
  movapd %xmm0,%xmm9
  andpd  %xmm0,%xmm4
  andnpd %xmm12,%xmm9
  movapd %xmm10,%xmm0
  orpd   %xmm4,%xmm9
  movapd %xmm13,%xmm4
  andnpd %xmm11,%xmm0
  andnpd %xmm9,%xmm4
  addsd  %xmm0,%xmm3
  unpckhpd %xmm0,%xmm0
  addsd  %xmm4,%xmm2
  unpckhpd %xmm4,%xmm4
  addsd  %xmm0,%xmm3
  addsd  %xmm4,%xmm2
  cmp    %rdi,%rax
  jne    L172
  mov    %r8d,%eax
  or     $0x1,%eax
  and    $0x1,%r8d
  je     L110
L127:
  cltq
  movq   D48(%rip),%xmm6
  movsd  0x0(%rbp,%rax,8),%xmm7
  movsd  (%rbx,%rax,8),%xmm0
  lea    0x0(,%rax,8),%rdi
  movsd  -0x8(%r13,%rdi,1),%xmm9
  movapd %xmm0,%xmm8
  movapd %xmm7,%xmm4
  subsd  %xmm9,%xmm4
  subsd  %xmm9,%xmm8
  andpd  %xmm6,%xmm8
  andpd  %xmm4,%xmm6
  movapd %xmm0,%xmm4
  subsd  %xmm7,%xmm4
  subsd  -0x8(%rbx,%rdi,1),%xmm0
  maxsd  %xmm4,%xmm8
  comisd %xmm0,%xmm15
  movsd  -0x8(%rbp,%rdi,1),%xmm4
  subsd  %xmm7,%xmm4
  maxsd  %xmm8,%xmm6
  addsd  %xmm6,%xmm1
  ja     L115
  comisd %xmm4,%xmm0
  jbe    L37
  movapd %xmm15,%xmm4
L153:
  movapd %xmm0,%xmm6
  cmpnltsd %xmm4,%xmm6
  andpd  %xmm6,%xmm0
L165:
  addsd  %xmm0,%xmm2
  addsd  %xmm4,%xmm3
L110:
  movsd  D43(%rip),%xmm7
  movapd %xmm2,%xmm0
  mulsd  %xmm7,%xmm0
  mulsd  %xmm3,%xmm7
L49:
  divsd  %xmm1,%xmm0
  lea    0x8(%r15),%rdi
  lea    0x8(%rsi),%r8
  divsd  %xmm1,%xmm7
  movsd  %xmm0,(%r15)
  movsd  %xmm7,(%rsi)
  cmp    %r12d,%ecx
  jge    L18
  movslq %ecx,%rax
  movq   D48(%rip),%xmm6
  movsd  D43(%rip),%xmm7
  mov    %rax,%r9
  neg    %r9
  shl    $0x3,%r9
  add    %r9,%r15
  add    %r9,%rsi
  jmp    L73
  nopl   0x0(%rax,%rax,1)
L149:
  comisd %xmm4,%xmm0
  jbe    L117
  movapd %xmm15,%xmm4
L122:
  movapd %xmm0,%xmm8
  cmpnltsd %xmm4,%xmm8
  andpd  %xmm8,%xmm0
L182:
  mulsd  %xmm5,%xmm2
  mulsd  %xmm5,%xmm3
  addsd  %xmm0,%xmm2
  addsd  %xmm4,%xmm3
  movapd %xmm2,%xmm0
  mulsd  %xmm7,%xmm0
  divsd  %xmm1,%xmm0
  movsd  %xmm0,0x8(%r15,%rax,8)
  movapd %xmm3,%xmm0
  mulsd  %xmm7,%xmm0
  divsd  %xmm1,%xmm0
  movsd  %xmm0,0x8(%rsi,%rax,8)
  add    $0x1,%rax
  cmp    %eax,%r12d
  jle    L74
L73:
  movsd  0x0(%rbp,%rax,8),%xmm8
  movsd  (%rbx,%rax,8),%xmm0
  mulsd  %xmm5,%xmm1
  movsd  -0x8(%r13,%rax,8),%xmm4
  movapd %xmm0,%xmm10
  movapd %xmm8,%xmm9
  subsd  %xmm4,%xmm10
  subsd  %xmm4,%xmm9
  movapd %xmm0,%xmm4
  subsd  %xmm8,%xmm4
  subsd  -0x8(%rbx,%rax,8),%xmm0
  andpd  %xmm6,%xmm10
  andpd  %xmm6,%xmm9
  maxsd  %xmm4,%xmm10
  comisd %xmm0,%xmm15
  movsd  -0x8(%rbp,%rax,8),%xmm4
  subsd  %xmm8,%xmm4
  maxsd  %xmm10,%xmm9
  addsd  %xmm9,%xmm1
  jbe    L149
  movapd %xmm15,%xmm0
L117:
  comisd %xmm4,%xmm15
  jbe    L122
  movapd %xmm15,%xmm4
  jmp    L182
  nopl   0x0(%rax)
L74:
  lea    -0x1(%r12),%eax
  sub    %ecx,%eax
  lea    0x8(,%rax,8),%rax
  add    %rax,%rdi
  add    %rax,%r8
L18:
  sub    (%rdx),%rdi
  mov    %r8,0x10(%rsp)
  mov    %rdi,%rbx
  mov    %r14,%rdi
  mov    %rdx,0x8(%rsp)
  call   <ti_di_start@plt>
  sar    $0x3,%rbx
  xor    %edi,%edi
  mov    %eax,%r9d
  mov    %r12d,%eax
  sub    %r9d,%eax
  cltq
  cmp    %rbx,%rax
  sete   %dil
  call   <assert@plt>
  mov    0x8(%rsp),%rdx
  mov    0x10(%rsp),%r8
  mov    %r14,%rdi
  sub    0x8(%rdx),%r8
  mov    %r8,%rbx
  call   <ti_di_start@plt>
  sar    $0x3,%rbx
  xor    %edi,%edi
  sub    %eax,%r12d
  movslq %r12d,%r12
  cmp    %rbx,%r12
  sete   %dil
  call   <assert@plt>
  xor    %eax,%eax
L86:
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L115:
  movapd %xmm15,%xmm0
L37:
  comisd %xmm4,%xmm15
  jbe    L153
  movapd %xmm15,%xmm4
  jmp    L165
  nopw   0x0(%rax,%rax,1)
L101:
  pxor   %xmm15,%xmm15
  movapd %xmm15,%xmm7
  movapd %xmm15,%xmm0
  movapd %xmm15,%xmm3
  movapd %xmm15,%xmm2
  movapd %xmm15,%xmm1
  jmp    L49
L145:
  pxor   %xmm15,%xmm15
  mov    $0x1,%eax
  movapd %xmm15,%xmm3
  movapd %xmm15,%xmm2
  movapd %xmm15,%xmm1
  jmp    L127
```

tool_calls: name: retrieve_data
arguments: label: D22
data_type: f32[2]
name: retrieve_data
arguments: label: D50
data_type: qword[2]
name: retrieve_data
arguments: label: D48
data_type: qword
name: retrieve_data
arguments: label: D43
data_type: f64

tool: {"D22": [0.0,1.875]}

tool: {"D50": [0x7fffffffffffffff,0x7fffffffffffffff]}

tool: D48: 9223372036854775807

tool: D43: 100

assistant: ```c
int ti_di(int size, double const *const *inputs, double const *options, double *const *outputs) {
  const double *high = inputs[0];
  const double *low = inputs[1];
  const double *close = inputs[2];
  const int period = (int)options[0];
  double *plus_di = outputs[0];
  double *minus_di = outputs[1];
  if (period < 1)
    return 1;
  if (size <= ti_di_start(options))
    return 0;
  const double per = ((double)period - 1) / ((double)period);
  double atr = 0;
  double dmup = 0;
  double dmdown = 0;
  int i;
  for (i = 1; i < period; ++i) {
    double truerange;
    do {
      const double l = low[i];
      const double h = high[i];
      const double c = close[i - 1];
      const double ych = fabs(h - c);
      const double ycl = fabs(l - c);
      double v = h - l;
      if (ych > v)
        v = ych;
      if (ycl > v)
        v = ycl;
      truerange = v;
    } while (0);
    atr += truerange;
    double dp, dm;
    do {
      dp = high[i] - high[i - 1];
      dm = low[i - 1] - low[i];
      if (dp < 0)
        dp = 0;
      else if (dp > dm)
        dm = 0;
      if (dm < 0)
        dm = 0;
      else if (dm > dp)
        dp = 0;
    } while (0);
    dmup += dp;
    dmdown += dm;
  }
  *plus_di++ = 100.0 * dmup / atr;
  *minus_di++ = 100.0 * dmdown / atr;
  for (i = period; i < size; ++i) {
    double truerange;
    do {
      const double l = low[i];
      const double h = high[i];
      const double c = close[i - 1];
      const double ych = fabs(h - c);
      const double ycl = fabs(l - c);
      double v = h - l;
      if (ych > v)
        v = ych;
      if (ycl > v)
        v = ycl;
      truerange = v;
    } while (0);
    atr = atr * per + truerange;
    double dp, dm;
    do {
      dp = high[i] - high[i - 1];
      dm = low[i - 1] - low[i];
      if (dp < 0)
        dp = 0;
      else if (dp > dm)
        dm = 0;
      if (dm < 0)
        dm = 0;
      else if (dm > dp)
        dp = 0;
    } while (0);
    dmup = dmup * per + dp;
    dmdown = dmdown * per + dm;
    *plus_di++ = 100.0 * dmup / atr;
    *minus_di++ = 100.0 * dmdown / atr;
  }
  assert(plus_di - outputs[0] == size - ti_di_start(options));
  assert(minus_di - outputs[1] == size - ti_di_start(options));
  return 0;
}
```