// File: /workspace/github_c_makefile_star2_O1/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
movq %rdi, %r14
leaq 0x174cf(%rip), %r13     # 0x1c330
cmpb $0x1, 0x28(%r13)
je 0x5162
xorl %eax, %eax
cmpl $0x0, 0x4(%r14)
je 0x5153
leaq 0x18(%rsp), %r15
movq $0x0, 0x10(%rsp)
xorl %ebx, %ebx
movq %r14, 0x8(%rsp)
movl (%r14), %edi
addl %ebx, %edi
movl 0x8(%r14), %esi
movl 0xc(%r14), %edx
callq 0x40c8
movl 0x4c(%r13), %edx
cmpl $0x1, %edx
movq %rax, 0x40(%rsp)
je 0x4ec3
cmpl $0x3, %edx
jne 0x4ed2
movq 0x8(%rax), %rsi
leaq 0x48(%rsp), %rdi
callq 0x5ee9
jmp 0x4edd
movq (%rax), %rsi
leaq 0x48(%rsp), %rdi
callq 0x5f30
jmp 0x4edd
cmpb $0x0, 0x29(%r13)
je 0x5119
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, 0x38(%rsp)
movl $0x0, 0x28(%rsp)
movb $0x0, 0x2c(%rsp)
movl 0x34(%r13), %eax
movl 0x38(%r13), %ebp
movl %eax, 0x34(%rsp)
cmpl $0x0, 0x3c(%r13)
je 0x4f1e
xorl %eax, %eax
callq 0x31ce
movl 0x3c(%r13), %ecx
xorl %edx, %edx
divq %rcx
jmp 0x4f20
xorl %edx, %edx
addl %ebp, %edx
movl %edx, 0x38(%rsp)
movl $0x1, %edi
movq %r15, %rsi
callq 0x2200
movabsq $0x431bde82d7b634db, %r12 # imm = 0x431BDE82D7B634DB
movq %r12, %rax
mulq 0x20(%rsp)
shrq $0x12, %rdx
imulq $0x3e8, 0x18(%rsp), %rbp # imm = 0x3E8
addq %rdx, %rbp
movq 0x28(%r14), %rdi
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
leaq 0x48(%rsp), %rcx
leaq 0x28(%rsp), %r8
callq 0x7b8d
movq %r13, %r14
testl %eax, %eax
je 0x503b
movl %eax, %r13d
movl $0x1, %edi
movq %r15, %rsi
callq 0x2200
movq %r12, %rax
mulq 0x20(%rsp)
shrq $0x12, %rdx
imulq $0x3e8, 0x18(%rsp), %rax # imm = 0x3E8
addq %rdx, %rax
subq %rbp, %rax
movl $0x0, %r12d
cmovaeq %rax, %r12
cmpl $0x9, %r13d
je 0x4fbc
cmpl $-0x2, %r13d
jne 0x4ff7
movq 0x173ed(%rip), %rdi     # 0x1c3b0
movq %r12, %rsi
callq 0x5dde
cmpb $0x0, 0x29(%r14)
jne 0x5002
movq 0x15007(%rip), %rax     # 0x19fe0
movq (%rax), %rdi
movl 0x34(%rsp), %r8d
leaq 0xdd20(%rip), %rsi      # 0x12d08
movl %r13d, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0x2390
jmp 0x5002
cmpb $0x0, 0x29(%r14)
je 0x5136
cmpl $0x5, %r13d
je 0x500e
cmpl $0x3, %r13d
jne 0x5021
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
movl $0x1, %esi
callq 0x303d
cmpb $0x0, 0x2b(%r14)
leaq 0x18(%rsp), %r15
movabsq $0x431bde82d7b634db, %r12 # imm = 0x431BDE82D7B634DB
je 0x50fc
movl $0x1, %edi
movq %r15, %rsi
callq 0x2200
movq %r12, %rax
mulq 0x20(%rsp)
shrq $0x12, %rdx
imulq $0x3e8, 0x18(%rsp), %rax # imm = 0x3E8
addq %rdx, %rax
movq 0x17351(%rip), %rdi     # 0x1c3b8
subq %rbp, %rax
movl $0x0, %esi
cmovaeq %rax, %rsi
callq 0x5dde
movq 0x40(%rsp), %rdi
callq 0x22a0
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
movl $0x1, %esi
callq 0x303d
movl 0x54(%r14), %edx
movb $0x1, %bpl
testl %edx, %edx
movq %r14, %r13
je 0x5101
cmpl $0x3e8, %edx            # imm = 0x3E8
jb 0x50c6
imull $0x3e8, %edx, %edi      # imm = 0x3E8
addl $0xfff0bdc0, %edi       # imm = 0xFFF0BDC0
movq 0x10(%rsp), %rax
movl %eax, %r15d
movq 0x8(%rsp), %r14
jmp 0x50e8
movq 0x10(%rsp), %rax
leal 0x1(%rax), %r15d
movl $0x3e8, %edi            # imm = 0x3E8
movl $0x3e8, %ecx            # imm = 0x3E8
subl %edx, %ecx
xorl %edx, %edx
divl %ecx
testl %edx, %edx
movq 0x8(%rsp), %r14
jne 0x50ed
callq 0x2370
movl %r15d, %eax
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %r15
jmp 0x5106
xorl %ebp, %ebp
movq %r14, %r13
movq 0x8(%rsp), %r14
testb %bpl, %bpl
je 0x5148
incl %ebx
cmpl 0x4(%r14), %ebx
jb 0x4e8e
jmp 0x5151
movq 0x14ec0(%rip), %rax     # 0x19fe0
movq (%rax), %rdi
leaq 0xd80d(%rip), %rsi      # 0x12937
xorl %eax, %eax
callq 0x2390
jmp 0x4edd
leaq 0x48(%rsp), %rdi
movl %r13d, %esi
callq 0x2d75
jmp 0x5002
movq $-0x1, %rax
jmp 0x5153
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x2d55
jmp 0x4e6c