// File: narula[P]skiplists/skiplist.cc
// Function: main
int main(int argc, char** argv) {
  if (argc < 2) {
	basic_test();
	return 0;
  }
  srand(time(NULL));
  int LIST_SIZE = atoi(argv[1]);
  int PROBABILITY = atoi(argv[2]);
  int POOL = 3*LIST_SIZE;
  int ITERATIONS = 10000;
  int seconds = 10;
  SkipList* stest2 = SkipList::init_list(LIST_SIZE, POOL, PROBABILITY);
  assert(stest2);
  timespec ts;
  if (LIST_SIZE < 100) {
	stest2->pretty_print_skiplist();
  }
  stest2->enable_counts();
  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() % POOL);
	if (ITERATIONS < 50) printf("key: %d\n", key);
	stest2->lookup(key);
  }
  clock_gettime(CLOCK_MONOTONIC, &ts);
  time_t lookup_time = ts.tv_sec*1000000000 + ts.tv_nsec;
  stest2->disable_counts();
  for (int i = LIST_SIZE; i < LIST_SIZE+ITERATIONS; i++) {
	stest2->insert(rand() % POOL);
  }
  clock_gettime(CLOCK_MONOTONIC, &ts);
  time_t insert_time = ts.tv_sec*1000000000 + ts.tv_nsec;

  printf("insert: %ld; lookup: %ld; itr: %d; size: %d; levels: %d; probability: %d; ptr: %d\n", 
		 (insert_time-lookup_time)/(ITERATIONS), (lookup_time-start)/(ITERATIONS), ITERATIONS, LIST_SIZE, int(floor(log(LIST_SIZE)/log(PROBABILITY))), PROBABILITY, stest2->get_ptr_count());
}

// Assembly:
subq $0xa8, %rsp
movl $0x0, 0xa4(%rsp)
movl %edi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
cmpl $0x2, 0xa0(%rsp)
jge 0x2080
callq 0x1d50
movl $0x0, 0xa4(%rsp)
jmp 0x2337
xorl %eax, %eax
movl %eax, %edi
callq 0x1090
movl %eax, %edi
callq 0x10a0
movq 0x98(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x10d0
movl %eax, 0x94(%rsp)
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x10d0
movl %eax, 0x90(%rsp)
imull $0x3, 0x94(%rsp), %eax
movl %eax, 0x8c(%rsp)
movl $0x2710, 0x88(%rsp) # imm = 0x2710
movl $0xa, 0x84(%rsp)
movl 0x94(%rsp), %edi
movl 0x8c(%rsp), %esi
movl 0x90(%rsp), %edx
callq 0x1c60
movq %rax, 0x78(%rsp)
cmpq $0x0, 0x78(%rsp)
je 0x210e
jmp 0x212d
leaq 0x1042(%rip), %rdi      # 0x3157
leaq 0x1042(%rip), %rsi      # 0x315e
movl $0x114, %edx            # imm = 0x114
leaq 0x1042(%rip), %rcx      # 0x316a
callq 0x1060
cmpl $0x64, 0x94(%rsp)
jge 0x2141
movq 0x78(%rsp), %rdi
callq 0x19e0
movq 0x78(%rsp), %rdi
callq 0x23c0
movl $0x1, %edi
leaq 0x68(%rsp), %rsi
callq 0x1080
imulq $0x3b9aca00, 0x68(%rsp), %rax # imm = 0x3B9ACA00
addq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x88(%rsp), %eax
jge 0x21ca
callq 0x1040
cltd
idivl 0x8c(%rsp)
movl %edx, 0x58(%rsp)
cmpl $0x32, 0x88(%rsp)
jge 0x21af
movl 0x58(%rsp), %esi
leaq 0xfd9(%rip), %rdi       # 0x3181
movb $0x0, %al
callq 0x1030
movq 0x78(%rsp), %rdi
movl 0x58(%rsp), %esi
callq 0x13d0
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x2175
movl $0x1, %edi
leaq 0x68(%rsp), %rsi
callq 0x1080
imulq $0x3b9aca00, 0x68(%rsp), %rax # imm = 0x3B9ACA00
addq 0x70(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x78(%rsp), %rdi
callq 0x23e0
movl 0x94(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movl 0x94(%rsp), %ecx
addl 0x88(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2247
movq 0x78(%rsp), %rax
movq %rax, 0x38(%rsp)
callq 0x1040
movq 0x38(%rsp), %rdi
cltd
idivl 0x8c(%rsp)
movl %edx, %esi
callq 0x17a0
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x2201
movl $0x1, %edi
leaq 0x68(%rsp), %rsi
callq 0x1080
imulq $0x3b9aca00, 0x68(%rsp), %rax # imm = 0x3B9ACA00
addq 0x70(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
subq 0x50(%rsp), %rax
movslq 0x88(%rsp), %rcx
cqto
idivq %rcx
movq %rax, 0x18(%rsp)
movq 0x50(%rsp), %rax
subq 0x60(%rsp), %rax
movslq 0x88(%rsp), %rcx
cqto
idivq %rcx
movq %rax, 0x20(%rsp)
movl 0x88(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x94(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x94(%rsp), %edi
callq 0x23a0
movsd %xmm0, 0x10(%rsp)
movl 0x90(%rsp), %edi
callq 0x23a0
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x10e0
cvttsd2si %xmm0, %eax
movl %eax, 0x30(%rsp)
movl 0x90(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x78(%rsp), %rdi
callq 0x2400
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl 0x28(%rsp), %ecx
movl 0x2c(%rsp), %r8d
movl 0x30(%rsp), %r9d
movl 0x34(%rsp), %r10d
leaq 0xe62(%rip), %rdi       # 0x318a
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x1030
movl 0xa4(%rsp), %eax
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)