// File: /workspace/github_c_makefile_star2_O0/millimat[P]Soft-Heap/epsilon-timing.c
// Function: time_insert_extract
void time_insert_extract(int tries, int n) {
  int elts[n];

  int max_r = ceil(-log(1./n)/log(2))+5;
  double cumul_insert[max_r+1];
  double cumul_extract[max_r+1];
  for(int i = 0; i < max_r+1; i++)
    cumul_insert[i] = cumul_extract[i] = 0;

  printf("--------------- Insert-Extract: %d ---------------\n", n);

  for(int i = 0; i < tries; i++) {

    for(int j = 0; j < n; j++)
      elts[j] = rand();

    // go over all relevant values of r(epsilon)
    for(int k = 1; k < n; k *= 2) {
      double epsilon = ((double)k)/n;
      int r = ceil(-log(epsilon)/log(2)) + 5;

      softheap *P = makeheap_empty(epsilon);

      clock_t start = clock();
      for(int j = 0; j < n; j++) {
        insert(P, elts[j]);
      }
      clock_t stop = clock();
      double insert_secs = (double)(stop-start) / CLOCKS_PER_SEC;

      start = clock();
      for(int j = 0; j < n; j++) {
        extract_min(P);
      }
      stop = clock();
      double extract_secs = (double)(stop-start) / CLOCKS_PER_SEC;

      destroy_heap(P);

      cumul_insert[r] += insert_secs;
      cumul_extract[r] += extract_secs;
    }
  }

  for(int i = max_r; i > 5; i--) {
    printf("r=%d \t average insert: %f \t average extract: %f\n", i, cumul_insert[i]/tries, cumul_extract[i]/tries);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl -0x8(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x10(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xb0(%rbp)
movq %rcx, %rsp
movq %rax, -0x18(%rbp)
cvtsi2sdl -0x8(%rbp), %xmm1
movsd 0x1de0(%rip), %xmm0     # 0x3008
divsd %xmm1, %xmm0
callq 0x1070
movaps 0x1df8(%rip), %xmm1     # 0x3030
pxor %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd 0x1dc4(%rip), %xmm0     # 0x3010
callq 0x1070
movaps %xmm0, %xmm1
movsd -0xa8(%rbp), %xmm0
divsd %xmm1, %xmm0
callq 0x10c0
movsd 0x1dab(%rip), %xmm1     # 0x3018
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
incl %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xa0(%rbp)
movq %rcx, %rsp
movq %rax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
incl %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x98(%rbp)
movq %rcx, %rsp
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1307
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rcx
movslq -0x34(%rbp), %rdx
xorps %xmm0, %xmm0
movsd %xmm0, (%rcx,%rdx,8)
movslq -0x34(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x12c9
movl -0x8(%rbp), %esi
leaq 0x1d2f(%rip), %rdi      # 0x3040
movb $0x0, %al
callq 0x1050
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x14ff
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x135a
callq 0x10d0
movl %eax, %edx
movq -0xb0(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1332
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x14ef
cvtsi2sdl -0x40(%rbp), %xmm0
cvtsi2sdl -0x8(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
callq 0x1070
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd 0x1c5f(%rip), %xmm0     # 0x3010
callq 0x1070
movaps %xmm0, %xmm1
movsd -0xb8(%rbp), %xmm0
divsd %xmm1, %xmm0
callq 0x10c0
movsd 0x1c46(%rip), %xmm1     # 0x3018
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x4c(%rbp)
movsd -0x48(%rbp), %xmm0
callq 0x1980
movq %rax, -0x58(%rbp)
callq 0x1040
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1425
movq -0xb0(%rbp), %rax
movq -0x58(%rbp), %rdi
movslq -0x64(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x1bf0
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x13fb
callq 0x1040
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
subq -0x60(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x1bdd(%rip), %xmm1     # 0x3020
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
callq 0x1040
movq %rax, -0x60(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1478
movq -0x58(%rbp), %rdi
callq 0x2010
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x145c
callq 0x1040
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
subq -0x60(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x1b8a(%rip), %xmm1     # 0x3020
divsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x58(%rbp), %rdi
callq 0x1af0
movq -0xa0(%rbp), %rcx
movq -0x98(%rbp), %rax
movsd -0x78(%rbp), %xmm0
movslq -0x4c(%rbp), %rdx
addsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
movsd -0x88(%rbp), %xmm0
movslq -0x4c(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x40(%rbp), %eax
shll %eax
movl %eax, -0x40(%rbp)
jmp 0x1361
jmp 0x14f1
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x131f
movl -0x1c(%rbp), %eax
movl %eax, -0x8c(%rbp)
cmpl $0x5, -0x8c(%rbp)
jle 0x156e
movq -0x98(%rbp), %rax
movq -0xa0(%rbp), %rcx
movl -0x8c(%rbp), %esi
movslq -0x8c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
cvtsi2sdl -0x4(%rbp), %xmm1
divsd %xmm1, %xmm0
movslq -0x8c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
cvtsi2sdl -0x4(%rbp), %xmm2
divsd %xmm2, %xmm1
leaq 0x1b1e(%rip), %rdi      # 0x3074
movb $0x2, %al
callq 0x1050
movl -0x8c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x1508
movq -0x10(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)