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

```asm
<run_sex>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x170,%rsp
  mov    %rdi,-0x168(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    $0x0,%eax
  call   <write_sex_cfg@plt>
  mov    -0x168(%rbp),%rdx
  lea    -0x110(%rbp),%rax
  lea    D3(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <sprintf@plt>
  lea    -0x110(%rbp),%rax
  mov    %rax,%rdi
  call   <system@plt>
  lea    -0x138(%rbp),%rdi
  lea    -0x140(%rbp),%rcx
  lea    -0x148(%rbp),%rdx
  lea    -0x150(%rbp),%rsi
  lea    -0x15c(%rbp),%rax
  mov    %rdi,%r8
  mov    %rax,%rdi
  call   <get_result@plt>
L88:
  pxor   %xmm0,%xmm0
  movsd  %xmm0,-0x130(%rbp)
  pxor   %xmm0,%xmm0
  movsd  %xmm0,-0x128(%rbp)
  movl   $0x0,-0x154(%rbp)
  jmp    L45
L29:
  mov    -0x140(%rbp),%rdx
  mov    -0x154(%rbp),%eax
  cltq
  shl    $0x3,%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  jbe    L28
  mov    -0x138(%rbp),%rdx
  mov    -0x154(%rbp),%eax
  cltq
  shl    $0x3,%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  movsd  -0x130(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x130(%rbp)
  movsd  -0x128(%rbp),%xmm1
  movsd  D13(%rip),%xmm0
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x128(%rbp)
L28:
  addl   $0x1,-0x154(%rbp)
L45:
  mov    -0x15c(%rbp),%eax
  cmp    %eax,-0x154(%rbp)
  jl     L29
  movsd  -0x130(%rbp),%xmm0
  divsd  -0x128(%rbp),%xmm0
  movsd  %xmm0,-0x130(%rbp)
  pxor   %xmm0,%xmm0
  movsd  %xmm0,-0x120(%rbp)
  movl   $0x0,-0x154(%rbp)
  jmp    L37
L53:
  mov    -0x140(%rbp),%rdx
  mov    -0x154(%rbp),%eax
  cltq
  shl    $0x3,%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  jbe    L58
  mov    -0x138(%rbp),%rdx
  mov    -0x154(%rbp),%eax
  cltq
  shl    $0x3,%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  movsd  -0x130(%rbp),%xmm0
  subsd  %xmm1,%xmm0
  movsd  %xmm0,-0x118(%rbp)
  movsd  -0x118(%rbp),%xmm0
  mulsd  %xmm0,%xmm0
  movsd  -0x120(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x120(%rbp)
L58:
  addl   $0x1,-0x154(%rbp)
L37:
  mov    -0x15c(%rbp),%eax
  cmp    %eax,-0x154(%rbp)
  jl     L53
  movsd  -0x128(%rbp),%xmm0
  movsd  D13(%rip),%xmm2
  movapd %xmm0,%xmm1
  subsd  %xmm2,%xmm1
  movsd  -0x120(%rbp),%xmm0
  divsd  %xmm1,%xmm0
  movq   %xmm0,%rax
  movq   %rax,%xmm0
  call   <sqrt@plt>
  movq   %xmm0,%rax
  mov    %rax,-0x120(%rbp)
  movl   $0x0,-0x158(%rbp)
  movl   $0x0,-0x154(%rbp)
  jmp    L149
L101:
  mov    -0x138(%rbp),%rdx
  mov    -0x154(%rbp),%eax
  cltq
  shl    $0x3,%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  movsd  -0x130(%rbp),%xmm0
  subsd  %xmm1,%xmm0
  movsd  %xmm0,-0x118(%rbp)
  mov    -0x140(%rbp),%rdx
  mov    -0x154(%rbp),%eax
  cltq
  shl    $0x3,%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  pxor   %xmm1,%xmm1
  comisd %xmm1,%xmm0
  jbe    L61
  movsd  -0x120(%rbp),%xmm0
  movapd %xmm0,%xmm1
  addsd  %xmm0,%xmm1
  movsd  -0x118(%rbp),%xmm0
  comisd %xmm1,%xmm0
  ja     L19
  movsd  -0x120(%rbp),%xmm1
  movsd  D35(%rip),%xmm0
  mulsd  %xmm1,%xmm0
  comisd -0x118(%rbp),%xmm0
  jbe    L61
L19:
  mov    -0x140(%rbp),%rdx
  mov    -0x154(%rbp),%eax
  cltq
  shl    $0x3,%rax
  add    %rdx,%rax
  pxor   %xmm0,%xmm0
  movsd  %xmm0,(%rax)
  addl   $0x1,-0x158(%rbp)
L61:
  addl   $0x1,-0x154(%rbp)
L149:
  mov    -0x15c(%rbp),%eax
  cmp    %eax,-0x154(%rbp)
  jl     L101
  cmpl   $0x0,-0x158(%rbp)
  jne    L88
  mov    -0x15c(%rbp),%eax
  cmp    $0xa,%eax
  jle    L129
  movsd  -0x130(%rbp),%xmm0
  jmp    L72
L129:
  movsd  D27(%rip),%xmm0
L72:
  movq   %xmm0,%rax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L93
  call   <__stack_chk_fail@plt>
L93:
  movq   %rax,%xmm0
  leave
  ret
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D3
type: string
name: extract_symbolic_data
arguments: data_tag: D13
type: f64
name: extract_symbolic_data
arguments: data_tag: D35
type: byte[8]
name: extract_symbolic_data
arguments: data_tag: D27
type: byte[8]

tool: D3: sex -c _sex.cfg %s

tool: D13: 1

tool: {"D35": [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0]}

tool: {"D27": [0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0xbf]}

assistant: ```c
double run_sex(char *fitsfile) {
  char command[256];
  int N, j, x;
  double *xx, *yy, *F, *Q;
  double S, NN, E, tt;
  write_sex_cfg();
  sprintf(command, "sex -c _sex.cfg %s", fitsfile);
  system(command);
  get_result(&N, &xx, &yy, &F, &Q);
  do {
    S = 0;
    NN = 0;
    for (x = 0; x < N; x++)
      if (F[x] > 0) {
        S += Q[x];
        NN++;
      }
    S /= NN;
    E = 0;
    for (x = 0; x < N; x++)
      if (F[x] > 0) {
        tt = S - Q[x];
        E += tt * tt;
      }
    E = sqrt(E / (NN - 1));
    j = 0;
    for (x = 0; x < N; x++) {
      tt = S - Q[x];
      if (F[x] > 0)
        if ((tt > 2 * E) || (tt < -2 * E)) {
          F[x] = 0;
          j++;
        }
    }
  } while (j);
  if (N > 10)
    return S;
  else
    return -1.0;
}
```