// File: /workspace/github_c_makefile_star2_O2/sharpyfox[P]citrusleaf-client/tests/key_c/src/key.c
// Function: ops_fn
void *
ops_fn(void *udata)
{
	op_work *work = (op_work *) udata;
	write_work *workw = (write_work * )malloc(sizeof(write_work));
	read_work *workr = (read_work * )malloc(sizeof(read_work));

	int iteration = (int)((work->n_ops)/100);
	int residue = (work->n_ops)%100;
	uint read_start_key =  work->start_key;
	uint write_start_key = work->start_key;
	work->writeratio = my_min(100, work->writeratio);

	//writing snd reading n_ops times in a ratio writeratio : (100-writepesr100)
	for (uint i=0;i<iteration;i++) {
		for(int j=0; j<work->writeratio; j++) {
        		write_start_key = (rand_64()%work->n_keys) + work->start_key;
			//writing
			workw->completed = work->wcompleted;
			workw->gen_errs = work->gen_errs;
			workw->key_len = work->key_len;
			workw->value_len = work->value_len;
			workw->start_key = write_start_key;
			workw->value_len = work->value_len;
			workw->asc = work->asc;
			workw->id = 0;
			workw->n_writes = 1;
			write_fn(workw);
		}

		for(int j=0; j<100-work->writeratio; j++) {	
			//reading
			workr->completed = work->rcompleted;
			workr->key_len = work->key_len;
			workr->value_len = work->value_len;
			workr->start_key = read_start_key;
			workr->value_len = work->value_len;
			workr->asc = work->asc;
			workr->n_keys = work->n_keys;
			workr->id = 0;
			workr->n_reads = 1;
			read_fn(workr);
		}
	}
	//Residue
	int work_residue = (int)(residue*work->writeratio/100);

	for(int j=0; j<work_residue; j++) {
		write_start_key = (rand_64()%work->n_keys) + work->start_key;
		//working
		workw->completed = work->wcompleted;
		workw->gen_errs = work->gen_errs;
		workw->key_len = work->key_len;
		workw->value_len = work->value_len;
		workw->start_key = write_start_key;
		workw->value_len = work->value_len;
		workw->asc = work->asc;
		workw->id = 0;
		workw->n_writes = 1;
		write_fn(workw);
	}
	
	for(int j=0; j<(residue-work_residue); j++) {
		//reading
		workr->completed = work->rcompleted;
		workr->key_len = work->key_len;
		workr->value_len = work->value_len;
		workr->start_key = work->start_key;
		workr->value_len = work->value_len;
		workr->asc = work->asc;
		workr->n_keys = work->n_keys;
		workr->id = 0;
		workr->n_reads = 1;
		read_fn(workr);
	}
	free(workw);
	free(workr);
	return (0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
pushq $0x30
popq %rdi
callq 0x22f0
movq %rax, %r14
pushq $0x28
popq %rdi
callq 0x22f0
movq %rax, %r15
movl (%rbx), %ebp
movl 0x4(%rbx), %eax
pushq $0x64
popq %r13
xorl %edx, %edx
divl %r13d
movl %eax, 0x10(%rsp)
movl 0x28(%rbx), %eax
movl %edx, 0xc(%rsp)
cmpl $0x64, %eax
cmovgel %r13d, %eax
xorl %ecx, %ecx
movl %eax, 0x28(%rbx)
cmpl 0x10(%rsp), %ecx
je 0x4a83
xorl %r12d, %r12d
movl %ecx, 0x14(%rsp)
cmpl %eax, %r12d
jge 0x4a2c
xorl %eax, %eax
callq 0x2834
movl 0x8(%rbx), %ecx
xorl %edx, %edx
movq %r14, %rdi
divq %rcx
movq 0x20(%rbx), %rax
addl (%rbx), %edx
movq %rax, 0x18(%r14)
movl %edx, (%r14)
movq 0xc(%rbx), %rax
movq %rax, 0x8(%r14)
movups 0x30(%rbx), %xmm0
movups %xmm0, 0x20(%r14)
andl $0x0, 0x10(%r14)
movl $0x1, 0x4(%r14)
callq 0x42d7
movl 0x28(%rbx), %eax
incl %r12d
jmp 0x49dd
xorl %r12d, %r12d
movl %r13d, %ecx
subl %eax, %ecx
cmpl %ecx, %r12d
jge 0x4a78
movq 0x18(%rbx), %rax
movq %r15, %rdi
movq %rax, 0x18(%r15)
movl 0x10(%rbx), %eax
movl %ebp, 0x4(%r15)
movl %eax, 0x10(%r15)
movq 0x38(%rbx), %rax
movq %rax, 0x20(%r15)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%r15)
andl $0x0, 0x14(%r15)
movl $0x1, (%r15)
callq 0x32ec
movl 0x28(%rbx), %eax
incl %r12d
jmp 0x4a2f
movl 0x14(%rsp), %ecx
incl %ecx
jmp 0x49cc
imull 0xc(%rsp), %eax
movl $0x0, %ebp
cltd
idivl %r13d
testl %eax, %eax
movl %eax, %r12d
cmovgl %eax, %ebp
subl $0x1, %ebp
jb 0x4ae2
xorl %eax, %eax
callq 0x2834
movl 0x8(%rbx), %ecx
xorl %edx, %edx
movq %r14, %rdi
divq %rcx
movq 0x20(%rbx), %rax
addl (%rbx), %edx
movq %rax, 0x18(%r14)
movl %edx, (%r14)
movq 0xc(%rbx), %rax
movq %rax, 0x8(%r14)
movups 0x30(%rbx), %xmm0
movups %xmm0, 0x20(%r14)
andl $0x0, 0x10(%r14)
movl $0x1, 0x4(%r14)
callq 0x42d7
jmp 0x4a99
movl 0xc(%rsp), %eax
xorl %ebp, %ebp
subl %r12d, %eax
testl %eax, %eax
cmovgl %eax, %ebp
subl $0x1, %ebp
jb 0x4b30
movq 0x18(%rbx), %rax
movq %r15, %rdi
movq %rax, 0x18(%r15)
movl (%rbx), %eax
movl 0x10(%rbx), %ecx
movl %eax, 0x4(%r15)
movl %ecx, 0x10(%r15)
movq 0x38(%rbx), %rax
movq %rax, 0x20(%r15)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%r15)
andl $0x0, 0x14(%r15)
movl $0x1, (%r15)
callq 0x32ec
jmp 0x4af0
movq %r14, %rdi
callq 0x22a0
movq %r15, %rdi
callq 0x22a0
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq