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

```asm
<avg_dist_interval>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %edi,-0x34(%rbp)
  mov    %esi,-0x38(%rbp)
  mov    %edx,-0x3c(%rbp)
  mov    %ecx,-0x40(%rbp)
  pxor   %xmm0,%xmm0
  movsd  %xmm0,-0x18(%rbp)
  mov    -0x34(%rbp),%edx
  mov    -0x38(%rbp),%eax
  add    %edx,%eax
  sub    $0x1,%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  movsd  %xmm0,-0x28(%rbp)
  pxor   %xmm0,%xmm0
  cvtsi2sdl -0x34(%rbp),%xmm0
  movapd %xmm0,%xmm1
  addsd  -0x28(%rbp),%xmm1
  movsd  D56(%rip),%xmm0
  mulsd  %xmm1,%xmm0
  movsd  %xmm0,-0x10(%rbp)
  mov    -0x3c(%rbp),%edx
  mov    -0x40(%rbp),%eax
  add    %edx,%eax
  sub    $0x1,%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  movsd  %xmm0,-0x20(%rbp)
  pxor   %xmm0,%xmm0
  cvtsi2sdl -0x3c(%rbp),%xmm0
  movapd %xmm0,%xmm1
  addsd  -0x20(%rbp),%xmm1
  movsd  D56(%rip),%xmm0
  mulsd  %xmm1,%xmm0
  movsd  %xmm0,-0x8(%rbp)
  pxor   %xmm0,%xmm0
  cvtsi2sdl -0x34(%rbp),%xmm0
  comisd -0x20(%rbp),%xmm0
  ja     L85
  pxor   %xmm0,%xmm0
  cvtsi2sdl -0x3c(%rbp),%xmm0
  comisd -0x28(%rbp),%xmm0
  jbe    L49
L85:
  movsd  -0x10(%rbp),%xmm0
  subsd  -0x8(%rbp),%xmm0
  movq   D169(%rip),%xmm1
  andpd  %xmm1,%xmm0
  movsd  %xmm0,-0x18(%rbp)
  jmp    L87
L49:
  movsd  -0x28(%rbp),%xmm0
  comisd -0x20(%rbp),%xmm0
  jbe    L3
  pxor   %xmm2,%xmm2
  cvtsi2sdl -0x3c(%rbp),%xmm2
  movsd  -0x20(%rbp),%xmm0
  movapd %xmm0,%xmm1
  subsd  %xmm2,%xmm1
  movsd  D64(%rip),%xmm0
  addsd  %xmm0,%xmm1
  movsd  D56(%rip),%xmm0
  mulsd  %xmm0,%xmm1
  movsd  -0x28(%rbp),%xmm0
  subsd  -0x20(%rbp),%xmm0
  mulsd  %xmm0,%xmm1
  pxor   %xmm3,%xmm3
  cvtsi2sdl -0x3c(%rbp),%xmm3
  movsd  -0x28(%rbp),%xmm0
  movapd %xmm0,%xmm2
  subsd  %xmm3,%xmm2
  movsd  D64(%rip),%xmm0
  addsd  %xmm2,%xmm0
  mulsd  %xmm1,%xmm0
  movsd  -0x18(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x18(%rbp)
  movsd  -0x20(%rbp),%xmm0
  movsd  %xmm0,-0x28(%rbp)
  jmp    L58
L3:
  movsd  -0x20(%rbp),%xmm0
  comisd -0x28(%rbp),%xmm0
  jbe    L58
  pxor   %xmm2,%xmm2
  cvtsi2sdl -0x34(%rbp),%xmm2
  movsd  -0x28(%rbp),%xmm0
  movapd %xmm0,%xmm1
  subsd  %xmm2,%xmm1
  movsd  D64(%rip),%xmm0
  addsd  %xmm0,%xmm1
  movsd  D56(%rip),%xmm0
  mulsd  %xmm0,%xmm1
  movsd  -0x20(%rbp),%xmm0
  subsd  -0x28(%rbp),%xmm0
  mulsd  %xmm0,%xmm1
  pxor   %xmm3,%xmm3
  cvtsi2sdl -0x34(%rbp),%xmm3
  movsd  -0x20(%rbp),%xmm0
  movapd %xmm0,%xmm2
  subsd  %xmm3,%xmm2
  movsd  D64(%rip),%xmm0
  addsd  %xmm2,%xmm0
  mulsd  %xmm1,%xmm0
  movsd  -0x18(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x18(%rbp)
  movsd  -0x28(%rbp),%xmm0
  movsd  %xmm0,-0x20(%rbp)
L58:
  mov    -0x34(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jge    L61
  pxor   %xmm2,%xmm2
  cvtsi2sdl -0x3c(%rbp),%xmm2
  movsd  -0x20(%rbp),%xmm0
  movapd %xmm0,%xmm1
  subsd  %xmm2,%xmm1
  movsd  D64(%rip),%xmm0
  addsd  %xmm0,%xmm1
  movsd  D56(%rip),%xmm0
  mulsd  %xmm0,%xmm1
  mov    -0x3c(%rbp),%eax
  sub    -0x34(%rbp),%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  mulsd  %xmm0,%xmm1
  pxor   %xmm3,%xmm3
  cvtsi2sdl -0x34(%rbp),%xmm3
  movsd  -0x20(%rbp),%xmm0
  movapd %xmm0,%xmm2
  subsd  %xmm3,%xmm2
  movsd  D64(%rip),%xmm0
  addsd  %xmm2,%xmm0
  mulsd  %xmm1,%xmm0
  movsd  -0x18(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x18(%rbp)
  mov    -0x3c(%rbp),%eax
  mov    %eax,-0x34(%rbp)
  jmp    L15
L61:
  mov    -0x3c(%rbp),%eax
  cmp    -0x34(%rbp),%eax
  jge    L15
  pxor   %xmm2,%xmm2
  cvtsi2sdl -0x34(%rbp),%xmm2
  movsd  -0x28(%rbp),%xmm0
  movapd %xmm0,%xmm1
  subsd  %xmm2,%xmm1
  movsd  D64(%rip),%xmm0
  addsd  %xmm0,%xmm1
  movsd  D56(%rip),%xmm0
  mulsd  %xmm0,%xmm1
  mov    -0x34(%rbp),%eax
  sub    -0x3c(%rbp),%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  mulsd  %xmm0,%xmm1
  pxor   %xmm3,%xmm3
  cvtsi2sdl -0x3c(%rbp),%xmm3
  movsd  -0x28(%rbp),%xmm0
  movapd %xmm0,%xmm2
  subsd  %xmm3,%xmm2
  movsd  D64(%rip),%xmm0
  addsd  %xmm2,%xmm0
  mulsd  %xmm1,%xmm0
  movsd  -0x18(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x18(%rbp)
  mov    -0x34(%rbp),%eax
  mov    %eax,-0x3c(%rbp)
L15:
  pxor   %xmm2,%xmm2
  cvtsi2sdl -0x34(%rbp),%xmm2
  movsd  -0x28(%rbp),%xmm0
  movapd %xmm0,%xmm1
  subsd  %xmm2,%xmm1
  pxor   %xmm3,%xmm3
  cvtsi2sdl -0x34(%rbp),%xmm3
  movsd  -0x28(%rbp),%xmm0
  movapd %xmm0,%xmm2
  subsd  %xmm3,%xmm2
  movsd  D64(%rip),%xmm0
  addsd  %xmm2,%xmm0
  mulsd  %xmm0,%xmm1
  pxor   %xmm3,%xmm3
  cvtsi2sdl -0x34(%rbp),%xmm3
  movsd  -0x28(%rbp),%xmm0
  movapd %xmm0,%xmm2
  subsd  %xmm3,%xmm2
  movsd  D11(%rip),%xmm0
  addsd  %xmm2,%xmm0
  mulsd  %xmm1,%xmm0
  movsd  D138(%rip),%xmm1
  divsd  %xmm1,%xmm0
  movsd  -0x18(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x18(%rbp)
  mov    -0x38(%rbp),%eax
  imul   -0x40(%rbp),%eax
  pxor   %xmm1,%xmm1
  cvtsi2sd %eax,%xmm1
  movsd  -0x18(%rbp),%xmm0
  divsd  %xmm1,%xmm0
  movsd  %xmm0,-0x18(%rbp)
L87:
  movsd  -0x18(%rbp),%xmm0
  movq   %xmm0,%rax
  movq   %rax,%xmm0
  pop    %rbp
  ret
```

tool_calls: name: unpack_data
arguments: data_tag: D56
data_type: byte[8]
name: unpack_data
arguments: data_tag: D169
data_type: qword
name: unpack_data
arguments: data_tag: D64
data_type: byte[8]
name: unpack_data
arguments: data_tag: D11
data_type: byte[8]
name: unpack_data
arguments: data_tag: D138
data_type: f64

tool: {"D56": [0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x3f]}

tool: D169: 9223372036854775807

tool: {"D64": [0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f]}

tool: {"D11": [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40]}

tool: D138: 3

assistant: ```c
double avg_dist_interval(int set1_low, int set1_span, int set2_low, int set2_span) {
  double set1_high;
  double set1_avg;
  double set2_high;
  double set2_avg;
  double val;
  val = 0;
  set1_high = set1_low + set1_span - 1;
  set1_avg = .5 * (set1_high + set1_low);
  set2_high = set2_low + set2_span - 1;
  set2_avg = .5 * (set2_high + set2_low);
  if (set1_low > set2_high || set2_low > set1_high) {
    val = fabs(set1_avg - set2_avg);
  } else {
    if (set1_high > set2_high) {
      val += .5 * (set2_high - set2_low + 1) * (set1_high - set2_high) * (set1_high - set2_low + 1);
      set1_high = set2_high;
    } else if (set2_high > set1_high) {
      val += .5 * (set1_high - set1_low + 1) * (set2_high - set1_high) * (set2_high - set1_low + 1);
      set2_high = set1_high;
    }
    if (set1_low < set2_low) {
      val += .5 * (set2_high - set2_low + 1) * (set2_low - set1_low) * (set2_high - set1_low + 1);
      set1_low = set2_low;
    } else if (set2_low < set1_low) {
      val += .5 * (set1_high - set1_low + 1) * (set1_low - set2_low) * (set1_high - set2_low + 1);
      set2_low = set1_low;
    }
    val += (set1_high - set1_low) * (set1_high - set1_low + 1) * (set1_high - set1_low + 2) / 3.0;
    val /= set1_span * set2_span;
  }
  return (val);
}
```