// File: /workspace/github_c_makefile_star2_O2/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 0x15c27(%rip), %r13     # 0x1a330
movq %rdi, %rbx
cmpb $0x1, 0x28(%r13)
je 0x495e
leaq 0x48(%rsp), %r15
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
cmpl 0x4(%rbx), %r14d
jae 0x4948
movl (%rbx), %edi
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
addl %r14d, %edi
callq 0x3983
movl 0x4c(%r13), %edx
movq %rax, 0x28(%rsp)
cmpl $0x1, %edx
je 0x4763
cmpl $0x3, %edx
jne 0x4770
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x564e
jmp 0x477b
movq (%rax), %rsi
movq %r15, %rdi
callq 0x568f
jmp 0x477b
cmpb $0x0, 0x29(%r13)
je 0x48f4
movabsq $0x200000000, %rax      # imm = 0x200000000
movl 0x34(%r13), %ecx
movl 0x38(%r13), %ebp
movq %rax, 0x20(%rsp)
andl $0x0, 0x10(%rsp)
cmpl $0x0, 0x3c(%r13)
movb $0x0, 0x14(%rsp)
movl %ecx, 0x1c(%rsp)
je 0x47b9
xorl %eax, %eax
callq 0x2834
movl 0x3c(%r13), %ecx
xorl %edx, %edx
divq %rcx
jmp 0x47bb
xorl %edx, %edx
addl %ebp, %edx
movl %edx, 0x20(%rsp)
callq 0x5408
movq 0x28(%rbx), %rdi
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
movq %r15, %rcx
leaq 0x10(%rsp), %r8
movq %rax, %r12
callq 0x70f4
testl %eax, %eax
je 0x4873
movl %eax, %ebp
callq 0x5408
subq %r12, %rax
movl $0x0, %r15d
cmovaeq %rax, %r15
cmpl $0x9, %ebp
je 0x4808
cmpl $-0x2, %ebp
jne 0x4842
movq 0x15ba1(%rip), %rdi     # 0x1a3b0
movq %r15, %rsi
callq 0x5595
cmpb $0x0, 0x29(%r13)
jne 0x484d
movq 0x137bb(%rip), %rax     # 0x17fe0
movl 0x1c(%rsp), %r8d
leaq 0xc4d3(%rip), %rsi      # 0x10d04
movl %ebp, %edx
movq %r15, %rcx
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2390
jmp 0x484d
cmpb $0x0, 0x29(%r13)
je 0x4911
cmpl $0x5, %ebp
je 0x4857
cmpl $0x3, %ebp
jne 0x4863
movq 0x20(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x26ab
cmpb $0x0, 0x2b(%r13)
leaq 0x48(%rsp), %r15
je 0x494c
callq 0x5408
movq 0x15b39(%rip), %rdi     # 0x1a3b8
subq %r12, %rax
movl $0x0, %esi
cmovaeq %rax, %rsi
callq 0x5595
movq 0x28(%rsp), %rdi
callq 0x22a0
movq 0x18(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x26ab
movl 0x54(%r13), %edx
testl %edx, %edx
je 0x48ec
cmpl $0x3e8, %edx            # imm = 0x3E8
jb 0x48c4
imull $0x3e8, %edx, %edi      # imm = 0x3E8
addl $0xfff0bdc0, %edi       # imm = 0xFFF0BDC0
jmp 0x48e7
movq 0x8(%rsp), %rax
movl $0x3e8, %esi            # imm = 0x3E8
movl $0x3e8, %edi            # imm = 0x3E8
subl %edx, %esi
xorl %edx, %edx
leal 0x1(%rax), %ecx
divl %esi
testl %edx, %edx
movl %ecx, %eax
movq %rax, 0x8(%rsp)
jne 0x48ec
callq 0x2370
incl %r14d
jmp 0x4728
movq 0x136e5(%rip), %rax     # 0x17fe0
leaq 0xc031(%rip), %rsi      # 0x10933
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2390
jmp 0x477b
movq 0x18(%r13), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x76c7
movq 0x136b5(%rip), %rax     # 0x17fe0
movq 0x30(%rsp), %rcx
leaq 0xc3f2(%rip), %rsi      # 0x10d29
movl %ebp, %edx
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2390
jmp 0x484d
xorl %eax, %eax
jmp 0x494f
pushq $-0x1
popq %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1367b(%rip), %rax     # 0x17fe0
movl (%rbx), %ecx
movl 0x4(%rbx), %edx
leaq 0xc361(%rip), %rsi      # 0x10cd2
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2390
jmp 0x4717