// File: /workspace/github_cpp_makefile_star2_O3/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), %r13
movslq 0x4(%r13), %rax
testq %rax, %rax
jle 0x197e
leaq -0x28(%rdx), %r9
movq %rax, %r8
shlq $0x5, %r8
leaq (%rcx,%r8), %rbp
addq $-0x20, %rbp
movq %rax, %r14
shlq $0x6, %r14
leaq -0x30(%r14), %rcx
movq %rcx, -0x30(%rsp)
addq $-0x48, %r14
movq %r8, -0x20(%rsp)
leaq (%rdx,%r8), %r12
addq $-0x20, %r12
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq $-0x40, %r15
movq %rdx, -0x28(%rsp)
movq %rdi, -0x50(%rsp)
movl %ecx, -0x64(%rsp)
movq %r14, -0x40(%rsp)
movq %rax, -0x38(%rsp)
leaq -0x1(%rax), %r14
leaq 0x8(%r13), %rdx
movq %r14, -0x58(%rsp)
shlq $0x6, %r14
cmpl %esi, 0x38(%r13,%r14)
jge 0x17aa
leaq (%r14,%r13), %r10
addq $0x8, %r10
movq 0x38(%rdx,%r14), %rbx
movl 0x28(%rdi), %eax
movl 0x2c(%rdi), %r8d
movq 0x40(%rbx,%r14), %rcx
cmpl $0x1, %r8d
jne 0x1790
incl %eax
movl %eax, 0x28(%rdi)
leaq 0x8(%rbx), %rdx
movq %r10, %r11
leaq (%rdx,%r14), %r10
movq %rbx, %r13
movq %rcx, %rbx
cmpl %esi, 0x30(%rdx,%r14)
jl 0x1780
jmp 0x17ad
xorl %r11d, %r11d
movq %r13, -0x60(%rsp)
movq %rbp, -0x10(%rsp)
movq %r9, -0x8(%rsp)
movq %r15, -0x48(%rsp)
leaq (%rdx,%r15), %rdi
movl $0x4, %r13d
movq %r12, -0x18(%rsp)
movq %r12, %rbp
movq -0x20(%rsp), %r15
movabsq $-0x100000000, %rbx     # imm = 0xFFFFFFFF00000000
xorl %r8d, %r8d
movl $0xfffffffe, %r9d       # imm = 0xFFFFFFFE
movq %r8, %rax
movq %r15, %r12
movq %rbp, %rcx
movq %r13, %r10
decq %r8
addq $0x8, %r15
addq $0x8, %rbp
decq %r13
addq %r9, %rbx
addq $0x2, %rbx
cmpl %esi, (%rdi,%r12,2)
jl 0x17eb
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmovel -0x58(%rsp), %edi
movl -0x64(%rsp), %r9d
cmpl $-0x1, %r9d
cmovnel %r9d, %edi
movl %edi, -0x64(%rsp)
movq -0x60(%rsp), %r13
cmpq $-0x1, %r8
je 0x184c
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
subl %r8d, %edi
addq %rdx, %r14
shlq $0x4, %rdi
movq 0x8(%rdi,%r14), %r13
movq %r8, %rdi
notq %rdi
addq -0x30(%rsp), %r13
xorl %r14d, %r14d
movq -0x8(%rsp), %r9
movq -0x10(%rsp), %rbp
movq (%r13,%r14,2), %r12
movq %r12, (%rbp,%r14)
addq $0x8, %r14
cmpq $0x20, %r14
jne 0x1864
cmpq $-0x1, %r8
movq -0x18(%rsp), %r12
je 0x18bd
sarq $0x1c, %rbx
movq -0x40(%rsp), %r14
addq %r14, %rdx
addq %rbx, %rdx
xorl %r8d, %r8d
movq -0x60(%rsp), %r13
movq (%rdx), %rbx
movq %rbx, (%r12,%r8,8)
incq %r8
addq $-0x10, %rdx
movq %rax, %rbx
addq %r8, %rbx
jne 0x189a
testq %r11, %r11
je 0x1906
cmpq $0x3, %rdi
jbe 0x18cc
jmp 0x18e3
testq %r11, %r11
movq -0x40(%rsp), %r14
movq -0x60(%rsp), %r13
je 0x1906
addq $0x38, %r11
movq (%r11), %rax
movq %rax, (%rcx)
addq $-0x10, %r11
addq $0x8, %rcx
decq %r10
jne 0x18d0
movq -0x50(%rsp), %rdi
cmpl $0x1, 0x2c(%rdi)
movq -0x28(%rsp), %rdx
jne 0x18f6
incl 0x28(%rdi)
movq -0x58(%rsp), %rax
shlq $0x5, %rax
movq 0x18(%rdx,%rax), %r13
jmp 0x190f
movq %r13, (%r9,%r15)
movq -0x50(%rsp), %rdi
movq -0x38(%rsp), %r10
movq -0x48(%rsp), %r15
movl -0x64(%rsp), %r11d
cmpq $0x1, %r10
je 0x1984
leaq -0x2(%r10), %rax
shlq $0x6, %rax
xorl %ecx, %ecx
movq (%r12,%rcx,8), %r8
testq %r8, %r8
je 0x193e
cmpl %esi, 0x38(%r8,%rax)
jle 0x1949
incq %rcx
cmpq $0x4, %rcx
jne 0x192e
jmp 0x1950
incl 0x14(%rdi,%rcx,4)
movq %r8, %r13
addq $-0x20, %r9
addq $-0x40, %r15
addq $-0x20, %rbp
addq $-0x40, -0x30(%rsp)
addq $-0x40, %r14
addq $-0x20, %r12
movl %r11d, %ecx
cmpq $0x1, %r10
movq -0x58(%rsp), %rax
jg 0x1746
jmp 0x1984
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl %r11d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq