// File: narula[P]skiplists/skiplist-extra.cc
// Function: SkipList::fastFindTest(int)
int SkipList::fastFindTest(int key) {
  node* pred = head;
  int lFound = -1;
  node *preds[max_level][FANOUT], *succs[max_level][FANOUT];
  for (int i = 0; i < max_level; i++) {
	for (int k = 0; k < FANOUT; k++) {
	  preds[i][k] = NULL;
	}
  }	
  for (int level = pred->topLevel-1; level >= 0; level--) {
	node* curr = pred->nexts[level][FANOUT-1].nxt;
	next* prevFour = NULL;
	while (key > pred->nexts[level][FANOUT-1].prefix) {
	  prevFour = pred->nexts[level];
	  pred = curr;
	  curr = pred->nexts[level][FANOUT-1].nxt;
	  inc();
	}
	int extra = 0;
	while (key > pred->nexts[level][extra].prefix) extra++;
	if (lFound == -1 && key == pred->nexts[level][extra].prefix) {
	  lFound = level;
	}
	node* prev = pred;
	if (extra > 0) {
	  prev = pred->nexts[level][extra-1].nxt;
	}
	for (int i = 0; i < FANOUT; i++) {
	  succs[level][i] = prev->nexts[level][i].nxt;
	}
	// get the ones right before (extra)
	for (int i = 0; i < extra; i++) {
	  preds[level][i] = pred->nexts[level][extra-i-1].nxt;
	}
	if (prevFour == NULL) {
	  // did not make it past head, later in preds will be NULL.
	  preds[level][extra] = pred;
	} else {
	  // either get last n where n = FANOUT-extra)  or whole thing backwards.
	  for (int i = extra; i < FANOUT; i++) {
		preds[level][i] = prevFour[FANOUT-i-1+extra].nxt;
	  }
	  inc();
	  // reset pred to be before
	  pred = preds[level][FANOUT-1];
	}

	// ARGH FIX.
	if (level > 0) {
	  for (int i = 0; i < FANOUT; i++) {
	  	if (preds[level] && preds[level][i] && 
	  		preds[level][i]->nexts[level-1][FANOUT-1].prefix <= key) {
	  	  pred = preds[level][i];
	  	  break;
	  	}
	  }
	}
  }
  return lFound;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq (%rax), %rcx
movq %rcx, -0x18(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl 0x10(%rax), %ecx
movq %rsp, %rdx
movq %rdx, -0x28(%rbp)
movq %rcx, %rsi
shlq $0x5, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x88(%rbp)
movq %rdx, %rsp
movq %rcx, -0x30(%rbp)
movl 0x10(%rax), %eax
movq %rax, %rdx
shlq $0x5, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x80(%rbp)
movq %rcx, %rsp
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x90(%rbp), %rcx
movl -0x3c(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x1844
movl $0x0, -0x40(%rbp)
cmpl $0x4, -0x40(%rbp)
jge 0x1837
movq -0x88(%rbp), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1808
jmp 0x1839
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x17f2
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jl 0x1b97
movq -0x18(%rbp), %rax
addq $0x8, %rax
movslq -0x44(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x38(%rax), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
addq $0x8, %rcx
movslq -0x44(%rbp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
cmpl 0x30(%rcx), %eax
jle 0x18e1
movq -0x90(%rbp), %rdi
movq -0x18(%rbp), %rax
addq $0x8, %rax
movslq -0x44(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movslq -0x44(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x38(%rax), %rax
movq %rax, -0x50(%rbp)
callq 0x4150
jmp 0x187e
movl $0x0, -0x5c(%rbp)
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
addq $0x8, %rcx
movslq -0x44(%rbp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
movslq -0x5c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jle 0x1918
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x18e8
cmpl $-0x1, -0x1c(%rbp)
jne 0x1949
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
addq $0x8, %rcx
movslq -0x44(%rbp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
movslq -0x5c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0x1949
movl -0x44(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpl $0x0, -0x5c(%rbp)
jle 0x1982
movq -0x18(%rbp), %rax
addq $0x8, %rax
movslq -0x44(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movl -0x5c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
cmpl $0x4, -0x6c(%rbp)
jge 0x19d3
movq -0x80(%rbp), %rax
movq -0x68(%rbp), %rcx
addq $0x8, %rcx
movslq -0x44(%rbp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
movslq -0x6c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rdx
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x6c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1989
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x1a31
movq -0x88(%rbp), %rax
movq -0x18(%rbp), %rcx
addq $0x8, %rcx
movslq -0x44(%rbp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
movl -0x5c(%rbp), %edx
subl -0x70(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rdx
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x70(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x19da
cmpq $0x0, -0x58(%rbp)
jne 0x1a58
movq -0x88(%rbp), %rax
movq -0x18(%rbp), %rdx
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x5c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x1acf
movl -0x5c(%rbp), %eax
movl %eax, -0x74(%rbp)
cmpl $0x4, -0x74(%rbp)
jge 0x1aa9
movq -0x88(%rbp), %rax
movq -0x58(%rbp), %rcx
movl $0x4, %edx
subl -0x74(%rbp), %edx
subl $0x1, %edx
addl -0x5c(%rbp), %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rdx
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x74(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x1a5e
movq -0x90(%rbp), %rdi
callq 0x4150
movq -0x88(%rbp), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x44(%rbp)
jle 0x1b87
movl $0x0, -0x78(%rbp)
cmpl $0x4, -0x78(%rbp)
jge 0x1b85
movq -0x88(%rbp), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $0x0, %rax
je 0x1b75
movq -0x88(%rbp), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x78(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x1b75
movq -0x88(%rbp), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x8, %rax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movl 0x30(%rax), %eax
cmpl -0xc(%rbp), %eax
jg 0x1b75
movq -0x88(%rbp), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
jmp 0x1b85
jmp 0x1b77
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x1ae0
jmp 0x1b87
jmp 0x1b89
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1851
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
movq %rcx, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)