// File: /workspace/github_c_makefile_star2_O1/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
movl $0x30, %edi
callq 0x22f0
movq %rax, %r14
movl $0x28, %edi
callq 0x22f0
movq %rax, %r15
movl (%rbx), %r12d
movl 0x4(%rbx), %eax
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
shrq $0x25, %rcx
movq %rcx, 0x10(%rsp)
imull $0x64, %ecx, %ecx
movl %eax, %edx
subl %ecx, %edx
movl %edx, 0xc(%rsp)
movl 0x28(%rbx), %ecx
cmpl $0x64, %ecx
movl $0x64, %edx
cmovgel %edx, %ecx
cmpq $0x64, %rax
movl %ecx, 0x28(%rbx)
jb 0x529a
xorl %ebp, %ebp
cmpl $0x0, 0x28(%rbx)
jle 0x5235
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x31ce
movl 0x8(%rbx), %ecx
xorl %edx, %edx
divq %rcx
addl (%rbx), %edx
movq 0x20(%rbx), %rax
movq %rax, 0x18(%r14)
movl 0xc(%rbx), %eax
movl %eax, 0x8(%r14)
movl 0x10(%rbx), %eax
movl %eax, 0xc(%r14)
movl %edx, (%r14)
movups 0x30(%rbx), %xmm0
movups %xmm0, 0x20(%r14)
movl $0x0, 0x10(%r14)
movl $0x1, 0x4(%r14)
movq %r14, %rdi
callq 0x4948
incl %r13d
cmpl 0x28(%rbx), %r13d
jl 0x51e1
cmpl $0x63, 0x28(%rbx)
jg 0x528e
xorl %r13d, %r13d
movq 0x18(%rbx), %rax
movq %rax, 0x18(%r15)
movl 0xc(%rbx), %eax
movl %eax, 0xc(%r15)
movl 0x10(%rbx), %eax
movl %eax, 0x10(%r15)
movl %r12d, 0x4(%r15)
movq 0x38(%rbx), %rax
movq %rax, 0x20(%r15)
movl 0x8(%rbx), %eax
movl %eax, 0x8(%r15)
movl $0x0, 0x14(%r15)
movl $0x1, (%r15)
movq %r15, %rdi
callq 0x3994
incl %r13d
movl $0x64, %eax
subl 0x28(%rbx), %eax
cmpl %eax, %r13d
jl 0x523e
incl %ebp
cmpl 0x10(%rsp), %ebp
jne 0x51d8
movl 0x28(%rbx), %eax
movl 0xc(%rsp), %r13d
imull %r13d, %eax
cltq
imulq $0x51eb851f, %rax, %r12 # imm = 0x51EB851F
movq %r12, %rcx
shrq $0x3f, %rcx
sarq $0x25, %r12
addl %ecx, %r12d
cmpl $0x64, %eax
jl 0x5314
movl %r12d, %ebp
xorl %eax, %eax
callq 0x31ce
movl 0x8(%rbx), %ecx
xorl %edx, %edx
divq %rcx
addl (%rbx), %edx
movq 0x20(%rbx), %rax
movq %rax, 0x18(%r14)
movl 0xc(%rbx), %eax
movl %eax, 0x8(%r14)
movl 0x10(%rbx), %eax
movl %eax, 0xc(%r14)
movl %edx, (%r14)
movups 0x30(%rbx), %xmm0
movups %xmm0, 0x20(%r14)
movl $0x0, 0x10(%r14)
movl $0x1, 0x4(%r14)
movq %r14, %rdi
callq 0x4948
decl %ebp
jne 0x52c5
subl %r12d, %r13d
jle 0x5368
xorl %ebp, %ebp
movq 0x18(%rbx), %rax
movq %rax, 0x18(%r15)
movl 0xc(%rbx), %eax
movl %eax, 0xc(%r15)
movl 0x10(%rbx), %eax
movl %eax, 0x10(%r15)
movl (%rbx), %ecx
movl %ecx, 0x4(%r15)
movl %eax, 0x10(%r15)
movq 0x38(%rbx), %rax
movq %rax, 0x20(%r15)
movl 0x8(%rbx), %eax
movl %eax, 0x8(%r15)
movl $0x0, 0x14(%r15)
movl $0x1, (%r15)
movq %r15, %rdi
callq 0x3994
incl %ebp
cmpl %r13d, %ebp
jl 0x531b
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