// File: /workspace/github_cpp_makefile_star2_O1/attractivechaos[P]udb2/bkthomps-hashmap/unordered_map.c
// Function: unordered_map_put
int unordered_map_put(unordered_map me, void *const key, void *const value)
{

    const unsigned long hash = me->hash(key);
    const int index = (int) (hash % me->capacity);
    if (!me->buckets[index]) {
        me->buckets[index] = unordered_map_create_element(me, hash, key, value);
        if (!me->buckets[index]) {
            return -ENOMEM;
        }
    } else {
        struct node *traverse = me->buckets[index];
        if (unordered_map_is_equal(me, traverse, hash, key)) {
            memcpy(traverse->value, value, me->value_size);
            return 0;
        }
        while (traverse->next) {
            traverse = traverse->next;
            if (unordered_map_is_equal(me, traverse, hash, key)) {
                memcpy(traverse->value, value, me->value_size);
                return 0;
            }
        }
        traverse->next = unordered_map_create_element(me, hash, key, value);
        if (!traverse->next) {
            return -ENOMEM;
        }
    }
    me->size++;
    if (me->size >= RESIZE_AT * me->capacity) {
        return unordered_map_resize(me);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, %rdi
callq *0x10(%rbx)
movq %rax, %r12
movslq 0x24(%rbx), %rcx
xorl %edx, %edx
divq %rcx
movq 0x28(%rbx), %rax
movslq %edx, %rbp
movq (%rax,%rbp,8), %r13
testq %r13, %r13
je 0x17f7
cmpq %r12, 0x10(%r13)
jne 0x1825
jmp 0x1837
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x195e
movq 0x28(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
movq 0x28(%rbx), %rax
cmpq $0x0, (%rax,%rbp,8)
jne 0x1883
movl $0xfffffff4, %ebp       # imm = 0xFFFFFFF4
jmp 0x1944
movq 0x18(%r13), %rax
testq %rax, %rax
je 0x185b
movq %rax, %r13
cmpq %r12, 0x10(%rax)
jne 0x1825
movq (%r13), %rdi
movq %r15, %rsi
callq *0x18(%rbx)
testl %eax, %eax
jne 0x1825
movq 0x8(%r13), %rdi
movq 0x8(%rbx), %rdx
movq %r14, %rsi
callq 0x1070
xorl %ebp, %ebp
xorl %eax, %eax
jmp 0x187b
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x195e
movq %rax, 0x18(%r13)
testq %rax, %rax
setne %al
movl $0xfffffff4, %ebp       # imm = 0xFFFFFFF4
testb %al, %al
je 0x1944
movl 0x20(%rbx), %eax
movl 0x24(%rbx), %r12d
incl %eax
cvtsi2sd %eax, %xmm1
movl %eax, 0x20(%rbx)
cvtsi2sd %r12d, %xmm0
movsd 0x7f8(%rip), %xmm2      # 0x2098
mulsd %xmm0, %xmm2
xorl %ebp, %ebp
ucomisd %xmm2, %xmm1
jb 0x1944
mulsd 0x7e8(%rip), %xmm0      # 0x20a0
cvttsd2si %xmm0, %r13d
movq 0x28(%rbx), %r14
movslq %r13d, %r15
movl $0x8, %esi
movq %r15, %rdi
callq 0x1050
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x1955
movl %r13d, 0x24(%rbx)
testl %r12d, %r12d
jle 0x193c
xorl %ecx, %ecx
movq (%r14,%rcx,8), %rsi
testq %rsi, %rsi
je 0x1934
movq 0x10(%rsi), %rax
movq 0x18(%rsi), %rdi
xorl %edx, %edx
divq %r15
movq $0x0, 0x18(%rsi)
movq 0x28(%rbx), %rax
movslq %edx, %r8
movq (%rax,%r8,8), %rdx
testq %rdx, %rdx
je 0x1925
movq %rdx, %rax
movq 0x18(%rdx), %rdx
testq %rdx, %rdx
jne 0x1913
addq $0x18, %rax
jmp 0x1929
leaq (%rax,%r8,8), %rax
movq %rsi, (%rax)
movq %rdi, %rsi
testq %rdi, %rdi
jne 0x18ee
incq %rcx
cmpq %r12, %rcx
jne 0x18e5
movq %r14, %rdi
callq 0x1030
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, 0x28(%rbx)
jmp 0x181b