// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x8(%rsi), %r12
testq %r12, %r12
je 0x1a71
movq %rsi, %r15
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
addq %r12, %r13
movl %r13d, %r14d
andl %edx, %r14d
movq 0x10(%rsi), %rbp
movzwl (%rbp,%r14,2), %eax
btl $0xb, %eax
jb 0x1985
movq (%r15), %rsi
incq %rsi
movq %rsi, %xmm0
movq 0x7fd(%rip), %xmm1      # 0x2030
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x801(%rip), %xmm2      # 0x2040
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %r12, %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 0x7b0(%rip), %xmm1      # 0x2020
ucomisd %xmm1, %xmm3
ja 0x1a71
testw %ax, %ax
je 0x195d
movl %edx, 0x10(%rsp)
movl %ecx, 0x14(%rsp)
movq 0x18(%r15), %rcx
movq %rcx, 0x18(%rsp)
andl (%rcx,%r14,8), %r13d
decq %r12
movq %r13, %rsi
movq %rsi, %rcx
movzwl (%rbp,%rsi,2), %edx
movl %edx, %edi
andl $0x7ff, %edi            # imm = 0x7FF
leal 0x1(%rdi), %esi
imull %edi, %esi
shrl %esi
addq %r13, %rsi
andq %r12, %rsi
cmpq %r14, %rsi
jne 0x189e
andl $0xfffff800, %edx       # imm = 0xFFFFF800
andl $0x7ff, %eax            # imm = 0x7FF
orl %edx, %eax
movw %ax, (%rbp,%rcx,2)
leaq 0x20(%rsp), %rdx
leaq 0xe(%rsp), %rcx
movq %r15, %rdi
movq %r13, %rsi
callq 0x1afe
testb %al, %al
je 0x1a71
movzwl 0xe(%rsp), %r12d
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1b45
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rsi
movq (%rsi,%r14,8), %rdx
movq %rdx, (%rsi,%rcx,8)
movq 0x10(%r15), %rbp
movzwl (%rbp,%r14,2), %edx
andl $0xfffff000, %edx       # imm = 0xFFFFF000
movzwl (%rbp,%rax,2), %esi
andl $0x7ff, %esi            # imm = 0x7FF
orl %edx, %esi
movw %si, (%rbp,%rcx,2)
movzwl (%rbp,%rax,2), %ecx
andl $0xfffff800, %ecx       # imm = 0xFFFFF800
orl %r12d, %ecx
movw %cx, (%rbp,%rax,2)
movq (%r15), %rsi
movq 0x8(%r15), %r12
incq %rsi
movl 0x14(%rsp), %ecx
movl 0x10(%rsp), %edx
movq 0x18(%r15), %rax
leaq (%rax,%r14,8), %rax
movl %edx, (%rax)
movl %ecx, 0x4(%rax)
leaq (,%r14,2), %rdx
addq %rbp, %rdx
movw $0xfff, (%rdx)          # imm = 0xFFF
movq %rsi, (%r15)
movq %rax, (%rbx)
jmp 0x1a6b
testb %r8b, %r8b
je 0x1a80
movq (%r15), %r13
incq %r13
movq %r13, %xmm0
movq 0x68f(%rip), %xmm1      # 0x2030
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x693(%rip), %xmm2      # 0x2040
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %r12, %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 0x642(%rip), %xmm1      # 0x2020
ucomisd %xmm1, %xmm3
ja 0x1a71
movl %edx, 0x10(%rsp)
movl %ecx, 0x14(%rsp)
leaq 0x20(%rsp), %rdx
leaq 0xe(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rsi
callq 0x1afe
testb %al, %al
je 0x1a71
movzwl 0xe(%rsp), %edx
movq %rdx, 0x18(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x1b45
movq 0x18(%r15), %rcx
movq 0x20(%rsp), %rdx
leaq (%rcx,%rdx,8), %rcx
movl 0x10(%rsp), %esi
movl %esi, (%rcx)
movl 0x14(%rsp), %esi
movl %esi, 0x4(%rcx)
movzwl (%rbp,%rax,2), %esi
andl $0x7ff, %esi            # imm = 0x7FF
leaq (,%rdx,2), %rdx
addq %rbp, %rdx
movw %si, (%rdx)
movzwl (%rbp,%rax,2), %esi
andl $0xfffff800, %esi       # imm = 0xFFFFF800
orl 0x18(%rsp), %esi
movw %si, (%rbp,%rax,2)
movq %r13, (%r15)
movq %rcx, (%rbx)
movq %rdx, 0x8(%rbx)
jmp 0x1ad9
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rbx)
movupd %xmm0, (%rbx)
jmp 0x1aec
leaq -0x1(%r12), %rdi
movq %r14, %r8
cmpw $0xfff, %ax             # imm = 0xFFF
ja 0x1a98
movq 0x18(%r15), %rsi
cmpl %edx, (%rsi,%r8,8)
je 0x1ac3
andl $0x7ff, %eax            # imm = 0x7FF
cmpw $0x7ff, %ax             # imm = 0x7FF
je 0x198e
movzwl %ax, %eax
leal 0x1(%rax), %r8d
imull %eax, %r8d
shrl %r8d
addq %r14, %r8
andq %rdi, %r8
movzwl (%rbp,%r8,2), %eax
jmp 0x1a88
leaq (,%r8,2), %rax
addq %rbp, %rax
leaq (%rsi,%r8,8), %rcx
movq %rcx, (%rbx)
movq %rax, 0x8(%rbx)
leaq (,%r12,2), %rax
addq %rbp, %rax
movq %rax, 0x10(%rbx)
movq %r14, 0x18(%rbx)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq