// File: /workspace/github_cpp_makefile_star2_O2/narula[P]skiplists/skiplist-extra.cc
// Function: SkipList::findNode(int, node* (*) [4], node* (*) [4])
int SkipList::findNode(int key, node* preds[][FANOUT], node* succs[][FANOUT]) {
  node* pred = head;
  int lFound = -1;
  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];
	}
	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];
		  drop_down_pred[i]++;
	  	  break;
	  	}
	  }
	}
  }
  return lFound;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, -0x18(%rsp)
movq %rdx, -0x28(%rsp)
movl $0xfffffffe, %r8d       # imm = 0xFFFFFFFE
movq (%rdi), %rcx
movl 0x4(%rcx), %r14d
leal -0x1(%r14), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x3c(%rsp)
movq %rdi, -0x30(%rsp)
testl %r14d, %r14d
jle 0x185c
movl %edx, -0x38(%rsp)
movl %edx, %r10d
movq %r10, %r9
shlq $0x5, %r9
movq -0x28(%rsp), %rax
leaq (%rax,%r9), %r12
shlq $0x6, %r10
addq -0x18(%rsp), %r9
leaq -0x1(%r14), %rax
movq %rax, -0x20(%rsp)
movl %eax, %r13d
movq %r13, -0x8(%rsp)
shlq $0x6, %r13
movq 0x40(%rcx,%r13), %rdx
movl 0x28(%rdi), %ebp
movl 0x2c(%rdi), %eax
xorl %ebx, %ebx
movq %rcx, %r11
cmpl %esi, 0x38(%r11,%r13)
jge 0x1703
movq %rdx, %rcx
leaq (%r11,%r13), %rbx
addq $0x8, %rbx
movq 0x40(%rdx,%r13), %rdx
movq %rcx, %r11
cmpl $0x1, %eax
jne 0x16dd
incl %ebp
movl %ebp, 0x28(%rdi)
jmp 0x16da
movl %ebp, -0x34(%rsp)
leaq 0x8(%r11), %rax
movq %rax, -0x10(%rsp)
leaq (%r11,%r10), %rdx
addq $0x8, %rdx
xorl %r15d, %r15d
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movabsq $-0x1, %rcx
movq %r15, %rbp
incq %rcx
leaq 0x10(%rdx), %rdi
incq %r15
addq %r8, %rax
addq $0x2, %rax
cmpl %esi, (%rdx)
movq %rdi, %rdx
jl 0x172f
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovel -0x20(%rsp), %edx
movl -0x3c(%rsp), %edi
cmpl $-0x1, %edi
cmovel %edx, %edi
movl %edi, -0x3c(%rsp)
movq %r11, %rdx
testq %rcx, %rcx
je 0x1781
leal (%rcx,%r8), %edx
incl %edx
shlq $0x4, %rdx
movq -0x10(%rsp), %rdi
addq %r13, %rdi
movq 0x8(%rdx,%rdi), %rdx
addq %r10, %rdx
addq $0x10, %rdx
xorl %edi, %edi
cmpq $0x20, %rdi
je 0x179e
movq (%rdx,%rdi,2), %r15
movq %r15, (%r9,%rdi)
addq $0x8, %rdi
jmp 0x178a
sarq $0x1c, %rax
addq %r11, %r10
addq %rax, %r10
movq %r12, %rax
subq $0x1, %rbp
jb 0x17c1
movq (%r10), %rdx
movq %rdx, (%rax)
addq $0x8, %rax
addq $-0x10, %r10
jmp 0x17ab
testq %rbx, %rbx
je 0x1810
addq $0x38, %rbx
movq -0x30(%rsp), %rdi
movl -0x38(%rsp), %edx
movl -0x34(%rsp), %r9d
cmpq $0x4, %rcx
jae 0x17ee
movq (%rbx), %rax
movq %rax, (%r12,%rcx,8)
incq %rcx
addq $-0x10, %rbx
jmp 0x17d8
cmpl $0x1, 0x2c(%rdi)
jne 0x17fb
incl %r9d
movl %r9d, 0x28(%rdi)
movq -0x8(%rsp), %rcx
shlq $0x5, %rcx
movq -0x28(%rsp), %rax
movq 0x18(%rax,%rcx), %r11
jmp 0x181d
movq %r11, (%r12,%rcx,8)
movq -0x30(%rsp), %rdi
movl -0x38(%rsp), %edx
cmpq $0x1, %r14
jne 0x1832
movq %r11, %rcx
decl %edx
movq -0x20(%rsp), %r14
jmp 0x168f
addl %r8d, %r14d
shlq $0x6, %r14
xorl %eax, %eax
cmpq $0x4, %rax
je 0x1823
movq (%r12,%rax,8), %rcx
testq %rcx, %rcx
je 0x1851
cmpl %esi, 0x38(%rcx,%r14)
jle 0x1856
incq %rax
jmp 0x183b
incl 0x14(%rdi,%rax,4)
jmp 0x1826
movl -0x3c(%rsp), %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop