// File: narula[P]skiplists/skiplist-fanout.cc
// Function: main
int main(int argc, char** argv) {
  srand(time(NULL));
  int LIST_SIZE = atoi(argv[1]);
  int ITERATIONS = 10000;
  int maxl = floor(log(LIST_SIZE)/log(4))+1;
  SkipList* stest2 = SkipList::init_list(LIST_SIZE, maxl);
  assert(stest2);
  if (LIST_SIZE < 99) {
	basic_test(stest2);
	stest2->pretty_print_skiplist();
  }
  stest2->enable_counts();
  timespec ts;
  clock_gettime(CLOCK_MONOTONIC, &ts);
  time_t start = ts.tv_sec*1000000000 + ts.tv_nsec;
  for (int i = 0; i < ITERATIONS; i++) {
	int key = (rand() % LIST_SIZE);
	if (ITERATIONS < 50) printf("key: %d\n", key);
	stest2->lookup(key);
  }
  clock_gettime(CLOCK_MONOTONIC, &ts);
  stest2->disable_counts();
  time_t lookup_time = ts.tv_sec*1000000000 + ts.tv_nsec;
  printf("lookupns: %ld; itr: %d; size: %d; levels: %d; probability: %d; ptr: %d\n", 
		 (lookup_time-start)/(ITERATIONS), ITERATIONS, LIST_SIZE, maxl, FANOUT, stest2->get_ptr_count());
}

// Assembly:
subq $0x78, %rsp
movl $0x0, 0x74(%rsp)
movl %edi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
xorl %eax, %eax
movl %eax, %edi
callq 0x10a0
movl %eax, %edi
callq 0x10b0
movq 0x68(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x10e0
movl %eax, 0x64(%rsp)
movl $0x2710, 0x60(%rsp)     # imm = 0x2710
movl 0x64(%rsp), %edi
callq 0x2b60
movsd %xmm0, 0x20(%rsp)
movl $0x4, %edi
callq 0x2b60
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x10f0
movsd 0x676(%rip), %xmm1      # 0x3008
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x5c(%rsp)
movl 0x64(%rsp), %edi
movl 0x5c(%rsp), %esi
callq 0x1aa0
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x50(%rsp)
je 0x29ba
jmp 0x29d9
leaq 0x748(%rip), %rdi       # 0x3109
leaq 0x65c(%rip), %rsi       # 0x3024
movl $0x16a, %edx            # imm = 0x16A
leaq 0x73c(%rip), %rcx       # 0x3110
callq 0x1070
cmpl $0x63, 0x64(%rsp)
jge 0x29f4
movq 0x50(%rsp), %rdi
callq 0x24b0
movq 0x50(%rsp), %rdi
callq 0x2670
movq 0x50(%rsp), %rdi
callq 0x2b80
movl $0x1, %edi
leaq 0x40(%rsp), %rsi
callq 0x1090
imulq $0x3b9aca00, 0x40(%rsp), %rax # imm = 0x3B9ACA00
addq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x60(%rsp), %eax
jge 0x2a74
callq 0x1050
cltd
idivl 0x64(%rsp)
movl %edx, 0x30(%rsp)
cmpl $0x32, 0x60(%rsp)
jge 0x2a59
movl 0x30(%rsp), %esi
leaq 0x6d5(%rip), %rdi       # 0x3127
movb $0x0, %al
callq 0x1040
movq 0x50(%rsp), %rdi
movl 0x30(%rsp), %esi
callq 0x1310
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x2a28
movl $0x1, %edi
leaq 0x40(%rsp), %rsi
callq 0x1090
movq 0x50(%rsp), %rdi
callq 0x2ba0
imulq $0x3b9aca00, 0x40(%rsp), %rax # imm = 0x3B9ACA00
addq 0x48(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
subq 0x38(%rsp), %rax
movslq 0x60(%rsp), %rcx
cqto
idivq %rcx
movq %rax, 0x8(%rsp)
movl 0x60(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x64(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x50(%rsp), %rdi
callq 0x2bc0
movq 0x8(%rsp), %rsi
movl 0x14(%rsp), %edx
movl 0x18(%rsp), %ecx
movl 0x1c(%rsp), %r8d
leaq 0x63c(%rip), %rdi       # 0x3130
movl $0x4, %r9d
movl %eax, (%rsp)
movb $0x0, %al
callq 0x1040
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopl (%rax)