// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %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 0x14b9
xorl %esi, %esi
movq %rdi, %r12
callq 0x1060
movq %r12, %rdi
movslq 0x4(%r15), %rcx
testq %rcx, %rcx
jle 0x16ce
movl 0x28(%r14), %edx
movl 0x2c(%r14), %r11d
movq %rcx, %rax
shlq $0x5, %rax
leaq (%rax,%rdi), %r9
addq $-0x28, %r9
movq %rcx, %rsi
shlq $0x6, %rsi
leaq -0x40(%rsi), %r12
addq $-0x48, %rsi
movq %rsi, -0x60(%rbp)
movq %rdi, -0x70(%rbp)
leaq (%rax,%rdi), %r10
addq $-0x20, %r10
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movabsq $0x100000000, %rsi      # imm = 0x100000000
movq %r14, -0x58(%rbp)
movl %r11d, -0x2c(%rbp)
movl %edi, -0x4c(%rbp)
movq %r9, -0x40(%rbp)
movq %rcx, -0x68(%rbp)
leaq -0x1(%rcx), %rax
leaq 0x8(%r15), %rdi
movq %rax, -0x48(%rbp)
shlq $0x6, %rax
cmpl %ebx, 0x38(%r15,%rax)
jge 0x156c
leaq (%r15,%rax), %rcx
addq $0x8, %rcx
movq 0x38(%rdi,%rax), %r8
movq 0x40(%r8,%rax), %r9
cmpl $0x1, %r11d
jne 0x1553
incl %edx
movl %edx, 0x28(%r14)
leaq 0x8(%r8), %rdi
movq %rcx, %r13
leaq (%rdi,%rax), %rcx
movq %r8, %r15
movq %r9, %r8
cmpl %ebx, 0x30(%rdi,%rax)
jl 0x1542
jmp 0x156f
xorl %r13d, %r13d
movl %edx, -0x30(%rbp)
movq %r12, -0x38(%rbp)
leaq (%rdi,%r12), %rax
movq $-0x1, %r9
movq %r10, %r8
xorl %ecx, %ecx
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
movq %rsi, %rdx
movq %rcx, %r12
movq %r8, %rsi
addq %rdx, %r14
incq %r9
leaq 0x10(%rax), %r11
incq %rcx
addq $0x8, %r8
cmpl %ebx, (%rax)
movq %r11, %rax
jl 0x1593
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovel -0x48(%rbp), %eax
movl -0x4c(%rbp), %ecx
cmpl $-0x1, %ecx
cmovnel %ecx, %eax
testq %r9, %r9
je 0x1600
sarq $0x1c, %r14
addq -0x60(%rbp), %rdi
addq %r14, %rdi
movq %r12, %r11
movq %r10, %r8
movl -0x30(%rbp), %edx
movq (%rdi), %rcx
movq %rcx, (%r8)
addq $-0x10, %rdi
addq $0x8, %r8
decq %r11
jne 0x15dc
testq %r13, %r13
movq -0x58(%rbp), %r14
je 0x165b
cmpq $0x3, %r9
jbe 0x160c
jmp 0x162c
testq %r13, %r13
movq -0x58(%rbp), %r14
movl -0x30(%rbp), %edx
je 0x165b
addq $0x38, %r13
movl $0x4, %edi
subq %r12, %rdi
movq (%r13), %rcx
movq %rcx, (%rsi)
addq $-0x10, %r13
addq $0x8, %rsi
decq %rdi
jne 0x1618
movl -0x2c(%rbp), %r11d
cmpl $0x1, %r11d
movq -0x68(%rbp), %r8
jne 0x1640
incl %edx
movl %edx, 0x28(%r14)
movq -0x40(%rbp), %r9
movq -0x38(%rbp), %r12
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
movq -0x70(%rbp), %rsi
movq 0x18(%rsi,%rcx), %r15
jmp 0x1673
movq -0x40(%rbp), %rcx
movq %r15, 0x8(%rcx,%r9,8)
movq %rcx, %r9
movq -0x68(%rbp), %r8
movl -0x2c(%rbp), %r11d
movq -0x38(%rbp), %r12
cmpq $0x1, %r8
je 0x16d3
leaq -0x2(%r8), %rdi
shlq $0x6, %rdi
xorl %esi, %esi
movq (%r10,%rsi,8), %rcx
testq %rcx, %rcx
je 0x1692
cmpl %ebx, 0x38(%rcx,%rdi)
jle 0x169e
incq %rsi
cmpq $0x4, %rsi
jne 0x1683
movq %r15, %rcx
addq $-0x20, %r9
addq $-0x40, %r12
addq $-0x40, -0x60(%rbp)
addq $-0x20, %r10
movq %rcx, %r15
movl %eax, %edi
cmpq $0x1, %r8
movq -0x48(%rbp), %rcx
movabsq $0x100000000, %rsi      # imm = 0x100000000
jg 0x1513
jmp 0x16d3
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq