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

	if (g_config.verbose) fprintf(stderr, " read thread started: key_start %d nkeys %d\n",work->start_key,work->n_keys);
	
	cf_digest *digests = alloca( sizeof(cf_digest) * g_config.n_batch );
	if (!digests) return(0);
	
	key_value **kvs = alloca( sizeof(key_value *) * g_config.n_batch);
	if (!kvs) return(0);
	
	uint *key_ints = alloca( sizeof(uint) * g_config.n_batch );
	if (!key_ints) return(0);

	getmany_userdata gm_udata;
	gm_udata.digests = digests;
	gm_udata.kvs = kvs;
	gm_udata.key_ints = key_ints;
	gm_udata.batch_factor = g_config.n_batch;
	
	// copy the bin name we want to fetch
	cl_bin values[1];
	memset(values, 0, sizeof(values));
	strcpy(values[0].bin_name, g_config.bin);

	cl_rv rv;
	
	// grab an array of digests to fetch
	for (uint i=0;i<work->n_reads / g_config.n_batch;i++) {
	
		for (int j=0; j < g_config.n_batch; j++) {
		
			uint key_int = key_ints[j] = (rand_64() % work->n_keys) + work->start_key;
			key_value *kv = kvs[j] = make_key_value(key_int, work->key_len, work->value_len);
	
			// Create the key we want to read
			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);
			}
		
			cf_digest d;
			citrusleaf_calculate_digest(g_config.table, &o_key, &d);
#ifdef PRINT_KEY			
			fprintf(stderr, "get: key %d digest %"PRIx64"\n",key_int, *(uint64_t *)&d);
#endif			

			memcpy( &digests[j], &d, sizeof(cf_digest) );
			
		}
		
		// do the actual work of reading
		uint64_t start_time = cf_getms();
		if (CITRUSLEAF_OK != (rv = citrusleaf_get_many_digest(work->asc, g_config.ns, digests, g_config.n_batch, values, 1, false, batch_getmany_cb, &gm_udata))) {
            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_read_timeout_histogram, diff);

                if (!g_config.silent) {
            		fprintf(stderr, "citrusleaf get many timeout %d %"PRIu64"\n",rv,diff);
                }
        	}
        	else {
                if (!g_config.silent) {
                	fprintf(stderr, "read: failed with error %d\n",rv);
                }
        	}
			citrusleaf_object_free(&values[0].object);
			if (g_config.continuous == false) {
				for (int j = 0; j < g_config.n_batch; j++)
					free(kvs[j]);
				return((void *)-1);
			}
		}
		uint64_t stop_time = cf_getms();
		histogram_insert_data_point(g_p_read_histogram,
			safe_delta_ms(start_time, stop_time));
		
		for (int j = 0; j < g_config.n_batch; j++) {
			free(kvs[j]);
			kvs[j] = 0;
		}
		
		atomic_int_add(work->completed, g_config.n_batch);
		
		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((void *)0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
leaq 0x2074b(%rip), %rax     # 0x25330
testb $0x1, 0x28(%rax)
je 0x4c11
movq 0x1e3ee(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
leaq 0x17ce1(%rip), %rsi     # 0x1c8eb
movb $0x0, %al
callq 0x23b0
leaq 0x20718(%rip), %rax     # 0x25330
movslq 0x30(%rax), %rax
leaq (%rax,%rax,4), %rax
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x4c4d
movq $0x0, -0x8(%rbp)
jmp 0x516f
leaq 0x206dc(%rip), %rax     # 0x25330
movslq 0x30(%rax), %rax
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x4c85
movq $0x0, -0x8(%rbp)
jmp 0x516f
leaq 0x206a4(%rip), %rax     # 0x25330
movslq 0x30(%rax), %rax
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x4cbd
movq $0x0, -0x8(%rbp)
jmp 0x516f
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x20654(%rip), %rax     # 0x25330
movl 0x30(%rax), %eax
movl %eax, -0x48(%rbp)
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x2150
leaq -0xa0(%rbp), %rdi
leaq 0x2062d(%rip), %rax     # 0x25330
movq 0x20(%rax), %rsi
callq 0x2240
movl $0x0, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x120(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
leaq 0x20601(%rip), %rcx     # 0x25330
xorl %edx, %edx
divl 0x30(%rcx)
movl %eax, %ecx
movl -0x120(%rbp), %eax
cmpl %ecx, %eax
jae 0x5167
movl $0x0, -0xac(%rbp)
movl -0xac(%rbp), %eax
leaq 0x205d5(%rip), %rcx     # 0x25330
cmpl 0x30(%rcx), %eax
jge 0x4ea6
movb $0x0, %al
callq 0x2960
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
xorl %edx, %edx
divq %rcx
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
addq %rax, %rdx
movl %edx, %eax
movq -0x38(%rbp), %rcx
movslq -0xac(%rbp), %rdx
movl %eax, (%rcx,%rdx,4)
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %edi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %esi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x4140
movq -0x30(%rbp), %rcx
movslq -0xac(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
movq %rax, -0xb8(%rbp)
leaq 0x20563(%rip), %rax     # 0x25330
cmpl $0x3, 0x4c(%rax)
jne 0x4dec
movq -0xb8(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x72b0
jmp 0x4e44
leaq 0x2053d(%rip), %rax     # 0x25330
cmpl $0x1, 0x4c(%rax)
jne 0x4e11
movq -0xb8(%rbp), %rax
movq (%rax), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x7350
jmp 0x4e42
leaq 0x20518(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x4e40
movq 0x1e1bb(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
leaq 0x20501(%rip), %rax     # 0x25330
movl 0x4c(%rax), %edx
leaq 0x17adf(%rip), %rsi     # 0x1c918
movb $0x0, %al
callq 0x23b0
jmp 0x4e42
jmp 0x4e44
leaq 0x204e5(%rip), %rax     # 0x25330
movq 0x18(%rax), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0xec(%rbp), %rdx
callq 0xb360
movq -0x28(%rbp), %rax
movslq -0xac(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq -0xec(%rbp), %rcx
movq %rcx, (%rax)
movq -0xe4(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0xdc(%rbp), %ecx
movl %ecx, 0x10(%rax)
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x4d4e
callq 0x6e30
movq %rax, -0xf8(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x2046f(%rip), %rax     # 0x25330
movq 0x10(%rax), %rsi
movq -0x28(%rbp), %rdx
leaq 0x20460(%rip), %rax     # 0x25330
movl 0x30(%rax), %ecx
leaq -0xa0(%rbp), %r8
movl $0x1, %r9d
xorl %eax, %eax
leaq -0x9a9(%rip), %r10      # 0x4540
leaq -0x60(%rbp), %rax
subq $0x20, %rsp
movl $0x0, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0xf970
addq $0x20, %rsp
movl %eax, %ecx
movl %ecx, -0xa4(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
je 0x5040
callq 0x6e30
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x43b0
movq %rax, -0x108(%rbp)
cmpl $-0x2, -0xa4(%rbp)
je 0x4f55
cmpl $0x9, -0xa4(%rbp)
jne 0x4f9c
movq 0x20434(%rip), %rdi     # 0x25390
movq -0x108(%rbp), %rsi
callq 0x70d0
leaq 0x203c1(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x4f9a
movq 0x1e064(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movl -0xa4(%rbp), %edx
movq -0x108(%rbp), %rcx
leaq 0x17c3f(%rip), %rsi     # 0x1cbd2
movb $0x0, %al
callq 0x23b0
jmp 0x4fc9
leaq 0x2038d(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x4fc7
movq 0x1e030(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movl -0xa4(%rbp), %edx
leaq 0x17a0b(%rip), %rsi     # 0x1c9cb
movb $0x0, %al
callq 0x23b0
jmp 0x4fc9
leaq -0xa0(%rbp), %rdi
addq $0x20, %rdi
callq 0x74b0
leaq 0x20350(%rip), %rax     # 0x25330
movb 0x2b(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x503e
movl $0x0, -0x10c(%rbp)
movl -0x10c(%rbp), %eax
leaq 0x2032c(%rip), %rcx     # 0x25330
cmpl 0x30(%rcx), %eax
jge 0x502e
movq -0x30(%rbp), %rax
movslq -0x10c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22c0
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0x4ff7
movq $-0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x516f
jmp 0x5040
callq 0x6e30
movq %rax, -0x118(%rbp)
movq 0x20345(%rip), %rax     # 0x25398
movq %rax, -0x128(%rbp)
movq -0xf8(%rbp), %rdi
movq -0x118(%rbp), %rsi
callq 0x43b0
movq -0x128(%rbp), %rdi
movq %rax, %rsi
callq 0x70d0
movl $0x0, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
leaq 0x2029d(%rip), %rcx     # 0x25330
cmpl 0x30(%rcx), %eax
jge 0x50d0
movq -0x30(%rbp), %rax
movslq -0x11c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22c0
movq -0x30(%rbp), %rax
movslq -0x11c(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x5086
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x20251(%rip), %rax     # 0x25330
movl 0x30(%rax), %esi
callq 0x26e0
leaq 0x20242(%rip), %rax     # 0x25330
cmpl $0x0, 0x54(%rax)
je 0x5151
leaq 0x20235(%rip), %rax     # 0x25330
cmpl $0x3e8, 0x54(%rax)      # imm = 0x3E8
jb 0x5120
leaq 0x20225(%rip), %rax     # 0x25330
movl 0x54(%rax), %eax
subl $0x3e8, %eax            # imm = 0x3E8
imull $0x3e8, %eax, %edi      # imm = 0x3E8
callq 0x2390
jmp 0x514f
movl -0x1c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x1c(%rbp)
movl $0x3e8, %ecx            # imm = 0x3E8
leaq 0x201f9(%rip), %rdx     # 0x25330
subl 0x54(%rdx), %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
jne 0x514d
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x2390
jmp 0x514f
jmp 0x5151
jmp 0x5153
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x4d16
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)