user: Please show me the C implementation that matches the assembly code listed below:

```asm
<time_stats>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,%rbp
  mov    %rsi,%r14
  mov    %rcx,%r15
  mov    %r8,0x10(%rsp)
  mov    %r9,0x18(%rsp)
  test   %rdx,%rdx
  je     L12
  mov    %rdx,%rax
  shl    $0x4,%rax
  add    %rax,%rbp
  add    %rdx,%rdx
  sub    %rdx,%r14
L12:
  test   %r14,%r14
  je     L31
  mov    %rbp,%rdx
  mov    %r14,%rsi
  shl    $0x4,%rsi
  add    %rbp,%rsi
  mov    $0x0,%eax
L70:
  imul   $0x3b9aca00,(%rdx),%rcx
  add    0x8(%rdx),%rcx
  add    %rcx,%rax
  add    $0x10,%rdx
  cmp    %rdx,%rsi
  jne    L70
  mov    $0x0,%edx
  div    %r14
  mov    %rax,%rcx
  mov    %rax,%rdx
  shr    $0x9,%rdx
  movabs $0x44b82fa09b5a53,%rsi
  mov    %rdx,%rax
  mul    %rsi
  shr    $0xb,%rdx
  imul   $0x3b9aca00,%rdx,%rsi
  mov    %rcx,%rax
  sub    %rsi,%rax
  mov    %rax,0x8(%r15)
  mov    %rdx,(%r15)
  mov    $0x0,%r12d
  mov    %r12d,%edi
  call   <mpz_init@plt>
  add    $0x8,%rbp
  movq   $0x0,0x8(%rsp)
  jmp    L109
L97:
  sub    (%r15),%r12
  mov    (%rax),%r13
  sub    0x8(%r15),%r13
  mov    $0x0,%ebx
  mov    %ebx,%edi
  call   <mpz_init@plt>
  mov    %r12,%rsi
  mov    %ebx,%edi
  call   <mpz_set_si@plt>
  mov    $0x3b9aca00,%edx
  mov    %ebx,%esi
  mov    %ebx,%edi
  call   <mpz_mul_ui@plt>
  mov    %r13,%rdx
  mov    %ebx,%esi
  mov    %ebx,%edi
  call   <mpz_add_ui@plt>
  mov    %ebx,%edx
  mov    %ebx,%esi
  mov    %ebx,%edi
  call   <mpz_mul@plt>
  mov    %ebx,%edx
  mov    $0x0,%r12d
  mov    %r12d,%esi
  mov    %r12d,%edi
  call   <mpz_add@plt>
  mov    %ebx,%edi
  call   <mpz_clear@plt>
L21:
  mov    0x8(%rsp),%rax
  add    $0x1,%rax
  add    $0x10,%rbp
  cmp    %rax,%r14
  je     L60
  mov    %rax,0x8(%rsp)
L109:
  mov    %rbp,%rax
  mov    -0x8(%rbp),%r12
  test   %r12,%r12
  jne    L97
  cmpq   $0x0,0x0(%rbp)
  je     L21
  jmp    L97
L60:
  cmp    $0x1,%rax
  ja     L37
L48:
  mov    $0x0,%r12d
  mov    %r12d,%esi
  mov    %r12d,%edi
  call   <mpz_sqrt@plt>
  mov    0x10(%rsp),%rbx
  mov    (%rbx),%edi
  call   <mpz_init@plt>
  mov    0x18(%rsp),%r14
  mov    (%r14),%edi
  call   <mpz_init@plt>
  mov    $0x3b9aca00,%ecx
  mov    %r12d,%edx
  mov    (%r14),%esi
  mov    (%rbx),%edi
  call   <mpz_tdiv_qr_ui@plt>
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L37:
  mov    0x8(%rsp),%rbx
  mov    %rbx,%rdx
  shr    %rdx
  mov    $0x0,%r12d
  mov    %r12d,%esi
  mov    %r12d,%edi
  call   <mpz_add_ui@plt>
  mov    %rbx,%rdx
  mov    %r12d,%esi
  mov    %r12d,%edi
  call   <mpz_tdiv_q_ui@plt>
  jmp    L48
L31:
  movq   $0x0,0x8(%r15)
  movq   $0x0,(%r15)
  mov    $0x0,%r12d
  mov    %r12d,%edi
  call   <mpz_init@plt>
  jmp    L48
```

assistant: ```c
void time_stats(const struct timespec *all_times, unsigned long int timecount, unsigned long int cut, struct timespec *avg, mpz_t *q, mpz_t *r) {
  if (cut > 0) {
    all_times += cut;
    timecount -= 2 * cut;
  }
  unsigned long long int temp = 0;
  for (unsigned long int i = 0; i < timecount; ++i)
    temp += all_times[i].tv_sec * 1000000000ull + all_times[i].tv_nsec;
  temp /= timecount;
  avg->tv_nsec = temp % 1000000000ull;
  avg->tv_sec = temp / 1000000000ull;
  mpz_t sumsqdif;
  mpz_init(sumsqdif);
  for (unsigned long int i = 0; i < timecount; ++i)
    if (all_times[i].tv_sec != 0 || all_times[i].tv_nsec != 0) {
      struct timespec dif;
      dif.tv_sec = all_times[i].tv_sec - avg->tv_sec;
      dif.tv_nsec = all_times[i].tv_nsec - avg->tv_nsec;
      if (dif.tv_nsec < 0) {
        dif.tv_nsec += 1000000000;
        --dif.tv_sec;
      }
      mpz_t tmp;
      mpz_init(tmp);
      mpz_set_si(tmp, dif.tv_sec);
      mpz_mul_ui(tmp, tmp, 1000000000);
      mpz_add_ui(tmp, tmp, dif.tv_nsec);
      mpz_mul(tmp, tmp, tmp);
      mpz_add(sumsqdif, sumsqdif, tmp);
      mpz_clear(tmp);
    }
  if (timecount > 1) {
    mpz_add_ui(sumsqdif, sumsqdif, (timecount - 1) / 2);
    mpz_tdiv_q_ui(sumsqdif, sumsqdif, timecount - 1);
  }
  mpz_sqrt(sumsqdif, sumsqdif);
  mpz_init(*q);
  mpz_init(*r);
  mpz_tdiv_qr_ui(*q, *r, sumsqdif, 1000000000);
}
```