// File: /workspace/github_cpp_makefile_star2_O2/chahk0129[P]hash_bench/./index/linear_probing.h
// Function: LinearProbingHash<char [32]>::Insert(char (&) [32], long)
void LinearProbingHash<Key_t>::Insert(Key_t& key, Value_t value){
    uint64_t key_hash;
    if constexpr(sizeof(Key_t) > 8)
	key_hash = h(key, sizeof(Key_t));
    else
	key_hash = h(&key, sizeof(Key_t));

RETRY:
    while(resizing_lock){
	asm("nop");
    }

    auto loc = key_hash;
    if(size < capacity*kResizingThreshold){
	int i = 0;
	while(i < capacity){
	    auto slot = (loc + i) % capacity;
	    unique_lock<shared_mutex> lock(mutex[slot/locksize]);
	    do{
		if constexpr(sizeof(Key_t) > 8){
		    if(memcmp(dict[slot].key, INVALID<Key_t>, sizeof(Key_t)) == 0){
			memcpy(dict[slot].key, key, sizeof(Key_t));
			memcpy(&dict[slot].value, &value, sizeof(Value_t));
			auto _size = size;
			while(!CAS(&size, &_size, _size+1)){
			    _size = size;
			}
			return;
		    }
		}
		else{
		    if(memcmp(&dict[slot].key, &INVALID<Key_t>, sizeof(Key_t)) == 0){
			memcpy(&dict[slot].key, &key, sizeof(Key_t));
			memcpy(&dict[slot].value, &value, sizeof(Value_t));
			auto _size = size;
			while(!CAS(&size, &_size, _size+1)){
			    _size = size;
			}
			return;
		    }
		}
		i++;
		slot = (loc + i) % capacity;
		if(!(i < capacity)) break;
	    }while(slot % locksize != 0);
	}
    }else{
	auto unlocked = 0;
	if(CAS(&resizing_lock, &unlocked, 1)){
#ifdef BREAKDOWN
	    clock_gettime(CLOCK_MONOTONIC, &t_start);
#endif
	    resize(capacity * kResizingFactor);
	    resizing_lock = 0;
#ifdef BREAKDOWN
	    clock_gettime(CLOCK_MONOTONIC, &t_end);
	    split_time += t_end.tv_nsec - t_start.tv_nsec + (t_end.tv_sec - t_start.tv_sec)*1000000000;
#endif
	}
    }
    goto RETRY;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x18(%rsp)
movq %rsi, %rax
movq %rdi, %rbx
pushq $0x20
popq %rsi
movl $0xc70697, %edx         # imm = 0xC70697
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x2040
movq %rax, 0x20(%rsp)
incq %rax
movq %rax, 0x28(%rsp)
leaq 0x38(%rsp), %r13
movq %rbx, 0x8(%rsp)
cmpl $0x0, 0x38(%rbx)
je 0x84a2
nop
jmp 0x8499
movq 0x10(%rbx), %rax
movq 0x30(%rbx), %rcx
testq %rcx, %rcx
js 0x84b6
cvtsi2ss %rcx, %xmm0
jmp 0x84cb
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
testq %rax, %rax
js 0x84d7
cvtsi2ss %rax, %xmm1
jmp 0x84ec
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
mulss 0xc(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x85f2
xorl %r15d, %r15d
movslq %r15d, %r12
movq 0x10(%rbx), %rcx
cmpq %r12, %rcx
jbe 0x8499
movq 0x20(%rsp), %rax
addq %r12, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rbp
movslq 0x4c(%rbx), %rcx
movq %rdx, %rax
xorl %edx, %edx
divq %rcx
imulq $0x38, %rax, %rsi
addq 0x40(%rbx), %rsi
movq %r13, %rdi
callq 0x8a0c
movq %rbx, %rax
movq 0x10(%rbx), %rbx
movq 0x18(%rax), %r13
movslq 0x4c(%rax), %rax
movq %rax, 0x30(%rsp)
imulq $0x28, %rbp, %r15
leaq (%r15,%r13), %rbp
movq %rbp, %rdi
leaq 0xbd85(%rip), %rsi      # 0x142e0
pushq $0x20
popq %rdx
callq 0x2200
movl %eax, %r14d
testl %eax, %eax
je 0x859d
leaq 0x1(%r12), %r15
cmpq %r15, %rbx
jbe 0x8596
movq 0x28(%rsp), %rax
addq %r12, %rax
xorl %edx, %edx
divq %rbx
movq %rdx, %rbp
movq %rdx, %rax
xorl %edx, %edx
divq 0x30(%rsp)
incq %r12
testq %rdx, %rdx
jne 0x8549
movq 0x8(%rsp), %rbx
jmp 0x85d7
movq 0x10(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x10(%rbp)
movups %xmm0, (%rbp)
movq 0x8(%rsp), %rbx
movq 0x18(%rbx), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x20(%rax,%r15)
movq 0x30(%rbx), %rax
leaq 0x1(%rax), %rcx
lock
cmpxchgq %rcx, 0x30(%rbx)
jne 0x85c4
movq %r12, %r15
leaq 0x38(%rsp), %r13
movq %r13, %rdi
callq 0x8a22
testl %r14d, %r14d
jne 0x84fd
jmp 0x86ae
xorl %eax, %eax
pushq $0x1
popq %rcx
lock
cmpxchgl %ecx, 0x38(%rbx)
jne 0x8499
pushq $0x1
popq %rdi
leaq 0xbca4(%rip), %rsi      # 0x142b0
callq 0x21b0
movq 0x10(%rbx), %rax
testq %rax, %rax
js 0x8621
cvtsi2ss %rax, %xmm0
jmp 0x8636
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
mulss 0x8(%rbx), %xmm0
cvttss2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subss 0x3a49(%rip), %xmm0     # 0xc098
cvttss2si %xmm0, %rsi
andq %rcx, %rsi
orq %rax, %rsi
movq %rbx, %rdi
callq 0x8a38
andl $0x0, 0x38(%rbx)
pushq $0x1
popq %rdi
leaq 0xbc50(%rip), %rsi      # 0x142c0
callq 0x21b0
movq 0xbc4c(%rip), %rax      # 0x142c8
subq 0xbc35(%rip), %rax      # 0x142b8
movq 0xbc36(%rip), %rcx      # 0x142c0
subq 0xbc1f(%rip), %rcx      # 0x142b0
imulq $0x3b9aca00, %rcx, %rcx # imm = 0x3B9ACA00
addq 0xbc01(%rip), %rax      # 0x142a0
addq %rcx, %rax
movq %rax, 0xbbf7(%rip)      # 0x142a0
jmp 0x8499
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop