// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movsd %xmm0, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movl $0xc8, %edi
callq 0x22a0
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x3d99
jmp 0x400e
movq -0x40(%rbp), %rax
movl $0x0, (%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x70(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x80(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x88(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x90(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x98(%rax)
cvttsd2si -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0xa0(%rax)
movsd -0x30(%rbp), %xmm0
movq -0x40(%rbp), %rax
cvtsi2sdq 0xa0(%rax), %xmm1
subsd %xmm1, %xmm0
movsd 0x1a7c4(%rip), %xmm1    # 0x1e670
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0xa8(%rax)
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0xb0(%rax)
movq -0x40(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rcx
movl $0xffffffef, %eax       # imm = 0xFFFFFFEF
xorl %edx, %edx
divq (%rcx)
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jbe 0x3f16
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rcx
movl $0xffffffef, %eax       # imm = 0xFFFFFFEF
xorl %edx, %edx
divq (%rcx)
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x40(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rcx
movq $-0x25, %rax
xorl %edx, %edx
divq (%rcx)
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jbe 0x3f61
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rcx
movq $-0x25, %rax
xorl %edx, %edx
divq (%rcx)
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0xc0(%rax)
movq -0x40(%rbp), %rsi
leaq 0xa6(%rip), %rdi        # 0x4020
leaq 0x1a7bf(%rip), %rdx     # 0x1e740
callq 0x12560
movq -0x40(%rbp), %rcx
movq %rax, 0xb8(%rcx)
cmpq $0x0, %rax
jne 0x3fd0
jmp 0x3f99
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3fbe
leaq 0x1a7a6(%rip), %rdi     # 0x1e750
movb $0x0, %al
callq 0x180a0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3fcc
leaq 0x1a78b(%rip), %rdi     # 0x1e750
movb $0x0, %al
callq 0x182f0
jmp 0x3fce
jmp 0x4005
movl -0xc(%rbp), %edi
movq -0x40(%rbp), %rdx
leaq 0xe2(%rip), %rsi        # 0x40c0
callq 0x13980
cmpq $0x0, %rax
jne 0x3feb
jmp 0x3ff5
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4016
movq -0x40(%rbp), %rax
movq 0xb8(%rax), %rdi
callq 0x127a0
movq -0x40(%rbp), %rdi
callq 0x2040
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq