// File: /workspace/github_c_makefile_star2_O0/qpfiffer[P]38-Moths/src/simple_sparsehash.c
// Function: sparse_array_group_set
static int _sparse_array_group_set(struct sparse_array_group *arr, const uint32_t i,
						   const void *val, const size_t vlen) {
	uint32_t offset = 0;
	void *destination = NULL;
	if (vlen > arr->elem_size)
		return 0;
	/* So what needs to happen in this function:
	 * 1. Convert the position (i) to the 'offset'
	 * 2. Check to see if this slot is already occupied (bmtest).
	 *    overwrite the old element if this is the case.
	 * 3. Otherwise, expand the array by a single element and increase
	 *    our bucket count (arr->count). Finally, OR the bit in our state
	 *    bitmap that shows this position is occupied.
	 * 4. After doing all that, create a copy of val and stick it in the right
	 *    position in our array.
	 */

	offset = position_to_offset(arr->bitmap, i);
	if (!is_position_occupied(arr->bitmap, i)) {
		const size_t to_move_siz = (arr->count - offset) * FULL_ELEM_SIZE;
		/* Reallocate the array to hold the new item */
		void *new_group = realloc(arr->group, (arr->count + 1) * FULL_ELEM_SIZE);
		if (new_group == NULL)
			return 0;

		/* Now take all of the old items and move them up a slot: */
		if (to_move_siz > 0) {
			memmove((unsigned char *)(new_group) + ((offset + 1) * FULL_ELEM_SIZE),
					(unsigned char *)(new_group) + (offset * FULL_ELEM_SIZE),
					to_move_siz);
		}

		/* Increase the bucket count because we've expanded: */
		arr->count++;
		arr->group = new_group;
		/* Remember to modify the bitmap: */
		set_position(arr->bitmap, i);
	}

	/* Copy the size into the position, fighting -pedantic the whole
	 * time.
	 */
	destination = (unsigned char *)(arr->group) + (offset * FULL_ELEM_SIZE);
	memcpy(destination, &vlen, sizeof(vlen));

	/* Here we mutate a variable because we're writing C and we don't respect
	 * anything.
	 */
	destination = (unsigned char *)destination + sizeof(vlen);
	memcpy(destination, val, vlen);

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x3900
movl $0x0, -0x4(%rbp)
jmp 0x3a4d
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movl -0x14(%rbp), %esi
callq 0x44c0
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movl -0x14(%rbp), %esi
callq 0x4550
cmpl $0x0, %eax
jne 0x39fc
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl -0x2c(%rbp), %eax
movl %eax, %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq $0x8, %rcx
imulq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x8, %rax
imulq %rax, %rsi
callq 0x3470
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x398c
movl $0x0, -0x4(%rbp)
jmp 0x3a4d
cmpq $0x0, -0x40(%rbp)
jbe 0x39d5
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq $0x8, %rcx
imulq %rcx, %rax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq $0x8, %rcx
imulq %rcx, %rax
addq %rax, %rsi
movq -0x40(%rbp), %rdx
callq 0x34d0
movq -0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movl -0x14(%rbp), %esi
callq 0x45a0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rdx
movq 0x8(%rdx), %rdx
addq $0x8, %rdx
imulq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x3370
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)