// File: /workspace/github_c_makefile_star2_O3/sharpyfox[P]citrusleaf-client/tests/key_c/src/key.c
// Function: delete_fn
void *
delete_fn(void *udata)
{	
	delete_work *work = (delete_work *) udata;
	uint32_t delay_factor = 0;

	if (g_config.verbose) fprintf(stderr, "delete worker thread: n_deletes %d start_key %d \n",work->n_deletes, work->start_key);

	for (uint i=0;i<work->n_deletes;i++) {

		key_value *kv = make_key_value(work->start_key + i, work->key_len, work->value_len);

		// Create a key for accessing
		cl_object o_key;
		if (g_config.key_type == CL_STR) {
			citrusleaf_object_init_str(&o_key,kv->key_str);
		}
		else if (g_config.key_type == CL_INT) {
			citrusleaf_object_init_int(&o_key,kv->key_int);
		}
		else {
			if (!g_config.silent) fprintf(stderr, " read thread: unsupport key type %d\n",g_config.key_type);
		}


#ifdef PRINT_KEY
		cf_digest d;
		citrusleaf_calculate_digest(g_config.table, &o_key, &d);
		fprintf(stderr, "set: key %d digest %"PRIx64"\n",(int)kv->key_int, *(uint64_t *)&d);
#endif

		// Set write parameters
		cl_write_parameters cl_wp;
		cl_write_parameters_set_default(&cl_wp);
		cl_wp.timeout_ms = g_config.timeout;
		cl_wp.record_ttl = g_config.record_ttl + (g_config.ttl_range != 0 ? rand_64() % g_config.ttl_range : 0);

		cl_rv rv;
		uint64_t start_time = cf_getms();
		if (CITRUSLEAF_OK != (rv = citrusleaf_delete(work->asc, g_config.ns, g_config.table, &o_key, &cl_wp))) {
			uint64_t stop_time = cf_getms();
			uint64_t diff = safe_delta_ms(start_time, stop_time);

			if (rv == CITRUSLEAF_FAIL_TIMEOUT || rv == CITRUSLEAF_FAIL_SERVERSIDE_TIMEOUT) {
				histogram_insert_data_point(g_p_delete_timeout_histogram, diff);

				if (!g_config.silent) {
					fprintf(stderr, "citrusleaf delete timeout %d %"PRIu64" %d\n",rv,diff,cl_wp.timeout_ms);
				}
			}
			else {
				if (!g_config.silent) {
					cf_digest d;
					citrusleaf_calculate_digest(g_config.table, &o_key, &d);
					fprintf(stderr, "citrusleaf delete failed %d %"PRIx64"\n",rv,*(uint64_t *)&d);
				}
			}

			if ((rv == CITRUSLEAF_FAIL_GENERATION) ||
					(rv == CITRUSLEAF_FAIL_KEY_EXISTS) ) {
				atomic_int_add(work->gen_errs, 1);			
			}
			if (g_config.continuous == false)
				return((void *)-1);
		}
		uint64_t stop_time = cf_getms();

		histogram_insert_data_point(g_p_delete_histogram,
				safe_delta_ms(start_time, stop_time));

		free(kv);
		atomic_int_add(work->completed, 1);

		if (g_config.delay) {
			if (g_config.delay >= 1000) {
				usleep( (g_config.delay - 1000) * 1000 );
			}
			else {
				if ( (delay_factor++ % (1000 - g_config.delay)) == 0) {
					usleep( 1000 );
				}
			}
		}


	}	
	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
leaq 0x1756d(%rip), %r12     # 0x1c330
movq %rdi, %r14
cmpb $0x1, 0x28(%r12)
je 0x50ce
xorl %eax, %eax
cmpl $0x0, 0x4(%r14)
je 0x50bf
leaq 0x10(%rsp), %r15
movabsq $0x431bde82d7b634db, %rbp # imm = 0x431BDE82D7B634DB
xorl %r13d, %r13d
movq $0x0, 0x20(%rsp)
movq %r14, 0x8(%rsp)
movl (%r14), %edi
movl 0x8(%r14), %esi
movl 0xc(%r14), %edx
addl %r13d, %edi
callq 0x4056
movl 0x4c(%r12), %edx
movq %rax, 0x40(%rsp)
cmpl $0x1, %edx
je 0x4e36
cmpl $0x3, %edx
jne 0x4e45
movq 0x8(%rax), %rsi
leaq 0x48(%rsp), %rdi
callq 0x5dcd
jmp 0x4e51
movq (%rax), %rsi
leaq 0x48(%rsp), %rdi
callq 0x5e14
jmp 0x4e51
cmpb $0x0, 0x29(%r12)
je 0x5085
movl 0x34(%r12), %ecx
movl 0x38(%r12), %ebx
cmpl $0x0, 0x3c(%r12)
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, 0x38(%rsp)
movl $0x0, 0x28(%rsp)
movb $0x0, 0x2c(%rsp)
movl %ecx, 0x34(%rsp)
je 0x4e96
xorl %eax, %eax
callq 0x31de
movl 0x3c(%r12), %ecx
xorl %edx, %edx
divq %rcx
jmp 0x4e98
xorl %edx, %edx
addl %ebx, %edx
movl $0x1, %edi
movq %r15, %rsi
movl %edx, 0x38(%rsp)
callq 0x2200
movq %rbp, %rax
imulq $0x3e8, 0x10(%rsp), %r14 # imm = 0x3E8
movq 0x10(%r12), %rsi
leaq 0x48(%rsp), %rcx
leaq 0x28(%rsp), %r8
mulq 0x18(%rsp)
movq 0x8(%rsp), %rax
shrq $0x12, %rdx
movq 0x28(%rax), %rdi
addq %rdx, %r14
movq 0x18(%r12), %rdx
callq 0x79e2
movq %r15, %rbx
testl %eax, %eax
je 0x4fb2
movl $0x1, %edi
movq %rbx, %rsi
movl %eax, %r15d
callq 0x2200
movq %rbp, %rax
movl $0x0, %ebx
mulq 0x18(%rsp)
imulq $0x3e8, 0x10(%rsp), %rax # imm = 0x3E8
shrq $0x12, %rdx
addq %rdx, %rax
subq %r14, %rax
cmovaeq %rax, %rbx
cmpl $0x9, %r15d
je 0x4f30
cmpl $-0x2, %r15d
jne 0x4f6c
movq 0x17479(%rip), %rdi     # 0x1c3b0
movq %rbx, %rsi
callq 0x5cc2
cmpb $0x0, 0x29(%r12)
jne 0x4f78
movq 0x15092(%rip), %rax     # 0x19fe0
movl 0x34(%rsp), %r8d
leaq 0xddaa(%rip), %rsi      # 0x12d04
movl %r15d, %edx
movq %rbx, %rcx
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2390
jmp 0x4f78
cmpb $0x0, 0x29(%r12)
je 0x50a2
cmpl $0x5, %r15d
je 0x4f84
cmpl $0x3, %r15d
jne 0x4f97
movq 0x8(%rsp), %rax
movl $0x1, %esi
movq 0x20(%rax), %rdi
callq 0x304d
cmpb $0x0, 0x2b(%r12)
leaq 0x10(%rsp), %rbx
movabsq $0x431bde82d7b634db, %rbp # imm = 0x431BDE82D7B634DB
je 0x50b8
movl $0x1, %edi
movq %rbx, %rsi
callq 0x2200
movq %rbp, %rax
movq 0x173ef(%rip), %rdi     # 0x1c3b8
movl $0x0, %esi
mulq 0x18(%rsp)
imulq $0x3e8, 0x10(%rsp), %rax # imm = 0x3E8
shrq $0x12, %rdx
addq %rdx, %rax
subq %r14, %rax
cmovaeq %rax, %rsi
callq 0x5cc2
movq 0x40(%rsp), %rdi
callq 0x22a0
movq 0x8(%rsp), %r14
movl $0x1, %esi
movq 0x18(%r14), %rdi
callq 0x304d
movl 0x54(%r12), %edx
movq %rbx, %r15
testl %edx, %edx
je 0x5038
cmpl $0x3e8, %edx            # imm = 0x3E8
jb 0x5044
imull $0x3e8, %edx, %edi      # imm = 0x3E8
movabsq $0x431bde82d7b634db, %rbp # imm = 0x431BDE82D7B634DB
addl $0xfff0bdc0, %edi       # imm = 0xFFF0BDC0
jmp 0x5071
movabsq $0x431bde82d7b634db, %rbp # imm = 0x431BDE82D7B634DB
jmp 0x5076
movq 0x20(%rsp), %rax
movl $0x3e8, %esi            # imm = 0x3E8
movl $0x3e8, %edi            # imm = 0x3E8
movabsq $0x431bde82d7b634db, %rbp # imm = 0x431BDE82D7B634DB
subl %edx, %esi
xorl %edx, %edx
leal 0x1(%rax), %ecx
divl %esi
testl %edx, %edx
movl %ecx, %eax
movq %rax, 0x20(%rsp)
jne 0x5076
callq 0x2370
incl %r13d
cmpl 0x4(%r14), %r13d
jb 0x4dff
jmp 0x50b4
movq 0x14f54(%rip), %rax     # 0x19fe0
leaq 0xd8a0(%rip), %rsi      # 0x12933
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2390
jmp 0x4e51
leaq 0x48(%rsp), %rdi
movl %r15d, %esi
callq 0x2d81
jmp 0x4f78
xorl %eax, %eax
jmp 0x50bf
movq $-0x1, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x2d61
jmp 0x4dd2