// File: attractivechaos[P]udb2/libcuckoo/./cuckoohash_map.hh
// Function: cuckoohash_map<unsigned int, unsigned int, Hash32, std::equal_to<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int>>, 4ul>::table_position cuckoohash_map<unsigned int, unsigned int, Hash32, std::equal_to<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int>>, 4ul>::cuckoo_insert<std::integral_constant<bool, false>, unsigned int>(cuckoohash_map<unsigned int, unsigned int, Hash32, std::equal_to<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int>>, 4ul>::hash_value, cuckoohash_map<unsigned int, unsigned int, Hash32, std::equal_to<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int>>, 4ul>::TwoBuckets&, unsigned int&)
table_position cuckoo_insert(const hash_value hv, TwoBuckets &b, K &key) {
    int res1, res2;
    bucket &b1 = buckets_[b.i1];
    if (!try_find_insert_bucket(b1, res1, hv.partial, key)) {
      return table_position{b.i1, static_cast<size_type>(res1),
                            failure_key_duplicated};
    }
    bucket &b2 = buckets_[b.i2];
    if (!try_find_insert_bucket(b2, res2, hv.partial, key)) {
      return table_position{b.i2, static_cast<size_type>(res2),
                            failure_key_duplicated};
    }
    if (res1 != -1) {
      return table_position{b.i1, static_cast<size_type>(res1), ok};
    }
    if (res2 != -1) {
      return table_position{b.i2, static_cast<size_type>(res2), ok};
    }

    // We are unlucky, so let's perform cuckoo hashing.
    size_type insert_bucket = 0;
    size_type insert_slot = 0;
    cuckoo_status st = run_cuckoo<TABLE_MODE>(b, insert_bucket, insert_slot);
    if (st == failure_under_expansion) {
      // The run_cuckoo operation operated on an old version of the table,
      // so we have to try again. We signal to the calling insert method
      // to try again by returning failure_under_expansion.
      return table_position{0, 0, failure_under_expansion};
    } else if (st == ok) {
      assert(TABLE_MODE() == locked_table_mode() ||
             !get_current_locks()[lock_ind(b.i1)].try_lock());
      assert(TABLE_MODE() == locked_table_mode() ||
             !get_current_locks()[lock_ind(b.i2)].try_lock());
      assert(!buckets_[insert_bucket].occupied(insert_slot));
      assert(insert_bucket == index_hash(hashpower(), hv.hash) ||
             insert_bucket == alt_index(hashpower(), hv.partial,
                                        index_hash(hashpower(), hv.hash)));
      // Since we unlocked the buckets during run_cuckoo, another insert
      // could have inserted the same key into either b.i1 or
      // b.i2, so we check for that before doing the insert.
      table_position pos = cuckoo_find(key, hv.partial, b.i1, b.i2);
      if (pos.status == ok) {
        pos.status = failure_key_duplicated;
        return pos;
      }
      return table_position{insert_bucket, insert_slot, ok};
    }
    assert(st == failure);
    LIBCUCKOO_DBG("hash table is full (hashpower = %zu, hash_items = %zu,"
                  "load factor = %.2f), need to increase hashpower\n",
                  hashpower(), size(), load_factor());
    return table_position{0, 0, failure_table_full};
  }

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0x40(%rsp)
movb %cl, %al
movq %rdi, 0x48(%rsp)
movq %rdx, 0xb8(%rsp)
movb %al, 0xc0(%rsp)
movq %rsi, 0xb0(%rsp)
movq %r8, 0xa8(%rsp)
movq %r9, 0xa0(%rsp)
movq 0xb0(%rsp), %rdi
movq %rdi, 0x50(%rsp)
addq $0x8, %rdi
movq 0xa8(%rsp), %rax
movq (%rax), %rsi
callq 0x4db0
movq 0x50(%rsp), %rdi
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rsi
movb 0xc0(%rsp), %al
movq 0xa0(%rsp), %r8
leaq 0x9c(%rsp), %rdx
movzbl %al, %ecx
callq 0x5d60
testb $0x1, %al
jne 0x56ce
movq 0x40(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
movslq 0x9c(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl $0x3, 0x10(%rax)
jmp 0x5acd
movq 0x50(%rsp), %rdi
addq $0x8, %rdi
movq 0xa8(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x4db0
movq 0x50(%rsp), %rdi
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rsi
movb 0xc0(%rsp), %al
movq 0xa0(%rsp), %r8
leaq 0x98(%rsp), %rdx
movzbl %al, %ecx
callq 0x5d60
testb $0x1, %al
jne 0x574c
movq 0x40(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, (%rax)
movslq 0x98(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl $0x3, 0x10(%rax)
jmp 0x5acd
cmpl $-0x1, 0x9c(%rsp)
je 0x5781
movq 0x40(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
movslq 0x9c(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, 0x10(%rax)
jmp 0x5acd
cmpl $-0x1, 0x98(%rsp)
je 0x57b7
movq 0x40(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, (%rax)
movslq 0x98(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, 0x10(%rax)
jmp 0x5acd
movq 0x50(%rsp), %rdi
movq $0x0, 0x80(%rsp)
movq $0x0, 0x78(%rsp)
movq 0xa8(%rsp), %rsi
leaq 0x80(%rsp), %rdx
leaq 0x78(%rsp), %rcx
callq 0x5e40
movl %eax, 0x74(%rsp)
cmpl $0x5, 0x74(%rsp)
jne 0x5818
movq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x20d0
movq 0x40(%rsp), %rax
movl $0x5, 0x10(%rax)
jmp 0x5acd
cmpl $0x0, 0x74(%rsp)
jne 0x5a82
movq 0x50(%rsp), %rdi
callq 0x5170
movq %rax, 0x38(%rsp)
movq 0xa8(%rsp), %rax
movq (%rax), %rdi
callq 0x5110
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x5190
movq %rax, %rdi
callq 0x6160
xorb $-0x1, %al
testb $0x1, %al
jne 0x585f
jmp 0x5861
jmp 0x5880
leaq 0x8d25(%rip), %rdi      # 0xe58d
leaq 0x8a3f(%rip), %rsi      # 0xe2ae
movl $0x47d, %edx            # imm = 0x47D
leaq 0x8d69(%rip), %rcx      # 0xe5e4
callq 0x2110
movq 0x50(%rsp), %rdi
callq 0x5170
movq %rax, 0x30(%rsp)
movq 0xa8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x5110
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x5190
movq %rax, %rdi
callq 0x6160
xorb $-0x1, %al
testb $0x1, %al
jne 0x58bd
jmp 0x58bf
jmp 0x58de
leaq 0x8e94(%rip), %rdi      # 0xe75a
leaq 0x89e1(%rip), %rsi      # 0xe2ae
movl $0x47f, %edx            # imm = 0x47F
leaq 0x8d0b(%rip), %rcx      # 0xe5e4
callq 0x2110
movq 0x50(%rsp), %rdi
addq $0x8, %rdi
movq 0x80(%rsp), %rsi
callq 0x4db0
movq %rax, %rdi
movq 0x78(%rsp), %rsi
callq 0x3590
movb (%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x590b
jmp 0x590d
jmp 0x592c
leaq 0x8e9d(%rip), %rdi      # 0xe7b1
leaq 0x8993(%rip), %rsi      # 0xe2ae
movl $0x480, %edx            # imm = 0x480
leaq 0x8cbd(%rip), %rcx      # 0xe5e4
callq 0x2110
movq 0x50(%rsp), %rdi
movq 0x80(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0x4f30
movq %rax, %rdi
movq 0xb8(%rsp), %rsi
callq 0x4f50
movq 0x20(%rsp), %rcx
movq %rax, %rdx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, 0x2f(%rsp)
je 0x59cd
movq 0x50(%rsp), %rdi
movq 0x80(%rsp), %rax
movq %rax, 0x18(%rsp)
callq 0x4f30
movq 0x50(%rsp), %rdi
movq %rax, 0x8(%rsp)
movb 0xc0(%rsp), %al
movb %al, 0x17(%rsp)
callq 0x4f30
movq %rax, %rdi
movq 0xb8(%rsp), %rsi
callq 0x4f50
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movb 0x17(%rsp), %al
movzbl %al, %esi
callq 0x4f80
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
sete %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x59d7
jmp 0x59d9
jmp 0x59f8
leaq 0x8e00(%rip), %rdi      # 0xe7e0
leaq 0x88c7(%rip), %rsi      # 0xe2ae
movl $0x483, %edx            # imm = 0x483
leaq 0x8bf1(%rip), %rcx      # 0xe5e4
callq 0x2110
movq 0x50(%rsp), %rsi
movq 0xa0(%rsp), %rdx
movb 0xc0(%rsp), %al
movq 0xa8(%rsp), %rcx
movq (%rcx), %r8
movq 0xa8(%rsp), %rcx
movq 0x8(%rcx), %r9
leaq 0x58(%rsp), %rdi
movzbl %al, %ecx
callq 0x6200
cmpl $0x0, 0x68(%rsp)
jne 0x5a60
movq 0x40(%rsp), %rax
movl $0x3, 0x68(%rsp)
movq 0x58(%rsp), %rcx
movq %rcx, (%rax)
movq 0x60(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x68(%rsp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x5acd
movq 0x40(%rsp), %rax
movq 0x80(%rsp), %rcx
movq %rcx, (%rax)
movq 0x78(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, 0x10(%rax)
jmp 0x5acd
jmp 0x5a84
cmpl $0x1, 0x74(%rsp)
jne 0x5a8d
jmp 0x5aac
leaq 0x8dd7(%rip), %rdi      # 0xe86b
leaq 0x8813(%rip), %rsi      # 0xe2ae
movl $0x48e, %edx            # imm = 0x48E
leaq 0x8b3d(%rip), %rcx      # 0xe5e4
callq 0x2110
jmp 0x5aae
jmp 0x5ab0
movq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x20d0
movq 0x40(%rsp), %rax
movl $0x4, 0x10(%rax)
movq 0x48(%rsp), %rax
addq $0xc8, %rsp
retq
nopw (%rax,%rax)