// File: /workspace/github_cpp_makefile_star2_O1/attractivechaos[P]udb2/verstable/./verstable.h
// Function: intmap_t_insert_raw
static inline VT_CAT( NAME, _itr ) VT_CAT( NAME, _insert_raw )(
  NAME *table,
  KEY_TY key,
  #ifdef VAL_TY
  VAL_TY val,
  #endif
  bool unique,
  bool replace
)
{
  if( !table->bucket_count )
    return VT_CAT( NAME, _end_itr )( table );

  uint64_t hash = HASH_FN( key );
  size_t home_bucket = hash & ( table->bucket_count - 1 );
  uint16_t hashfrag = VT_HASH_FRAG( hash );

  // Case 1: The home bucket is empty or contains a key that doesn't belong there.
  if( !( table->metadata[ home_bucket ] & VT_IN_HOME_BUCKET_MASK ) )
  {
    if( table->key_count + 1 > table->bucket_count * MAX_LOAD )
      return VT_CAT( NAME, _end_itr )( table );

    if( table->metadata[ home_bucket ] != VT_EMPTY )
      if( !VT_CAT( NAME, _evict )( table, home_bucket ) )
        return VT_CAT( NAME, _end_itr )( table );

    table->buckets[ home_bucket ].key = key;
    #ifdef VAL_TY
    table->buckets[ home_bucket ].val = val;
    #endif
    table->metadata[ home_bucket ] = hashfrag | VT_IN_HOME_BUCKET_MASK | VT_DISPLACEMENT_MASK;

    ++table->key_count;

    VT_CAT( NAME, _itr ) itr = {
      table->buckets + home_bucket,
      table->metadata + home_bucket,
      table->metadata + table->bucket_count,
      home_bucket
    };
    return itr;
  }

  // Case 2: The home bucket contains the beginning of a chain.

  // Optionally, check the existing chain.
  if( !unique )
  {
    size_t bucket = home_bucket;
    while( true )
    {
      if(
        ( table->metadata[ bucket ] & VT_HASH_FRAG_MASK ) == hashfrag &&
        CMPR_FN( table->buckets[ bucket ].key, key )
      )
      {
        if( replace )
        {
          #ifdef KEY_DTOR_FN
          KEY_DTOR_FN( table->buckets[ bucket ].key );
          #endif
          table->buckets[ bucket ].key = key;

          #ifdef VAL_TY
          #ifdef VAL_DTOR_FN
          VAL_DTOR_FN( table->buckets[ bucket ].val );
          #endif
          table->buckets[ bucket ].val = val;
          #endif
        }

        VT_CAT( NAME, _itr ) itr = {
          table->buckets + bucket,
          table->metadata + bucket,
          table->metadata + table->bucket_count,
          home_bucket
        };
        return itr;
      }

      uint16_t displacement = table->metadata[ bucket ] & VT_DISPLACEMENT_MASK;
      if( displacement == VT_DISPLACEMENT_MASK )
        break;

      bucket = ( home_bucket + VT_QUADRATIC( displacement ) ) & ( table->bucket_count - 1 );
    }
  }

  if( table->key_count + 1 > table->bucket_count * MAX_LOAD )
    return VT_CAT( NAME, _end_itr )( table );

  // Find the earliest empty bucket, per quadratic probing.
  size_t empty;
  uint16_t displacement;
  if( !VT_CAT( NAME, _find_first_empty )( table, home_bucket, &empty, &displacement ) )
    return VT_CAT( NAME, _end_itr )( table );

  size_t prev = VT_CAT( NAME, _find_insert_location_in_chain )( table, home_bucket, displacement );

  // Insert the new key (and value) in the empty bucket and link it to the chain.
  table->buckets[ empty ].key = key;
  #ifdef VAL_TY
  table->buckets[ empty ].val = val;
  #endif
  table->metadata[ empty ] = hashfrag | ( table->metadata[ prev ] & VT_DISPLACEMENT_MASK );
  table->metadata[ prev ] = ( table->metadata[ prev ] & ~VT_DISPLACEMENT_MASK ) | displacement;

  ++table->key_count;


  VT_CAT( NAME, _itr ) itr = {
    table->buckets + empty,
    table->metadata + empty,
    table->metadata + table->bucket_count,
    home_bucket
  };
  return itr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rax
movq 0x8(%rsi), %r9
testq %r9, %r9
je 0x1cbe
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
addq %r9, %r11
movl %r11d, %edi
andl %edx, %edi
movq 0x10(%rsi), %r10
movzwl (%r10,%rdi,2), %ebx
btl $0xb, %ebx
jb 0x1a63
movq (%rsi), %r8
incq %r8
movq %r8, %xmm0
movq 0x6bf(%rip), %xmm1      # 0x2030
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x6c3(%rip), %xmm2      # 0x2040
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %r9, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x672(%rip), %xmm1      # 0x2020
ucomisd %xmm1, %xmm3
ja 0x1cbe
testw %bx, %bx
je 0x1c86
movq 0x18(%rsi), %r12
andl (%r12,%rdi,8), %r11d
decq %r9
movq %r11, %r8
movq %r8, %r14
movzwl (%r10,%r8,2), %r15d
andl $0x7ff, %r15d           # imm = 0x7FF
leal 0x1(%r15), %r8d
imull %r15d, %r8d
shrl %r8d
addq %r11, %r8
andq %r9, %r8
cmpq %rdi, %r8
cmoveq %r14, %r8
jne 0x19cf
movzwl (%r10,%r8,2), %ebp
andl $0xfffff800, %ebp       # imm = 0xFFFFF800
andl $0x7ff, %ebx            # imm = 0x7FF
orl %ebp, %ebx
movw %bx, (%r10,%r8,2)
leaq 0x1(%r11), %r14
andq %r9, %r14
cmpw $0x0, (%r10,%r14,2)
sete %bpl
je 0x1bf5
movl $0x1, %r8d
movl $0x2, %ebx
addq %rbx, %r8
leaq (%r8,%r11), %r14
andq %r9, %r14
cmpw $0x0, (%r10,%r14,2)
sete %bpl
je 0x1bf9
incq %rbx
cmpq $0x7ff, %rbx            # imm = 0x7FF
jne 0x1a32
movw $0x7ff, %bx             # imm = 0x7FF
xorl %ebp, %ebp
jmp 0x1bf9
testb %r8b, %r8b
jne 0x1ab5
leaq -0x1(%r9), %r8
movl $0x7ff, %r11d           # imm = 0x7FF
movq %rdi, %rbx
movzwl (%r10,%rbx,2), %r14d
cmpl $0xfff, %r14d           # imm = 0xFFF
ja 0x1a91
movq 0x18(%rsi), %r15
cmpl %edx, (%r15,%rbx,8)
je 0x1b5d
andl %r11d, %r14d
cmpl %r11d, %r14d
je 0x1aa9
leal 0x1(%r14), %ebx
imull %r14d, %ebx
shrl %ebx
addq %rdi, %rbx
andq %r8, %rbx
movzwl %r14w, %ebp
cmpl $0x7ff, %ebp            # imm = 0x7FF
jne 0x1a75
movq (%rsi), %r8
incq %r8
movq %r8, %xmm0
movq 0x568(%rip), %xmm1      # 0x2030
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x56c(%rip), %xmm2      # 0x2040
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %r9, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x51b(%rip), %xmm1      # 0x2020
ucomisd %xmm1, %xmm3
ja 0x1cbe
leaq 0x1(%rdi), %r14
leaq -0x1(%r9), %rbx
andq %rbx, %r14
cmpw $0x0, (%r10,%r14,2)
sete %bpl
je 0x1b6e
movl $0x1, %r15d
movl $0x2, %r11d
movw $0x7fd, %r12w           # imm = 0x7FD
addq %r11, %r15
leaq (%r15,%rdi), %r14
andq %rbx, %r14
cmpw $0x0, (%r10,%r14,2)
sete %bpl
je 0x1b73
incq %r11
decw %r12w
jne 0x1b37
movw $0x7ff, %r11w           # imm = 0x7FF
jmp 0x1b73
leaq (%r10,%rbx,2), %rcx
leaq (%r15,%rbx,8), %rdx
movq %rdx, (%rax)
movq %rcx, 0x8(%rax)
jmp 0x1bec
movw $0x1, %r11w
testb %bpl, %bpl
je 0x1cbe
movq %rdi, %r15
movzwl (%r10,%r15,2), %ebp
andl $0x7ff, %ebp            # imm = 0x7FF
movq %r15, %r13
cmpw %r11w, %bp
ja 0x1ba7
leal 0x1(%rbp), %r15d
imull %ebp, %r15d
shrl %r15d
addq %rdi, %r15
andq %rbx, %r15
movq %r12, %r13
movq %r13, %r12
cmpw %r11w, %bp
jbe 0x1b7f
movq 0x18(%rsi), %rbx
leaq (%rbx,%r14,8), %rbx
movl %edx, (%rbx)
movl %ecx, 0x4(%rbx)
movzwl (%r10,%r13,2), %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
leaq (%r10,%r14,2), %rdx
movw %cx, (%rdx)
movzwl (%r10,%r13,2), %ecx
andl $0xfffff800, %ecx       # imm = 0xFFFFF800
orl %ecx, %r11d
movw %r11w, (%r10,%r13,2)
movq %r8, (%rsi)
movq %rbx, (%rax)
movq %rdx, 0x8(%rax)
leaq (%r10,%r9,2), %rcx
jmp 0x1cb4
movw $0x1, %bx
testb %bpl, %bpl
je 0x1cbe
movq %r12, -0x8(%rsp)
movq %r11, %r15
movzwl (%r10,%r15,2), %r8d
andl $0x7ff, %r8d            # imm = 0x7FF
movq %r15, %r12
cmpw %bx, %r8w
ja 0x1c33
leal 0x1(%r8), %r15d
imull %r8d, %r15d
shrl %r15d
addq %r11, %r15
andq %r9, %r15
movq %r13, %r12
movq %r12, %r13
cmpw %bx, %r8w
jbe 0x1c0a
movq -0x8(%rsp), %r9
movq (%r9,%rdi,8), %r8
movq %r8, (%r9,%r14,8)
movq 0x10(%rsi), %r8
movzwl (%r8,%rdi,2), %r9d
andl $0xfffff000, %r9d       # imm = 0xFFFFF000
movzwl (%r8,%r12,2), %r10d
andl $0x7ff, %r10d           # imm = 0x7FF
orl %r9d, %r10d
movw %r10w, (%r8,%r14,2)
movzwl (%r8,%r12,2), %r9d
andl $0xfffff800, %r9d       # imm = 0xFFFFF800
orl %r9d, %ebx
movw %bx, (%r8,%r12,2)
testb %bpl, %bpl
je 0x1cbe
movq 0x18(%rsi), %r8
leaq (%r8,%rdi,8), %r8
movl %edx, (%r8)
movl %ecx, 0x4(%r8)
movq 0x10(%rsi), %rcx
leaq (%rcx,%rdi,2), %rdx
movw $0xfff, (%rdx)          # imm = 0xFFF
incq (%rsi)
movq %r8, (%rax)
movq %rdx, 0x8(%rax)
movq 0x8(%rsi), %rdx
leaq (%rcx,%rdx,2), %rcx
movq %rcx, 0x10(%rax)
movq %rdi, 0x18(%rax)
jmp 0x1ccb
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rax)
movupd %xmm0, (%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq