// File: /workspace/github_c_makefile_star2_O0/aerospike[P]aerospike-common/src/main/aerospike/as_orderedmap.c
// Function: as_orderedmap_set
int
as_orderedmap_set(as_orderedmap* map, const as_val* key, const as_val* val)
{
	if (map == NULL || ! is_valid_key_type(key)) {
		return -1;
	}

	as_val* cval = (as_val*)(val != NULL ? val : &as_nil);
	as_val* ckey = (as_val*)key;
	uint32_t ix;
	bool found = key_find(map->table, map->count, key, &ix, true);

	if (ix == UINT32_MAX) {
		return -1;
	}

	if (found) {
		as_val_destroy(map->table[ix].key);
		as_val_destroy(map->table[ix].value);
		map->table[ix].key = ckey;
		map->table[ix].value = cval;

		return 0;
	}

	if (ix + HOLD_TABLE_CAP > map->count) {
		// Near end of main table - insert directly.

		if (map->count == map->capacity) {
			map->capacity *= 2;

			map_entry* table = (map_entry*)cf_realloc(map->table,
					map->capacity * sizeof(map_entry));

			if (table == NULL) {
				return -1;
			}

			map->table = table;
		}

		memmove(&map->table[ix + 1], &map->table[ix],
				sizeof(map_entry) * (map->count - ix));
		map->table[ix].key = ckey;
		map->table[ix].value = cval;
		map->count++;

		return 0;
	}

	// Far from end of main table - insert in hold table.

	if (map->hold_table == NULL) {
		map->hold_table = cf_malloc(HOLD_TABLE_CAP * sizeof(map_entry));
		map->hold_locations = cf_malloc(HOLD_TABLE_CAP * sizeof(uint32_t));
	}

	uint32_t hold_ix;

	found = key_find(map->hold_table, map->hold_count, key, &hold_ix, false);

	if (hold_ix == UINT32_MAX) {
		return -1;
	}

	if (found) {
		as_val_destroy(map->hold_table[hold_ix].key);
		as_val_destroy(map->hold_table[hold_ix].value);
		map->hold_table[hold_ix].key = ckey;
		map->hold_table[hold_ix].value = cval;

		return 0;
	}

	if (map->hold_count == HOLD_TABLE_CAP) {
		return -1; // previous merge failed
	}

	memmove(&map->hold_table[hold_ix + 1], &map->hold_table[hold_ix],
			sizeof(map_entry) * (map->hold_count - hold_ix));
	map->hold_table[hold_ix].key = ckey;
	map->hold_table[hold_ix].value = cval;

	memmove(&map->hold_locations[hold_ix + 1], &map->hold_locations[hold_ix],
			sizeof(uint32_t) * (map->hold_count - hold_ix));
	map->hold_locations[hold_ix] = ix;

	map->hold_count++;

	if (map->hold_count == HOLD_TABLE_CAP) {
		as_orderedmap_merge(map);
		// Ignore merge allocation failure, next insert will fail.
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x13da8
movq -0x18(%rbp), %rdi
callq 0x13c00
testb $0x1, %al
jne 0x13db4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1417b
cmpq $0x0, -0x20(%rbp)
je 0x13dc5
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x13dd2
movq 0x1c21c(%rip), %rax     # 0x2ffe8
movq %rax, -0x50(%rbp)
jmp 0x13dd2
movq -0x50(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
movq -0x18(%rbp), %rdx
leaq -0x34(%rbp), %rcx
movl $0x1, %r8d
callq 0x13c80
andb $0x1, %al
movb %al, -0x35(%rbp)
cmpl $-0x1, -0x34(%rbp)
jne 0x13e1b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1417b
testb $0x1, -0x35(%rbp)
je 0x13e95
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x8550
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x8550
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x1417b
movl -0x34(%rbp), %eax
addl $0x3e8, %eax            # imm = 0x3E8
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jbe 0x13f8f
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x13f03
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
shll %ecx
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %esi
shlq $0x4, %rsi
callq 0x85b0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x13ef7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1417b
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movl -0x34(%rbp), %eax
shlq $0x4, %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
subl -0x34(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
shlq $0x4, %rdx
callq 0x8970
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x1417b
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x13fc4
movl $0x3e80, %edi           # imm = 0x3E80
callq 0x8090
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x8090
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %esi
movq -0x18(%rbp), %rdx
leaq -0x44(%rbp), %rcx
xorl %r8d, %r8d
callq 0x13c80
andb $0x1, %al
movb %al, -0x35(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x13ffa
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1417b
testb $0x1, -0x35(%rbp)
je 0x14074
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x44(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x8550
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x44(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x8550
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x44(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x44(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x1417b
movq -0x10(%rbp), %rax
cmpl $0x3e8, 0x28(%rax)      # imm = 0x3E8
jne 0x1408d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1417b
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movl -0x44(%rbp), %eax
shlq $0x4, %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
subl -0x44(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
shlq $0x4, %rdx
callq 0x8970
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x44(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x44(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
movl -0x44(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
subl -0x44(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
shlq $0x2, %rdx
callq 0x8970
movl -0x34(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x44(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
cmpl $0x3e8, 0x28(%rax)      # imm = 0x3E8
jne 0x14174
movq -0x10(%rbp), %rdi
callq 0x14190
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop