// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rdx, 0x18(%rsp)
movq %rsi, %rax
movq %rdi, %r15
movl $0x20, %esi
movl $0xc70697, %edx         # imm = 0xC70697
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x2050
movq %rax, 0x20(%rsp)
leaq 0x1(%rax), %rbx
cmpl $0x0, 0x38(%r15)
je 0x96e5
nop
jmp 0x96db
movq 0x10(%r15), %rax
movq 0x30(%r15), %rcx
testq %rcx, %rcx
js 0x96fc
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
jmp 0x9714
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
testq %rax, %rax
js 0x9723
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
jmp 0x973b
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
mulss 0xc(%r15), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x9857
xorl %r12d, %r12d
movslq %r12d, %r14
movq 0x10(%r15), %rcx
cmpq %r14, %rcx
jbe 0x96db
movq 0x20(%rsp), %rax
addq %r14, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rbp
movslq 0x4c(%r15), %rcx
movq %rdx, %rax
xorl %edx, %edx
divq %rcx
imulq $0x38, %rax, %rax
addq 0x40(%r15), %rax
movq %rax, (%rsp)
movb $0x0, 0x8(%rsp)
movq %rsp, %rdi
callq 0xa0ba
movb $0x1, 0x8(%rsp)
movq 0x10(%r15), %rdi
movq 0x18(%r15), %rsi
movslq 0x4c(%r15), %r8
leaq (,%rbp,4), %rax
addq %rbp, %rax
movdqu 0x10(%rsi,%rax,8), %xmm0
pcmpeqb 0xab28(%rip), %xmm0     # 0x142e0
movdqu (%rsi,%rax,8), %xmm1
pcmpeqb 0xab0b(%rip), %xmm1     # 0x142d0
pand %xmm0, %xmm1
pmovmskb %xmm1, %ecx
xorl %r13d, %r13d
cmpl $0xffff, %ecx           # imm = 0xFFFF
setne %cl
je 0x9802
leaq 0x1(%r14), %r12
cmpq %r12, %rdi
jbe 0x983e
leaq (%rbx,%r14), %rax
xorl %edx, %edx
divq %rdi
movq %rdx, %rbp
movq %rdx, %rax
xorl %edx, %edx
divq %r8
incq %r14
testq %rdx, %rdx
jne 0x979f
jmp 0x983e
leaq (%rsi,%rax,8), %rdx
movq 0x10(%rsp), %rsi
movdqu (%rsi), %xmm0
movdqu 0x10(%rsi), %xmm1
movdqu %xmm1, 0x10(%rdx)
movdqu %xmm0, (%rdx)
movq 0x18(%r15), %rdx
movq 0x18(%rsp), %rsi
movq %rsi, 0x20(%rdx,%rax,8)
movq 0x30(%r15), %rax
leaq 0x1(%rax), %rdx
lock
cmpxchgq %rdx, 0x30(%r15)
jne 0x982b
movq %r14, %r12
movb %cl, %r13b
movq %rsp, %rdi
callq 0x9de6
testl %r13d, %r13d
jne 0x974d
jmp 0x9925
xorl %eax, %eax
movl $0x1, %ecx
lock
cmpxchgl %ecx, 0x38(%r15)
jne 0x96db
movl $0x1, %edi
leaq 0xaa2a(%rip), %rsi      # 0x142a0
callq 0x21b0
movq 0x10(%r15), %rax
testq %rax, %rax
js 0x988e
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x98a6
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
mulss 0x8(%r15), %xmm0
cvttss2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subss 0x37d0(%rip), %xmm0     # 0xd090
cvttss2si %xmm0, %rsi
andq %rcx, %rsi
orq %rax, %rsi
movq %r15, %rdi
callq 0x9dfc
movl $0x0, 0x38(%r15)
movl $0x1, %edi
leaq 0xa9c9(%rip), %rsi      # 0x142b0
callq 0x21b0
movq 0xa9c5(%rip), %rax      # 0x142b8
subq 0xa9ae(%rip), %rax      # 0x142a8
movq 0xa9af(%rip), %rcx      # 0x142b0
subq 0xa998(%rip), %rcx      # 0x142a0
imulq $0x3b9aca00, %rcx, %rcx # imm = 0x3B9ACA00
addq 0xa97a(%rip), %rax      # 0x14290
addq %rcx, %rax
movq %rax, 0xa970(%rip)      # 0x14290
jmp 0x96db
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq