// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl $0x0, 0x9c(%rsp)
leaq 0x1fa6f(%rip), %rax     # 0x25330
testb $0x1, 0x28(%rax)
je 0x58f4
movq 0x1d712(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movq 0xa0(%rsp), %rax
movl 0x4(%rax), %edx
movq 0xa0(%rsp), %rax
movl (%rax), %ecx
leaq 0x173ca(%rip), %rsi     # 0x1ccb7
movb $0x0, %al
callq 0x23b0
movl $0x0, 0x98(%rsp)
movl 0x98(%rsp), %eax
movq 0xa0(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x5c64
movq 0xa0(%rsp), %rax
movl (%rax), %edi
addl 0x98(%rsp), %edi
movq 0xa0(%rsp), %rax
movl 0x8(%rax), %esi
movq 0xa0(%rsp), %rax
movl 0xc(%rax), %edx
callq 0x4140
movq %rax, 0x90(%rsp)
leaq 0x1f9de(%rip), %rax     # 0x25330
cmpl $0x3, 0x4c(%rax)
jne 0x5970
movq 0x90(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x70(%rsp), %rdi
callq 0x72b0
jmp 0x59c7
leaq 0x1f9b9(%rip), %rax     # 0x25330
cmpl $0x1, 0x4c(%rax)
jne 0x5994
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x70(%rsp), %rdi
callq 0x7350
jmp 0x59c5
leaq 0x1f995(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x59c3
movq 0x1d638(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
leaq 0x1f97e(%rip), %rax     # 0x25330
movl 0x4c(%rax), %edx
leaq 0x16f5c(%rip), %rsi     # 0x1c918
movb $0x0, %al
callq 0x23b0
jmp 0x59c5
jmp 0x59c7
leaq 0x58(%rsp), %rdi
callq 0x5810
leaq 0x1f958(%rip), %rax     # 0x25330
movl 0x34(%rax), %eax
movl %eax, 0x64(%rsp)
leaq 0x1f94a(%rip), %rax     # 0x25330
movl 0x38(%rax), %eax
movq %rax, 0x10(%rsp)
leaq 0x1f93b(%rip), %rax     # 0x25330
cmpl $0x0, 0x3c(%rax)
je 0x5a18
movb $0x0, %al
callq 0x2960
leaq 0x1f927(%rip), %rcx     # 0x25330
movl 0x3c(%rcx), %ecx
xorl %edx, %edx
divq %rcx
movq %rdx, 0x8(%rsp)
jmp 0x5a21
xorl %eax, %eax
movq %rax, 0x8(%rsp)
jmp 0x5a21
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
addq %rcx, %rax
movl %eax, 0x68(%rsp)
callq 0x6e30
movq %rax, 0x48(%rsp)
movq 0xa0(%rsp), %rax
movq 0x28(%rax), %rdi
leaq 0x1f8e1(%rip), %rax     # 0x25330
movq 0x10(%rax), %rsi
leaq 0x1f8d6(%rip), %rax     # 0x25330
movq 0x18(%rax), %rdx
leaq 0x70(%rsp), %rcx
leaq 0x58(%rsp), %r8
callq 0xa8c0
movl %eax, %ecx
movl %ecx, 0x54(%rsp)
xorl %eax, %eax
cmpl %ecx, %eax
je 0x5b87
callq 0x6e30
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x43b0
movq %rax, 0x38(%rsp)
cmpl $-0x2, 0x54(%rsp)
je 0x5aa9
cmpl $0x9, 0x54(%rsp)
jne 0x5aef
movq 0x1f900(%rip), %rdi     # 0x253b0
movq 0x38(%rsp), %rsi
callq 0x70d0
leaq 0x1f86f(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x5aed
movq 0x1d512(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movl 0x54(%rsp), %edx
movq 0x38(%rsp), %rcx
movl 0x64(%rsp), %r8d
leaq 0x17203(%rip), %rsi     # 0x1cce9
movb $0x0, %al
callq 0x23b0
jmp 0x5b39
leaq 0x1f83a(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x5b37
leaq 0x1f82d(%rip), %rax     # 0x25330
movq 0x18(%rax), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x24(%rsp), %rdx
callq 0xb360
movq 0x1d4c3(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movl 0x54(%rsp), %edx
movq 0x24(%rsp), %rcx
leaq 0x171de(%rip), %rsi     # 0x1cd0e
movb $0x0, %al
callq 0x23b0
jmp 0x5b39
cmpl $0x3, 0x54(%rsp)
je 0x5b47
cmpl $0x5, 0x54(%rsp)
jne 0x5b5d
movq 0xa0(%rsp), %rax
movq 0x20(%rax), %rdi
movl $0x1, %esi
callq 0x26e0
leaq 0x1f7cc(%rip), %rax     # 0x25330
movb 0x2b(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5b85
movq $-0x1, %rax
movq %rax, 0xb0(%rsp)
jmp 0x5c70
jmp 0x5b87
callq 0x6e30
movq %rax, 0x18(%rsp)
movq 0x1f820(%rip), %rax     # 0x253b8
movq %rax, (%rsp)
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x43b0
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x70d0
movq 0x90(%rsp), %rdi
callq 0x22c0
movq 0xa0(%rsp), %rax
movq 0x18(%rax), %rdi
movl $0x1, %esi
callq 0x26e0
leaq 0x1f74f(%rip), %rax     # 0x25330
cmpl $0x0, 0x54(%rax)
je 0x5c4c
leaq 0x1f742(%rip), %rax     # 0x25330
cmpl $0x3e8, 0x54(%rax)      # imm = 0x3E8
jb 0x5c13
leaq 0x1f732(%rip), %rax     # 0x25330
movl 0x54(%rax), %eax
subl $0x3e8, %eax            # imm = 0x3E8
imull $0x3e8, %eax, %edi      # imm = 0x3E8
callq 0x2390
jmp 0x5c4a
movl 0x9c(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x9c(%rsp)
movl $0x3e8, %ecx            # imm = 0x3E8
leaq 0x1f6fe(%rip), %rdx     # 0x25330
subl 0x54(%rdx), %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
jne 0x5c48
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x2390
jmp 0x5c4a
jmp 0x5c4c
jmp 0x5c4e
movl 0x98(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0x58ff
movq $0x0, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
addq $0xb8, %rsp
retq