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

```asm
<time_stats>:
  endbr64
  push   %r15
  mov    %rcx,%r15
  push   %r14
  push   %r13
  push   %r12
  mov    %rsi,%r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x28,%rsp
  mov    %r8,0x10(%rsp)
  mov    %r9,0x18(%rsp)
  test   %rdx,%rdx
  je     L24
  mov    %rdx,%rax
  add    %rdx,%rdx
  shl    $0x4,%rax
  sub    %rdx,%r12
  add    %rax,%rbx
L24:
  test   %r12,%r12
  je     L21
  mov    %r12,%rsi
  mov    %rbx,%rdx
  xor    %eax,%eax
  shl    $0x4,%rsi
  add    %rbx,%rsi
  nopw   0x0(%rax,%rax,1)
L20:
  imul   $0x3b9aca00,(%rdx),%rcx
  add    $0x10,%rdx
  add    -0x8(%rdx),%rcx
  add    %rcx,%rax
  cmp    %rdx,%rsi
  jne    L20
  xor    %edx,%edx
  xor    %edi,%edi
  xor    %r13d,%r13d
  movabs $0x44b82fa09b5a53,%rsi
  div    %r12
  mov    %rax,%rdx
  mov    %rax,%rcx
  shr    $0x9,%rdx
  mov    %rdx,%rax
  mul    %rsi
  mov    %rcx,%rax
  shr    $0xb,%rdx
  imul   $0x3b9aca00,%rdx,%rsi
  mov    %rdx,(%r15)
  sub    %rsi,%rax
  mov    %rax,0x8(%r15)
  call   <mpz_init@plt>
  jmp    L28
  nopw   0x0(%rax,%rax,1)
L78:
  mov    %rax,%r13
L28:
  mov    (%rbx),%rsi
  mov    0x8(%rbx),%rax
  mov    %rsi,%rcx
  or     %rax,%rcx
  je     L65
  xor    %ebp,%ebp
  sub    (%r15),%rsi
  sub    0x8(%r15),%rax
  mov    %ebp,%edi
  mov    %rsi,0x8(%rsp)
  mov    %rax,%r14
  call   <mpz_init@plt>
  mov    0x8(%rsp),%rsi
  mov    %ebp,%edi
  call   <mpz_set_si@plt>
  mov    $0x3b9aca00,%edx
  mov    %ebp,%esi
  mov    %ebp,%edi
  call   <mpz_mul_ui@plt>
  mov    %r14,%rdx
  mov    %ebp,%esi
  mov    %ebp,%edi
  call   <mpz_add_ui@plt>
  mov    %ebp,%edx
  mov    %ebp,%esi
  mov    %ebp,%edi
  call   <mpz_mul@plt>
  xor    %r8d,%r8d
  mov    %ebp,%edx
  mov    %r8d,%edi
  mov    %r8d,%esi
  call   <mpz_add@plt>
  mov    %ebp,%edi
  call   <mpz_clear@plt>
L65:
  lea    0x1(%r13),%rax
  add    $0x10,%rbx
  cmp    %rax,%r12
  jne    L78
  cmp    $0x1,%r12
  jne    L46
L36:
  xor    %r8d,%r8d
  mov    %r8d,%esi
  mov    %r8d,%edi
  mov    %r8d,0x8(%rsp)
  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    (%r14),%esi
  mov    (%rbx),%edi
  mov    $0x3b9aca00,%ecx
  mov    0x8(%rsp),%edx
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1100 <mpz_tdiv_qr_ui@plt>
  nopw   0x0(%rax,%rax,1)
L46:
  xor    %r8d,%r8d
  mov    %r13,%rdx
  shr    %rdx
  mov    %r8d,%esi
  mov    %r8d,%edi
  mov    %r8d,0x8(%rsp)
  call   <mpz_add_ui@plt>
  mov    0x8(%rsp),%r8d
  mov    %r13,%rdx
  mov    %r8d,%esi
  mov    %r8d,%edi
  call   <mpz_tdiv_q_ui@plt>
  jmp    L36
  nopl   0x0(%rax)
L21:
  movq   $0x0,0x8(%r15)
  xor    %edi,%edi
  movq   $0x0,(%r15)
  call   <mpz_init@plt>
  jmp    L36
```

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);
}
```