// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
movq 0x8(%rsi), %r10
testq %r10, %r10
je 0x1ae1
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
addq %r10, %rbx
movl %ebx, %eax
andl %edx, %eax
movq 0x10(%rsi), %r9
movzwl (%r9,%rax,2), %r11d
btl $0xb, %r11d
jb 0x1a86
movq (%rsi), %r8
incq %r8
movq %r8, %xmm0
movq 0x68c(%rip), %xmm1      # 0x2030
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x690(%rip), %xmm2      # 0x2040
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %r10, %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 0x63f(%rip), %xmm1      # 0x2020
ucomisd %xmm1, %xmm3
ja 0x1ae1
testw %r11w, %r11w
je 0x1c90
movq 0x18(%rsi), %r8
andl (%r8,%rax,8), %ebx
decq %r10
movq %rbx, %r15
movq %r15, %r14
movzwl (%r9,%r15,2), %ebp
movl %ebp, %r12d
andl $0x7ff, %r12d           # imm = 0x7FF
leal 0x1(%r12), %r15d
imull %r12d, %r15d
shrl %r15d
addq %rbx, %r15
andq %r10, %r15
cmpq %rax, %r15
jne 0x1a03
andl $0xfffff800, %ebp       # imm = 0xFFFFF800
andl $0x7ff, %r11d           # imm = 0x7FF
orl %ebp, %r11d
movw %r11w, (%r9,%r14,2)
leaq 0x1(%rbx), %r14
andq %r10, %r14
cmpw $0x0, (%r9,%r14,2)
je 0x1c04
movl $0x1, %r15d
movl $0x2, %r11d
cmpq $0x7ff, %r11            # imm = 0x7FF
je 0x1ae1
addq %r11, %r15
leaq (%r15,%rbx), %r14
andq %r10, %r14
incq %r11
cmpw $0x0, (%r9,%r14,2)
jne 0x1a60
decl %r11d
jmp 0x1c09
testb %r8b, %r8b
je 0x1af3
movq (%rsi), %r8
incq %r8
movq %r8, %xmm0
movq 0x592(%rip), %xmm1      # 0x2030
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x596(%rip), %xmm2      # 0x2040
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %r10, %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 0x545(%rip), %xmm1      # 0x2020
ucomisd %xmm1, %xmm3
jbe 0x1b3f
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rdi)
movupd %xmm0, (%rdi)
jmp 0x1cbe
leaq -0x1(%r10), %r8
movl $0x7ff, %ebx            # imm = 0x7FF
movl %r11d, %ebp
movq %rax, %r14
movzwl %bp, %r15d
cmpl $0xfff, %r15d           # imm = 0xFFF
ja 0x1b19
movq 0x18(%rsi), %r15
cmpl %edx, (%r15,%r14,8)
je 0x1b83
andl %ebx, %ebp
cmpl %ebx, %ebp
je 0x1a8b
movzwl %bp, %r15d
leal 0x1(%r15), %r14d
imull %r15d, %r14d
shrl %r14d
addq %rax, %r14
andq %r8, %r14
movzwl (%r9,%r14,2), %ebp
jmp 0x1b02
leaq 0x1(%rax), %r15
leaq -0x1(%r10), %r14
andq %r14, %r15
cmpw $0x0, (%r9,%r15,2)
je 0x1b93
movl $0x1, %r12d
movl $0x2, %ebx
cmpq $0x7ff, %rbx            # imm = 0x7FF
je 0x1ae1
addq %rbx, %r12
leaq (%r12,%rax), %r15
andq %r14, %r15
incq %rbx
cmpw $0x0, (%r9,%r15,2)
jne 0x1b5d
decl %ebx
jmp 0x1b97
leaq (%r9,%r14,2), %rcx
leaq (%r15,%r14,8), %rdx
movq %rdx, (%rdi)
jmp 0x1cae
movw $0x1, %bx
andl $0x7ff, %r11d           # imm = 0x7FF
cmpw %bx, %r11w
jbe 0x1ba9
movq %rax, %r12
jmp 0x1bd0
movzwl %r11w, %r11d
leal 0x1(%r11), %r12d
imull %r11d, %r12d
shrl %r12d
addq %rax, %r12
andq %r14, %r12
movzwl (%r9,%r12,2), %r11d
andl $0x7ff, %r11d           # imm = 0x7FF
cmpw %bx, %r11w
jbe 0x1ba9
movq 0x18(%rsi), %r14
leaq (%r14,%r15,8), %r14
movl %edx, (%r14)
movl %ecx, 0x4(%r14)
leaq (%r9,%r15,2), %rcx
movw %r11w, (%rcx)
movzwl (%r9,%r12,2), %edx
andl $0xfffff800, %edx       # imm = 0xFFFFF800
orl %edx, %ebx
movw %bx, (%r9,%r12,2)
movq %r8, (%rsi)
movq %r14, (%rdi)
jmp 0x1cae
movw $0x1, %r11w
movzwl (%r9,%rbx,2), %ebp
andl $0x7ff, %ebp            # imm = 0x7FF
cmpw %r11w, %bp
jbe 0x1c1f
movq %rbx, %r15
jmp 0x1c46
movzwl %bp, %r12d
leal 0x1(%r12), %r15d
imull %r12d, %r15d
shrl %r15d
addq %rbx, %r15
andq %r10, %r15
movzwl (%r9,%r15,2), %ebp
andl $0x7ff, %ebp            # imm = 0x7FF
cmpw %r11w, %bp
jbe 0x1c1f
movq (%r8,%rax,8), %r9
movq %r9, (%r8,%r14,8)
movq 0x10(%rsi), %r9
movzwl (%r9,%rax,2), %r8d
andl $0xfffff000, %r8d       # imm = 0xFFFFF000
movzwl (%r9,%r15,2), %r10d
andl $0x7ff, %r10d           # imm = 0x7FF
orl %r8d, %r10d
movw %r10w, (%r9,%r14,2)
movzwl (%r9,%r15,2), %r8d
andl $0xfffff800, %r8d       # imm = 0xFFFFF800
orl %r8d, %r11d
movw %r11w, (%r9,%r15,2)
movq (%rsi), %r8
movq 0x8(%rsi), %r10
incq %r8
movq 0x18(%rsi), %r11
leaq (%r11,%rax,8), %r11
movl %edx, (%r11)
movl %ecx, 0x4(%r11)
leaq (%r9,%rax,2), %rcx
movw $0xfff, (%rcx)          # imm = 0xFFF
movq %r8, (%rsi)
movq %r11, (%rdi)
movq %rcx, 0x8(%rdi)
leaq (%r9,%r10,2), %rcx
movq %rcx, 0x10(%rdi)
movq %rax, 0x18(%rdi)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq