// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/struct.c
// Function: janet_struct_put_ext
void janet_struct_put_ext(JanetKV *st, Janet key, Janet value, int replace) {
    int32_t cap = janet_struct_capacity(st);
    int32_t hash = janet_hash(key);
    int32_t index = janet_maphash(cap, hash);
    int32_t i, j, dist;
    int32_t bounds[4] = {index, cap, 0, index};
    if (janet_checktype(key, JANET_NIL) || janet_checktype(value, JANET_NIL)) return;
    if (janet_checktype(key, JANET_NUMBER) && isnan(janet_unwrap_number(key))) return;
    /* Avoid extra items */
    if (janet_struct_hash(st) == janet_struct_length(st)) return;
    for (dist = 0, j = 0; j < 4; j += 2)
        for (i = bounds[j]; i < bounds[j + 1]; i++, dist++) {
            int status;
            int32_t otherhash;
            int32_t otherindex, otherdist;
            JanetKV *kv = st + i;
            /* We found an empty slot, so just add key and value */
            if (janet_checktype(kv->key, JANET_NIL)) {
                kv->key = key;
                kv->value = value;
                /* Update the temporary count */
                janet_struct_hash(st)++;
                return;
            }
            /* Robinhood hashing - check if colliding kv pair
             * is closer to their source than current. We use robinhood
             * hashing to ensure that equivalent structs that are constructed
             * with different order have the same internal layout, and therefor
             * will compare properly - i.e., {1 2 3 4} should equal {3 4 1 2}.
             * Collisions are resolved via an insertion sort insertion. */
            otherhash = janet_hash(kv->key);
            otherindex = janet_maphash(cap, otherhash);
            otherdist = (i + cap - otherindex) & (cap - 1);
            if (dist < otherdist)
                status = -1;
            else if (otherdist < dist)
                status = 1;
            else if (hash < otherhash)
                status = -1;
            else if (otherhash < hash)
                status = 1;
            else
                status = janet_compare(key, kv->key);
            /* If other is closer to their ideal slot */
            if (status == 1) {
                /* Swap current kv pair with pair in slot */
                JanetKV temp = *kv;
                kv->key = key;
                kv->value = value;
                key = temp.key;
                value = temp.value;
                /* Save dist and hash of new kv pair */
                dist = otherdist;
                hash = otherhash;
            } else if (status == 0) {
                if (replace) {
                    /* A key was added to the struct more than once - replace old value */
                    kv->value = value;
                }
                return;
            }
        }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl -0x10(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6f030
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x44(%rbp)
xorl %eax, %eax
testb $0x1, %al
jne 0x679ff
jmp 0x67a25
movsd -0x8(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x67a11
jmp 0x67a8d
movq -0x8(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x67a8d
jmp 0x67a42
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0x8(%rbp), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
je 0x67a8d
xorl %eax, %eax
testb $0x1, %al
jne 0x67a4a
jmp 0x67a70
movsd -0x10(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x67a5c
jmp 0x67a8d
movq -0x10(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x67a8d
jmp 0x67a92
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0x10(%rbp), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
jne 0x67a92
jmp 0x67cf3
movb $0x1, %al
testb $0x1, %al
jne 0x67a9a
jmp 0x67ac0
movsd -0x8(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x67aac
jmp 0x67add
movq -0x8(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x67add
jmp 0x67af4
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0x8(%rbp), %rax
movabsq $-0x8000000000000, %rcx # imm = 0xFFF8000000000000
cmpq %rcx, %rax
jne 0x67af4
movsd -0x8(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x67aef
jmp 0x67af4
jmp 0x67cf3
movq -0x18(%rbp), %rax
movl -0x14(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl -0x18(%rcx), %eax
jne 0x67b09
jmp 0x67cf3
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x4, -0x30(%rbp)
jge 0x67cf3
movslq -0x30(%rbp), %rax
movl -0x50(%rbp,%rax,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl -0x50(%rbp,%rcx,4), %eax
jge 0x67ce3
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
xorl %eax, %eax
testb $0x1, %al
jne 0x67b5d
jmp 0x67b89
movq -0x68(%rbp), %rax
movsd (%rax), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x67b72
jmp 0x67ba9
movq -0x68(%rbp), %rax
movq (%rax), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x67ba9
jmp 0x67bd2
movq -0x68(%rbp), %rcx
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq (%rcx), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
jne 0x67bd2
movq -0x68(%rbp), %rax
movq -0x8(%rbp), %rcx
movq %rcx, (%rax)
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl -0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rax)
jmp 0x67cf3
movq -0x68(%rbp), %rax
movq (%rax), %rdi
callq 0x6f030
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl -0x2c(%rbp), %eax
addl -0x20(%rbp), %eax
subl -0x5c(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x60(%rbp), %eax
jge 0x67c14
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
jmp 0x67c60
movl -0x60(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x67c25
movl $0x1, -0x54(%rbp)
jmp 0x67c5e
movl -0x24(%rbp), %eax
cmpl -0x58(%rbp), %eax
jge 0x67c36
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
jmp 0x67c5c
movl -0x58(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x67c47
movl $0x1, -0x54(%rbp)
jmp 0x67c5a
movq -0x68(%rbp), %rax
movq -0x8(%rbp), %rdi
movq (%rax), %rsi
callq 0x6f240
movl %eax, -0x54(%rbp)
jmp 0x67c5c
jmp 0x67c5e
jmp 0x67c60
cmpl $0x1, -0x54(%rbp)
jne 0x67cae
movq -0x68(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x78(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq -0x8(%rbp), %rcx
movq %rcx, (%rax)
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x67cca
cmpl $0x0, -0x54(%rbp)
jne 0x67cc8
cmpl $0x0, -0x1c(%rbp)
je 0x67cc6
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
jmp 0x67cf3
jmp 0x67cca
jmp 0x67ccc
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x67b2c
jmp 0x67ce5
movl -0x30(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x30(%rbp)
jmp 0x67b17
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)