// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/kvlds/dispatch.c
// Function: dispatch_accept
struct dispatch_state *
dispatch_accept(int s, struct btree * T,
    size_t kmax, size_t vmax, double w, size_t g)
{
	struct dispatch_state * D;

	/* Allocate space for dispatcher state. */
	if ((D = malloc(sizeof(struct dispatch_state))) == NULL)
		goto err0;

	/* Initialize dispatcher. */
	D->dying = 0;
	D->readq = NULL;
	D->read_cookie = NULL;
	D->T = T;
	D->kmax = kmax;
	D->vmax = vmax;
	D->nrequests = 0;
	D->nmr_head = NULL;
	D->nmr_ip = 0;
	D->nmr_concurrency = T->poolsz / 4;
	D->mr_head = NULL;
	D->mr_reqs = 0;
	D->mr_concurrency = T->poolsz / 4;
	D->mr_inprogress = 0;
	D->mr_qlen = 0;
	D->mr_timer = NULL;
	D->mr_timer_expired = 0;
	D->mr_timeout.tv_sec = (time_t)w;
	D->mr_timeout.tv_usec = (suseconds_t)((w - (double)D->mr_timeout.tv_sec)
	    * 1000000);
	D->mr_min_batch = g;

	/**
	 * Adjust maximum # of pages touched by MRs (if necessary).  In
	 * addition to the limit of T->poolsz / 4 (as calculated above), we
	 * have 2 more limits which arise from the wire and lbs protocols.
	 * - The record of a wire packet must fit into 4 bytes.  The
	 *   packet length is defined as:
	 *       len = 16 + nblks * blklen
	 *   and we must have:
	 *       len <= UINT32_MAX
	 * - The length of the wire packet (including header and trailer) must
	 *   fit into size_t.  Using the same definition of len, we must have:
	 *       len <= SIZE_MAX - 20
	 */
	if (D->mr_concurrency > ((UINT32_MAX - 16) / D->T->pagelen))
		D->mr_concurrency = (UINT32_MAX - 16) / D->T->pagelen;
	if (D->mr_concurrency > ((SIZE_MAX - 16 - 20) / D->T->pagelen))
		D->mr_concurrency = (SIZE_MAX - 16 - 20) / D->T->pagelen;

	/* Start the periodic cleaning timer. */
	D->docleans = 0;
	if ((D->mrc_timer = events_timer_register(callback_mrc_timer, D,
	    &fivesec)) == NULL) {
		warnp("events_timer_register");
		goto err1;
	}

	/* Accept a connection. */
	if (network_accept(s, callback_accept, D) == NULL)
		goto err2;

	/* Success! */
	return (D);

err2:
	events_timer_cancel(D->mrc_timer);
err1:
	free(D);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r14
movsd %xmm0, (%rsp)
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r15
movl %edi, %ebp
movl $0xc8, %edi
callq 0x22a0
testq %rax, %rax
je 0x333a
movq %rax, %rbx
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x18(%rax)
movq %r15, 0x28(%rax)
movq %r13, 0x30(%rax)
movq %r12, 0x38(%rax)
andq $0x0, 0x40(%rax)
andq $0x0, 0x50(%rax)
movq 0x8(%r15), %rcx
shrq $0x2, %rcx
movq %rcx, 0x58(%rax)
andq $0x0, 0x60(%rax)
andq $0x0, 0x70(%rax)
movq %rcx, 0x78(%rax)
andl $0x0, 0x80(%rax)
movsd (%rsp), %xmm1
cvttsd2si %xmm1, %rax
andl $0x0, 0x98(%rbx)
movupd %xmm0, 0x88(%rbx)
cvtsi2sd %rax, %xmm0
movq %rax, 0xa0(%rbx)
subsd %xmm0, %xmm1
mulsd 0xe1b3(%rip), %xmm1     # 0x11420
cvttsd2si %xmm1, %rax
movq %rax, 0xa8(%rbx)
movq %r14, 0xb0(%rbx)
movq (%r15), %rsi
movl $0xffffffef, %eax       # imm = 0xFFFFFFEF
xorl %edx, %edx
divq %rsi
cmpq %rax, %rcx
setbe %dil
cmovaeq %rax, %rcx
pushq $-0x25
popq %rax
xorl %edx, %edx
divq %rsi
cmpq %rax, %rcx
setbe %dl
testb %dl, %dil
jne 0x32b6
cmpq %rax, %rcx
cmovbq %rcx, %rax
movq %rax, 0x78(%rbx)
andl $0x0, 0xc0(%rbx)
leaq 0x8a(%rip), %rdi        # 0x334e
leaq 0xe15d(%rip), %rdx      # 0x11428
movq %rbx, %rsi
callq 0xaa98
movq %rax, 0xb8(%rbx)
testq %rax, %rax
je 0x3303
leaq 0xc1(%rip), %rsi        # 0x33a7
movl %ebp, %edi
movq %rbx, %rdx
callq 0xb5a4
testq %rax, %rax
jne 0x333c
movq 0xb8(%rbx), %rdi
callq 0xac0b
jmp 0x3332
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3324
movq %rax, %r14
leaq 0xe121(%rip), %rdi      # 0x11438
xorl %eax, %eax
callq 0xdf55
andl $0x0, (%r14)
jmp 0x3332
leaq 0xe10d(%rip), %rdi      # 0x11438
xorl %eax, %eax
callq 0xe0e4
movq %rbx, %rdi
callq 0x2040
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq