// File: /workspace/github_c_makefile_star2_O3/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 $0x228, %rsp            # imm = 0x228
movq %rsi, %r15
movq %rdi, %r14
movq 0x8(%rdi), %rsi
movl 0x8(%r15), %eax
movl 0xc(%r15), %ecx
leaq (%rax,%rcx), %r12
addq $0x10, %r12
movq %r12, %rdi
callq *(%r14)
movq %rax, %rbx
testq %rax, %rax
je 0xf15c
movq %rbx, -0x30(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x6340
movq 0x258(%r14), %r13
leaq 0x260(%r14), %rax
movq %rax, -0x38(%rbp)
decq %r13
cmpq $0x3f, %r13
ja 0xef82
movq -0x38(%rbp), %r12
movq %r12, %rbx
movq %rbx, %r12
movq 0x8(%rbx,%r13,8), %rbx
testq %rbx, %rbx
je 0xef71
movq (%rbx), %r15
cmpq $0xffff, %r15           # imm = 0xFFFF
jbe 0xef6a
shrq $0x10, %r15
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq *0x50(%r14)
testl %eax, %eax
je 0xf071
jns 0xef36
jmp 0xef71
callq 0x66ef
jmp 0xef4f
movq %r12, -0x250(%rbp,%r13,8)
decq %r13
cmpq $0x40, %r13
jb 0xef33
movq %fs:-0x8, %rax
testq %rax, %rax
jne 0xefac
leaq -0x48(%rbp), %r15
movl $0x4, %edi
movq %r15, %rsi
callq 0x6110
imulq $0x3b9aca00, (%r15), %rax # imm = 0x3B9ACA00
addq 0x8(%r15), %rax
movq %rax, %rcx
shrq $0xc, %rcx
xorq %rax, %rcx
movq %rcx, %rax
shlq $0x19, %rax
xorq %rcx, %rax
movq %rax, %rcx
shrq $0x1b, %rcx
xorq %rax, %rcx
movabsq $0x2545f4914f6cdd1d, %rax # imm = 0x2545F4914F6CDD1D
imulq %rcx, %rax
movq %rax, %fs:-0x8
vcvtusi2sd %rax, %xmm0, %xmm0
vmulsd 0x5091(%rip), %xmm0, %xmm0 # 0x14080
movl $0x1, %r15d
xorl %edi, %edi
movq -0x30(%rbp), %rbx
vmovsd 0x58(%r14,%rdi), %xmm1
decq %r15
addq $0x8, %rdi
vucomisd %xmm0, %xmm1
ja 0xeffb
movq 0x258(%r14), %rax
movq %r15, %r12
negq %r12
cmpq %rax, %r12
movq -0x38(%rbp), %rcx
jbe 0xf03c
movq %rcx, -0x250(%rbp,%rax,8)
incq %rax
cmpq %rax, %r12
jne 0xf025
movq %r12, 0x258(%r14)
callq 0x63a0
testq %rax, %rax
je 0xf0b7
movq %rbx, %rcx
shlq $0x10, %rcx
testq %rbx, %rbx
je 0xf118
movq (%rbx), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
xorl %edx, %esi
movl %esi, %edx
shrl $0x10, %edx
xorl %esi, %edx
movzwl %dx, %edx
jmp 0xf11a
movq (%rbx), %rcx
cmpq $0x10000, %rcx          # imm = 0x10000
jae 0xf083
movq -0x30(%rbp), %r15
jmp 0xf0df
movq %rcx, %rdi
shrq $0x10, %rdi
movq -0x30(%rbp), %r15
testq %r15, %r15
je 0xf0cd
movq 0x40(%r14), %rax
testq %rax, %rax
je 0xf0cd
movq 0x48(%r14), %rdx
movq %r15, %rsi
callq *%rax
movzwl (%rbx), %ecx
movq %r15, %rax
shlq $0x10, %rax
orq %rax, %rcx
movq %rcx, (%rbx)
jmp 0xf0f4
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xf0c9
movq 0x18(%r14), %rsi
movq %rbx, %rdi
callq *%rax
xorl %ecx, %ecx
jmp 0xf148
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xf0df
movq 0x18(%r14), %rsi
callq *%rax
movzwl (%rbx), %ecx
movq %r15, %rax
shlq $0x10, %rax
movzwl %cx, %ecx
orq %rax, %rcx
movq %rcx, (%rbx)
testq %r15, %r15
je 0xf10c
movq (%r15), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
xorl %ecx, %edx
movl %edx, %ecx
shrl $0x10, %ecx
xorl %edx, %ecx
movzwl %cx, %ecx
jmp 0xf10e
xorl %ecx, %ecx
orq %rcx, %rax
movq %rax, (%rbx)
movb $0x1, %cl
jmp 0xf148
xorl %edx, %edx
orq %rcx, %rdx
movq %rdx, (%rax)
movb $0x1, %cl
testq %r15, %r15
je 0xf148
xorl %edx, %edx
movq -0x250(%rbp,%rdx,8), %rsi
movq 0x8(%rsi,%rdx,8), %rdi
movq %rdi, 0x8(%rax,%rdx,8)
movq %rax, 0x8(%rsi,%rdx,8)
incq %rdx
cmpq %rdx, %r12
jne 0xf129
movl %ecx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x66ef
jmp 0xef02