// File: /workspace/github_c_makefile_star2_O0/oreparaz[P]dudect/src/dudect.h
// Function: report
static dudect_state_t report(dudect_ctx_t *ctx) {

  #if DUDECT_TRACE
  for (size_t i = 0; i < DUDECT_TESTS; i++) {
    printf(" bucket %zu has %f measurements\n", i, ctx->ttest_ctxs[i]->n[0] +  ctx->ttest_ctxs[i]->n[1]);
  }

  printf("t-test on raw measurements\n");
  report_test(ctx->ttest_ctxs[0]);

  printf("t-test on cropped measurements\n");
  for (size_t i = 0; i < DUDECT_NUMBER_PERCENTILES; i++) {
    report_test(ctx->ttest_ctxs[i + 1]);
  }

  printf("t-test for second order leakage\n");
  report_test(ctx->ttest_ctxs[1 + DUDECT_NUMBER_PERCENTILES]);
  #endif /* DUDECT_TRACE */

  ttest_ctx_t *t = max_test(ctx);
  double max_t = fabs(t_compute(t));
  double number_traces_max_t = t->n[0] +  t->n[1];
  double max_tau = max_t / sqrt(number_traces_max_t);

  // print the number of measurements of the test that yielded max t.
  // sometimes you can see this number go down - this can be confusing
  // but can happen (different test)
  printf("meas: %7.2lf M, ", (number_traces_max_t / 1e6));
  if (number_traces_max_t < DUDECT_ENOUGH_MEASUREMENTS) {
    printf("not enough measurements (%.0f still to go).\n", DUDECT_ENOUGH_MEASUREMENTS-number_traces_max_t);
    return DUDECT_NO_LEAKAGE_EVIDENCE_YET;
  }

  /*
   * We report the following statistics:
   *
   * max_t: the t value
   * max_tau: a t value normalized by sqrt(number of measurements).
   *          this way we can compare max_tau taken with different
   *          number of measurements. This is sort of "distance
   *          between distributions", independent of number of
   *          measurements.
   * (5/tau)^2: how many measurements we would need to barely
   *            detect the leak, if present. "barely detect the
   *            leak" here means have a t value greater than 5.
   *
   * The first metric is standard; the other two aren't (but
   * pretty sensible imho)
   */
  printf("max t: %+7.2f, max tau: %.2e, (5/tau)^2: %.2e.",
    max_t,
    max_tau,
    (double)(5*5)/(double)(max_tau*max_tau));

  if (max_t > t_threshold_bananas) {
    printf(" Definitely not constant time.\n");
    return DUDECT_LEAKAGE_FOUND;
  }
  if (max_t > t_threshold_moderate) {
    printf(" Probably not constant time.\n");
    return DUDECT_LEAKAGE_FOUND;
  }
  if (max_t < t_threshold_moderate) {
    printf(" For the moment, maybe constant time.\n");
  }
  return DUDECT_NO_LEAKAGE_EVIDENCE_YET;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq 0x28(%rsp), %rdi
callq 0x2000
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x20d0
movaps 0x278a7(%rip), %xmm1    # 0x29070
pand %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x20(%rsp), %rax
movsd 0x20(%rax), %xmm0
movq 0x20(%rsp), %rax
addsd 0x28(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x10c0
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
movsd 0x2780d(%rip), %xmm1    # 0x29030
divsd %xmm1, %xmm0
leaq 0x279d2(%rip), %rdi     # 0x29200
movb $0x1, %al
callq 0x1060
movsd 0x277eb(%rip), %xmm0    # 0x29028
ucomisd 0x10(%rsp), %xmm0
jbe 0x186e
movsd 0x277db(%rip), %xmm0    # 0x29028
subsd 0x10(%rsp), %xmm0
leaq 0x279b7(%rip), %rdi     # 0x29211
movb $0x1, %al
callq 0x1060
movl $0x1, 0x34(%rsp)
jmp 0x191e
movsd 0x18(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movsd 0x8(%rsp), %xmm3
mulsd 0x8(%rsp), %xmm3
movsd 0x277b2(%rip), %xmm2    # 0x29040
divsd %xmm3, %xmm2
leaq 0x279a5(%rip), %rdi     # 0x2923e
movb $0x3, %al
callq 0x1060
movsd 0x18(%rsp), %xmm0
movsd 0x2778a(%rip), %xmm1    # 0x29038
ucomisd %xmm1, %xmm0
jbe 0x18cc
leaq 0x279b2(%rip), %rdi     # 0x2926d
movb $0x0, %al
callq 0x1060
movl $0x0, 0x34(%rsp)
jmp 0x191e
movsd 0x18(%rsp), %xmm0
movsd 0x27746(%rip), %xmm1    # 0x29020
ucomisd %xmm1, %xmm0
jbe 0x18f8
leaq 0x279a6(%rip), %rdi     # 0x2928d
movb $0x0, %al
callq 0x1060
movl $0x0, 0x34(%rsp)
jmp 0x191e
movsd 0x27720(%rip), %xmm0    # 0x29020
ucomisd 0x18(%rsp), %xmm0
jbe 0x1916
leaq 0x2799c(%rip), %rdi     # 0x292ab
movb $0x0, %al
callq 0x1060
movl $0x1, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw (%rax,%rax)