// File: /workspace/github_cpp_makefile_star2_O3/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 0xa3df
nop
jmp 0xa3d5
movq 0x10(%r15), %rax
movq 0x30(%r15), %rcx
testq %rcx, %rcx
js 0xa3f6
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
jmp 0xa40e
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
testq %rax, %rax
js 0xa41d
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
jmp 0xa435
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 0xa551
xorl %r12d, %r12d
movslq %r12d, %r14
movq 0x10(%r15), %rcx
cmpq %r14, %rcx
jbe 0xa3d5
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 0xad3c
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 0xae2e(%rip), %xmm0     # 0x152e0
movdqu (%rsi,%rax,8), %xmm1
pcmpeqb 0xae11(%rip), %xmm1     # 0x152d0
pand %xmm0, %xmm1
pmovmskb %xmm1, %ecx
xorl %r13d, %r13d
cmpl $0xffff, %ecx           # imm = 0xFFFF
setne %cl
je 0xa4fc
leaq 0x1(%r14), %r12
cmpq %r12, %rdi
jbe 0xa538
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 0xa499
jmp 0xa538
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 0xa525
movq %r14, %r12
movb %cl, %r13b
movq %rsp, %rdi
callq 0xaa52
testl %r13d, %r13d
jne 0xa447
jmp 0xa61f
xorl %eax, %eax
movl $0x1, %ecx
lock
cmpxchgl %ecx, 0x38(%r15)
jne 0xa3d5
movl $0x1, %edi
leaq 0xad30(%rip), %rsi      # 0x152a0
callq 0x21b0
movq 0x10(%r15), %rax
testq %rax, %rax
js 0xa588
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0xa5a0
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 0x3b16(%rip), %xmm0     # 0xe0d0
cvttss2si %xmm0, %rsi
andq %rcx, %rsi
orq %rax, %rsi
movq %r15, %rdi
callq 0xaa68
movl $0x0, 0x38(%r15)
movl $0x1, %edi
leaq 0xaccf(%rip), %rsi      # 0x152b0
callq 0x21b0
movq 0xaccb(%rip), %rax      # 0x152b8
subq 0xacb4(%rip), %rax      # 0x152a8
movq 0xacb5(%rip), %rcx      # 0x152b0
subq 0xac9e(%rip), %rcx      # 0x152a0
imulq $0x3b9aca00, %rcx, %rcx # imm = 0x3B9ACA00
addq 0xac80(%rip), %rax      # 0x15290
addq %rcx, %rax
movq %rax, 0xac76(%rip)      # 0x15290
jmp 0xa3d5
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq