// File: /workspace/github_cpp_makefile_star2_O1/narula[P]skiplists/skiplist-extra.cc
// Function: SkipList::insert(int)
int SkipList::insert(int key) {
  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;
	  succs[i][k] = NULL;
	}
  }
  int found = findNode(key, preds, succs);
  if (found != -1) return 0;
  node* add = new node();
  add->key = key;
  int topLevel = randomLevel(max_level);
  add->topLevel = topLevel;
  for (int level = 0; level< add->topLevel; level++) {
	for (int k = 0; k < FANOUT; k++) {
	  add->nexts[level][k].nxt = succs[level][k];
	  add->nexts[level][k].prefix = succs[level][k]->key;
	  node* pr = preds[level][k];
	  if (pr) {
		// scoot rest down
		for (int j = FANOUT-2; j >= k; j--) {
		  pr->nexts[level][j+1].nxt = pr->nexts[level][j].nxt;
		  pr->nexts[level][j+1].prefix = pr->nexts[level][j].prefix;
		}
		pr->nexts[level][k].nxt = add;
		pr->nexts[level][k].prefix  = key;
	  }
	}
  }
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebx
movq %rdi, %r13
movl 0x10(%rdi), %eax
movq %rsp, %r14
movq %rax, %r12
shlq $0x5, %r12
subq %r12, %r14
movq %r14, %rsp
movq %rsp, %rcx
subq %r12, %rcx
movq %rcx, %rsp
testl %eax, %eax
movq %rcx, -0x30(%rbp)
jle 0x19a5
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x1060
movq -0x30(%rbp), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x1060
movq -0x30(%rbp), %rcx
movq %r13, %rdi
movl %ebx, %esi
movq %r14, %rdx
callq 0x16a6
movl %eax, %ecx
xorl %eax, %eax
cmpl $-0x1, %ecx
jne 0x1aeb
movl $0x348, %edi            # imm = 0x348
callq 0x10d0
movq %rax, %r12
movl $0x348, %edx            # imm = 0x348
movq %rax, %rdi
xorl %esi, %esi
callq 0x1060
movl %ebx, (%r12)
movl 0x10(%r13), %r13d
callq 0x1050
movl %eax, %ecx
movl %eax, %esi
notl %esi
movl $0x1, %eax
movl $0x1, %edx
testb $0x3, %sil
jne 0x1a14
movslq %ecx, %rcx
movq %rcx, %rsi
incl %edx
shrq $0x2, %rsi
notl %ecx
testb $0xc, %cl
movq %rsi, %rcx
je 0x1a04
cmpl %r13d, %edx
cmovgel %r13d, %edx
movl %edx, 0x4(%r12)
testl %r13d, %r13d
jle 0x1aeb
movq %r12, %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
cmpl $0x2, %edx
movl $0x1, %eax
cmovgel %edx, %eax
movq %rax, -0x38(%rbp)
movl $0x40, %edx
xorl %esi, %esi
movq %r14, -0x48(%rbp)
movq %rsi, %rdi
shlq $0x5, %rdi
movq -0x30(%rbp), %rax
leaq (%rax,%rdi), %r8
movq %rsi, %r9
shlq $0x6, %r9
movq -0x40(%rbp), %rax
leaq (%rax,%r9), %r10
addq %r14, %rdi
xorl %r11d, %r11d
movq (%r8,%r11,8), %rax
movq %r11, %r13
shlq $0x4, %r13
movq %rax, 0x8(%r13,%r10)
movl (%rax), %eax
movl %eax, (%r13,%r10)
movq (%rdi,%r11,8), %r14
testq %r14, %r14
je 0x1ac8
cmpq $0x2, %r11
ja 0x1abb
leaq (%r14,%rdx), %rax
movl $0x3, %r15d
movq -0x10(%rax), %rcx
movq %rcx, (%rax)
movl -0x18(%rax), %ecx
movl %ecx, -0x8(%rax)
addq $-0x10, %rax
decq %r15
cmpq %r11, %r15
ja 0x1aa2
addq %r9, %r14
movq %r12, 0x10(%r13,%r14)
movl %ebx, 0x8(%r13,%r14)
incq %r11
cmpq $0x4, %r11
jne 0x1a72
incq %rsi
addq $0x40, %rdx
cmpq -0x38(%rbp), %rsi
movq -0x48(%rbp), %r14
jne 0x1a4e
movl $0x1, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq