// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %r15
movl 0x10(%rdi), %eax
movq %rsp, %rdi
movq %rax, %rdx
shlq $0x5, %rdx
subq %rdx, %rdi
movq %rdi, %rsp
testl %eax, %eax
jle 0x148f
xorl %esi, %esi
movq %rdi, %r12
callq 0x1060
movq %r12, %rdi
movslq 0x4(%r15), %r12
testq %r12, %r12
jle 0x1692
movl 0x28(%r14), %ecx
movl 0x2c(%r14), %r8d
movq %r12, %rax
shlq $0x5, %rax
leaq (%rax,%rdi), %r9
addq $-0x28, %r9
movq %r12, %rdx
shlq $0x6, %rdx
leaq -0x40(%rdx), %r13
addq $-0x48, %rdx
movq %rdx, -0x50(%rbp)
movq %rdi, -0x68(%rbp)
leaq (%rax,%rdi), %r10
addq $-0x20, %r10
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %r14, -0x38(%rbp)
movl %r8d, -0x2c(%rbp)
movl %eax, -0x44(%rbp)
movq %r12, -0x40(%rbp)
leaq -0x1(%r12), %rdi
movq %rdi, %rax
shlq $0x6, %rax
cmpl %ebx, 0x38(%r15,%rax)
movq %rdi, -0x78(%rbp)
movq %r9, -0x60(%rbp)
jge 0x1537
leaq (%r15,%rax), %rdx
addq $0x8, %rdx
movq 0x38(%rdx), %rsi
movq %rsi, %r15
movq %rdx, %r11
movq 0x40(%rsi,%rax), %rsi
cmpl $0x1, %r8d
jne 0x1524
incl %ecx
movl %ecx, 0x28(%r14)
leaq (%r15,%rax), %rdx
addq $0x8, %rdx
cmpl %ebx, 0x30(%rdx)
jl 0x150d
leaq 0x8(%r15), %rdi
jmp 0x153e
leaq 0x8(%r15), %rdi
xorl %r11d, %r11d
movq %r13, -0x58(%rbp)
leaq (%rdi,%r13), %rax
movq $-0x1, %r8
movq %r10, -0x70(%rbp)
movq %r10, %r13
xorl %esi, %esi
movabsq $-0x100000000, %r9      # imm = 0xFFFFFFFF00000000
movabsq $0x100000000, %r10      # imm = 0x100000000
movq %rsi, %rdx
movq %r13, %r14
addq %r10, %r9
incq %r8
leaq 0x10(%rax), %r12
incq %rsi
addq $0x8, %r13
cmpl %ebx, (%rax)
movq %r12, %rax
jl 0x156a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq -0x78(%rbp), %r12
cmovel %r12d, %eax
movl -0x44(%rbp), %esi
cmpl $-0x1, %esi
cmovnel %esi, %eax
testq %r8, %r8
movq -0x70(%rbp), %r10
je 0x15cc
sarq $0x1c, %r9
addq -0x50(%rbp), %rdi
addq %r9, %rdi
movq %rdx, %r9
movq %r10, %r13
movq (%rdi), %rsi
movq %rsi, (%r13)
addq $-0x10, %rdi
addq $0x8, %r13
decq %r9
jne 0x15b8
testq %r11, %r11
je 0x1614
cmpq $0x3, %r8
movq -0x60(%rbp), %r9
movq -0x58(%rbp), %r13
ja 0x15fe
addq $0x38, %r11
movl $0x4, %edi
subq %rdx, %rdi
movq (%r11), %rdx
movq %rdx, (%r14)
addq $-0x10, %r11
addq $0x8, %r14
decq %rdi
jne 0x15eb
movl -0x2c(%rbp), %r8d
cmpl $0x1, %r8d
jne 0x162f
incl %ecx
movq -0x38(%rbp), %r14
movl %ecx, 0x28(%r14)
jmp 0x1633
movq -0x60(%rbp), %r9
movq %r15, 0x8(%r9,%r8,8)
movq -0x38(%rbp), %r14
movl -0x2c(%rbp), %r8d
movq -0x58(%rbp), %r13
movq -0x40(%rbp), %r11
jmp 0x1647
movq -0x38(%rbp), %r14
movq -0x40(%rbp), %r11
movq %r12, %rdx
shlq $0x5, %rdx
movq -0x68(%rbp), %rsi
movq 0x18(%rsi,%rdx), %r15
cmpq $0x1, %r11
je 0x166f
leaq -0x2(%r11), %rdi
shlq $0x6, %rdi
xorl %edx, %edx
movq (%r10,%rdx,8), %rsi
testq %rsi, %rsi
je 0x1666
cmpl %ebx, 0x38(%rsi,%rdi)
jle 0x1672
incq %rdx
cmpq $0x4, %rdx
jne 0x1657
movq %r15, %rsi
addq $-0x20, %r9
addq $-0x40, %r13
addq $-0x40, -0x50(%rbp)
addq $-0x20, %r10
movq %rsi, %r15
cmpq $0x1, %r11
jg 0x14df
jmp 0x1697
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq