// File: narula[P]skiplists/skiplist.cc
// Function: basic_test()
void basic_test() {
  SkipList* sk = SkipList::init_list(1000, 1000, 2);
  int error = 0;
  for (int i = 999; i >= 0; i--) {
	if (sk->lookup(i) <= 0) {
	  printf("Error lookup: %d\n", i);
	  error = 1;
	}
  }
  if (sk->insert(998) > 0) {
	printf("Error insert: %d\n", 998);
	error = 1;
  }
  if (sk->lookup(2000) > 0) {
	  printf("Error lookup: %d\n", 2000);
	  error = 1;
  }
  if (sk->insert(2000) <= 0) {
	printf("Error insert: %d\n", 2000);
	error = 1;
  }
  if (sk->lookup(2000) <= 0) {
	printf("Error lookup: %d\n", 2000);
	error = 1;
  }
  SkipList* sk2 = new SkipList(2, 4);
  for (int i = 0; i < 20; i+=4) {
	if (sk2->insert(i) <= 0)  {
	  printf("Error making small list: %d\n", i);
	  error = 1;
	}
  }
  for (int i = 1; i < 30; i+=5) {
	if (sk2->insert(i) <=0 && i%4 != 0) {
	  printf("Error making small list: %d\n", i);
	  error = 1;
	}
  }
  for (int i = 26; i >= 1; i-=5) {
	if (sk2->lookup(i) != 1) {
	  printf("Error lookup by 5 in small list: %d\n", i);
	  error = 1;	  
	}
  }
  for (int i = 16; i >= 0; i-=4) {
	if (sk2->lookup(i) != 1) {
	  printf("Error lookup by 4 in small list: %d\n", i);
	  error = 1;	  
	}
  }
  if (!error) {
	printf("PASSED\n");
  } else {
	sk2->pretty_print_skiplist();
  }
}

// Assembly:
subq $0x48, %rsp
movl $0x3e8, %esi            # imm = 0x3E8
movl $0x2, %edx
movl %esi, %edi
callq 0x1c60
movq %rax, 0x40(%rsp)
movl $0x0, 0x3c(%rsp)
movl $0x3e7, 0x38(%rsp)      # imm = 0x3E7
cmpl $0x0, 0x38(%rsp)
jl 0x1dbd
movq 0x40(%rsp), %rdi
movl 0x38(%rsp), %esi
callq 0x13d0
cmpl $0x0, %eax
jg 0x1dae
movl 0x38(%rsp), %esi
leaq 0x1325(%rip), %rdi      # 0x30c4
movb $0x0, %al
callq 0x1030
movl $0x1, 0x3c(%rsp)
jmp 0x1db0
movl 0x38(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x1d7a
movq 0x40(%rsp), %rdi
movl $0x3e6, %esi            # imm = 0x3E6
callq 0x17a0
cmpl $0x0, %eax
jle 0x1dec
leaq 0x12fe(%rip), %rdi      # 0x30d6
movl $0x3e6, %esi            # imm = 0x3E6
movb $0x0, %al
callq 0x1030
movl $0x1, 0x3c(%rsp)
movq 0x40(%rsp), %rdi
movl $0x7d0, %esi            # imm = 0x7D0
callq 0x13d0
cmpl $0x0, %eax
jle 0x1e1b
leaq 0x12bd(%rip), %rdi      # 0x30c4
movl $0x7d0, %esi            # imm = 0x7D0
movb $0x0, %al
callq 0x1030
movl $0x1, 0x3c(%rsp)
movq 0x40(%rsp), %rdi
movl $0x7d0, %esi            # imm = 0x7D0
callq 0x17a0
cmpl $0x0, %eax
jg 0x1e4a
leaq 0x12a0(%rip), %rdi      # 0x30d6
movl $0x7d0, %esi            # imm = 0x7D0
movb $0x0, %al
callq 0x1030
movl $0x1, 0x3c(%rsp)
movq 0x40(%rsp), %rdi
movl $0x7d0, %esi            # imm = 0x7D0
callq 0x13d0
cmpl $0x0, %eax
jg 0x1e79
leaq 0x125f(%rip), %rdi      # 0x30c4
movl $0x7d0, %esi            # imm = 0x7D0
movb $0x0, %al
callq 0x1030
movl $0x1, 0x3c(%rsp)
movl $0x20, %edi
callq 0x10b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
movl $0x2, %esi
movl $0x4, %edx
callq 0x1200
jmp 0x1e9f
movq 0x8(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x20(%rsp)
cmpl $0x14, 0x20(%rsp)
jge 0x1f18
movq 0x30(%rsp), %rdi
movl 0x20(%rsp), %esi
callq 0x17a0
cmpl $0x0, %eax
jg 0x1f09
movl 0x20(%rsp), %esi
leaq 0x1212(%rip), %rdi      # 0x30e8
movb $0x0, %al
callq 0x1030
movl $0x1, 0x3c(%rsp)
jmp 0x1f09
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
movl $0x20, %esi
callq 0x10c0
jmp 0x2030
jmp 0x1f0b
movl 0x20(%rsp), %eax
addl $0x4, %eax
movl %eax, 0x20(%rsp)
jmp 0x1eb1
movl $0x1, 0x1c(%rsp)
cmpl $0x1e, 0x1c(%rsp)
jge 0x1f74
movq 0x30(%rsp), %rdi
movl 0x1c(%rsp), %esi
callq 0x17a0
cmpl $0x0, %eax
jg 0x1f65
movl 0x1c(%rsp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x1f65
movl 0x1c(%rsp), %esi
leaq 0x1192(%rip), %rdi      # 0x30e8
movb $0x0, %al
callq 0x1030
movl $0x1, 0x3c(%rsp)
jmp 0x1f67
movl 0x1c(%rsp), %eax
addl $0x5, %eax
movl %eax, 0x1c(%rsp)
jmp 0x1f20
movl $0x1a, 0x18(%rsp)
cmpl $0x1, 0x18(%rsp)
jl 0x1fbf
movq 0x30(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x13d0
cmpl $0x1, %eax
je 0x1fb0
movl 0x18(%rsp), %esi
leaq 0x1164(%rip), %rdi      # 0x3105
movb $0x0, %al
callq 0x1030
movl $0x1, 0x3c(%rsp)
jmp 0x1fb2
movl 0x18(%rsp), %eax
subl $0x5, %eax
movl %eax, 0x18(%rsp)
jmp 0x1f7c
movl $0x10, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
jl 0x200a
movq 0x30(%rsp), %rdi
movl 0x14(%rsp), %esi
callq 0x13d0
cmpl $0x1, %eax
je 0x1ffb
movl 0x14(%rsp), %esi
leaq 0x113e(%rip), %rdi      # 0x312a
movb $0x0, %al
callq 0x1030
movl $0x1, 0x3c(%rsp)
jmp 0x1ffd
movl 0x14(%rsp), %eax
subl $0x4, %eax
movl %eax, 0x14(%rsp)
jmp 0x1fc7
cmpl $0x0, 0x3c(%rsp)
jne 0x2021
leaq 0x1137(%rip), %rdi      # 0x314f
movb $0x0, %al
callq 0x1030
jmp 0x202b
movq 0x30(%rsp), %rdi
callq 0x19e0
addq $0x48, %rsp
retq
movq 0x28(%rsp), %rdi
callq 0x10f0
nopw (%rax,%rax)