// File: /workspace/github_cpp_makefile_star2_O1/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 (%rdi), %r10
movslq 0x4(%r10), %r14
testq %r14, %r14
jle 0x193c
leaq -0x28(%rdx), %r8
movq %r14, %rax
shlq $0x5, %rax
leaq (%rcx,%rax), %r13
addq $-0x20, %r13
movq %r14, %r11
shlq $0x6, %r11
leaq -0x30(%r11), %rcx
movq %rcx, -0x38(%rsp)
addq $-0x48, %r11
movq %rdx, -0x30(%rsp)
movq %rax, -0x28(%rsp)
leaq (%rdx,%rax), %r12
addq $-0x20, %r12
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq $-0x40, %rbx
movq %rdi, -0x58(%rsp)
movq %r11, -0x18(%rsp)
movq %r8, -0x40(%rsp)
movl %eax, -0x64(%rsp)
movq %r14, -0x50(%rsp)
leaq -0x1(%r14), %r11
movq %r11, %r9
shlq $0x6, %r9
cmpl %esi, 0x38(%r10,%r9)
movq %r11, -0x8(%rsp)
movq %r13, -0x10(%rsp)
jge 0x177a
leaq (%r10,%r9), %rcx
addq $0x8, %rcx
movq 0x38(%rcx), %rax
movl 0x28(%rdi), %edx
movl 0x2c(%rdi), %r8d
movq %rax, %r14
movq %rcx, %r10
movq 0x40(%rax,%r9), %rax
cmpl $0x1, %r8d
jne 0x1762
incl %edx
movl %edx, 0x28(%rdi)
leaq (%r14,%r9), %rcx
addq $0x8, %rcx
cmpl %esi, 0x30(%rcx)
jl 0x174c
movq %r14, -0x60(%rsp)
leaq 0x8(%r14), %rbp
jmp 0x1786
movq %r10, -0x60(%rsp)
leaq 0x8(%r10), %rbp
xorl %r10d, %r10d
movq %rbx, -0x48(%rsp)
leaq (%rbx,%rbp), %rax
movl $0x4, %r11d
movq %r12, -0x20(%rsp)
movq %r12, %rdx
movq -0x28(%rsp), %r15
movabsq $-0x100000000, %rbx     # imm = 0xFFFFFFFF00000000
xorl %r12d, %r12d
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
movq %r12, %r8
movq %r15, %r14
movq %rdx, %rcx
movq %r11, %rdi
decq %r12
addq $0x8, %r15
addq $0x8, %rdx
decq %r11
addq %r13, %rbx
addq $0x2, %rbx
cmpl %esi, (%rax,%r14,2)
jl 0x17b5
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq -0x8(%rsp), %r14
cmovel %r14d, %eax
movl -0x64(%rsp), %edx
cmpl $-0x1, %edx
cmovnel %edx, %eax
movl %eax, -0x64(%rsp)
movq -0x60(%rsp), %rax
cmpq $-0x1, %r12
je 0x1817
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
subl %r12d, %eax
addq %rbp, %r9
shlq $0x4, %rax
movq 0x8(%rax,%r9), %rax
movq %r12, %r9
notq %r9
addq -0x38(%rsp), %rax
xorl %edx, %edx
movq -0x10(%rsp), %r13
movq (%rax,%rdx,2), %r11
movq %r11, (%r13,%rdx)
addq $0x8, %rdx
cmpq $0x20, %rdx
jne 0x1829
cmpq $-0x1, %r12
movq -0x18(%rsp), %r11
movq -0x20(%rsp), %r12
je 0x186f
sarq $0x1c, %rbx
addq %r11, %rbp
addq %rbx, %rbp
xorl %eax, %eax
movq (%rbp), %rdx
movq %rdx, (%r12,%rax,8)
incq %rax
addq $-0x10, %rbp
movq %r8, %rdx
addq %rax, %rdx
jne 0x1858
testq %r10, %r10
je 0x18c1
cmpq $0x3, %r9
movq -0x40(%rsp), %r8
movq -0x48(%rsp), %rbx
ja 0x189b
addq $0x38, %r10
movq (%r10), %rax
movq %rax, (%rcx)
addq $-0x10, %r10
addq $0x8, %rcx
decq %rdi
jne 0x1888
movq -0x58(%rsp), %rdi
cmpl $0x1, 0x2c(%rdi)
movq -0x30(%rsp), %rcx
movq -0x50(%rsp), %r9
jne 0x18b3
incl 0x28(%rdi)
movq %r14, %rax
shlq $0x5, %rax
movq 0x18(%rcx,%rax), %r10
jmp 0x18de
movq -0x40(%rsp), %r8
movq -0x60(%rsp), %r10
movq %r10, (%r8,%r15)
movq -0x58(%rsp), %rdi
movq -0x48(%rsp), %rbx
movq -0x50(%rsp), %r9
cmpq $0x1, %r9
je 0x1906
leaq -0x2(%r9), %rax
shlq $0x6, %rax
xorl %ecx, %ecx
movq (%r12,%rcx,8), %rdx
testq %rdx, %rdx
je 0x18fd
cmpl %esi, 0x38(%rdx,%rax)
jle 0x1936
incq %rcx
cmpq $0x4, %rcx
jne 0x18ee
movq %r10, %rdx
movl -0x64(%rsp), %eax
addq $-0x20, %r8
addq $-0x40, %rbx
addq $-0x20, %r13
addq $-0x40, -0x38(%rsp)
addq $-0x40, %r11
addq $-0x20, %r12
movq %rdx, %r10
cmpq $0x1, %r9
jg 0x170a
jmp 0x1941
incl 0x14(%rdi,%rcx,4)
jmp 0x1909
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq