// File: /workspace/github_c_makefile_star2_O2/wuxb45[P]SLB/lib1.c
// Function: skiplist_set
bool
skiplist_set(struct skiplist * const list, const struct kv * const kv)
{
  const struct kv * const newkv = kv_alloc_dup(kv, &(list->mm));
  u64 h = list->height - 1;
  struct skipnode * path[64];
  struct skipnode * left = &(list->n0);
  struct skipnode * right = NULL;
  while (h < 64) { // h >= 0
    while (left->next[h]) {
      right = left->next[h];
      struct kv * const curr = __u64_to_ptr(right->e.ptr);
      debug_assert(curr);
      const int cmp = list->comp(newkv, curr);
      if (cmp == 0) {
        kvmap_put_entry(&(list->mm), &(right->e), newkv);
        return true;
      } else if (cmp < 0) {
        break;
      } else {
        left = right;
      }
    }
    path[h] = left;
    h--;
  }
  // insert
  const double r = random_double();
  h = 0;
  while (r < list->factors[h]) h++;
  const u64 height = h;
  if (height > list->height) {
    for (u64 i = list->height; i < height; i++) {
      path[i] = &(list->n0);
    }
    list->height = height;
  }
  const u64 nodesize = sizeof(list->n0) + (sizeof(list->n0.next[0]) * height);
  struct skipnode * const newnode = (typeof(newnode))malloc(nodesize);
  if (newnode == NULL) {
    if (list->mm.rf) {
      list->mm.rf((struct kv *)newkv, list->mm.rp);
    }
    return false;
  }
  newnode->e.ptr = 0;
  kvmap_put_entry(&(list->mm), &(newnode->e), newkv);
  for (u64 i = 0; i < height; i++) {
    newnode->next[i] = path[i]->next[i];
    path[i]->next[i] = newnode;
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdi, %r14
movq %rsi, %rdi
movq %r14, %rsi
callq 0xba29
movq %rax, -0x30(%rbp)
movq 0x258(%r14), %r13
leaq 0x260(%r14), %rbx
movq %rbx, -0x38(%rbp)
decq %r13
cmpq $0x3f, %r13
ja 0xd4be
movq %rbx, %r15
movq %r15, %rbx
movq 0x8(%r15,%r13,8), %r15
testq %r15, %r15
je 0xd491
movq (%r15), %r12
cmpq $0xffff, %r12           # imm = 0xFFFF
ja 0xd47c
callq 0x6e43
shrq $0x10, %r12
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq *0x50(%r14)
testl %eax, %eax
je 0xd49b
jns 0xd45e
movq %rbx, -0x240(%rbp,%r13,8)
jmp 0xd452
movq %r14, %rdi
movq %r15, %rsi
movq -0x30(%rbp), %rdx
callq 0xccb2
movb $0x1, %al
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
popq %r12
xorl %r15d, %r15d
callq 0x916e
vmovsd 0x60(%r14,%r12,8), %xmm1
incq %r12
addq $-0x8, %r15
vucomisd %xmm0, %xmm1
ja 0xd4ca
movq 0x258(%r14), %rax
cmpq %rax, %r12
movq -0x38(%rbp), %rcx
jbe 0xd507
cmpq %r12, %rax
jae 0xd500
movq %rcx, -0x240(%rbp,%rax,8)
incq %rax
jmp 0xd4ee
movq %r12, 0x258(%r14)
negq %r15
movq %r15, %rdi
callq 0x63a0
testq %rax, %rax
je 0xd554
movq %rax, %r15
andq $0x0, (%rax)
movq %r14, %rdi
movq %rax, %rsi
movq -0x30(%rbp), %rdx
callq 0xccb2
xorl %eax, %eax
cmpq %rax, %r12
je 0xd4aa
movq -0x240(%rbp,%rax,8), %rcx
movq 0x8(%rcx,%rax,8), %rdx
movq %rdx, 0x8(%r15,%rax,8)
movq %r15, 0x8(%rcx,%rax,8)
incq %rax
jmp 0xd52f
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xd567
movq 0x18(%r14), %rsi
movq -0x30(%rbp), %rdi
callq *%rax
xorl %eax, %eax
jmp 0xd4ac