// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/s3/dispatch.c
// Function: callback_accept
static int
callback_accept(void * cookie, int s)
{
	struct dispatch_state * D = cookie;

	/* We have a socket. */
	if ((D->sconn = s) == -1) {
		warnp("Error accepting connection");
		goto err0;
	}

	/* Make the accepted connection non-blocking. */
	if (fcntl(D->sconn, F_SETFL, O_NONBLOCK) == -1) {
		warnp("Cannot make connection non-blocking");
		goto err1;
	}

	/* Create a buffered writer for the connection. */
	if ((D->writeq = netbuf_write_init(D->sconn,
	    dropconnection, D)) == NULL) {
		warnp("Cannot create packet write queue");
		goto err1;
	}

	/* Create a buffered reader for the connection. */
	if ((D->readq = netbuf_read_init(D->sconn)) == NULL) {
		warnp("Cannot create packet read queue");
		goto err2;
	}

	/* Wait for a request to arrive. */
	if ((D->read_cookie = wire_readpacket_wait(D->readq,
	    gotrequest, D)) == NULL) {
		warnp("Error reading request from connection");
		goto err3;
	}

	/* We are no longer waiting for a connection. */
	D->accepting = 0;

	/* Success! */
	return (0);

err3:
	netbuf_read_free(D->readq);
err2:
	netbuf_write_free(D->writeq);
err1:
	if (close(D->sconn))
		warnp("close");
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %esi, 0x1c(%rdi)
cmpl $-0x1, %esi
je 0x3ba0
movq %rdi, %rbx
movl %esi, %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x2110
cmpl $-0x1, %eax
je 0x3bc3
movl 0x1c(%rbx), %edi
leaq 0x2da(%rip), %rsi       # 0x3e27
movq %rbx, %rdx
callq 0x6eb4
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x3bd9
movl 0x1c(%rbx), %edi
callq 0x6b1c
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x3c1c
leaq 0x2e6(%rip), %rsi       # 0x3e60
movq %rax, %rdi
movq %rbx, %rdx
callq 0xb9ea
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x3c49
movl $0x0, 0x18(%rbx)
xorl %ebx, %ebx
jmp 0x3cf0
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3c04
movq %rax, %rbx
leaq 0xd838(%rip), %rdi      # 0x113ec
xorl %eax, %eax
callq 0xa33c
movl $0x0, (%rbx)
jmp 0x3c12
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3c40
movq %rax, %r14
leaq 0xd830(%rip), %rdi      # 0x11407
jmp 0x3bf1
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3c6d
movq %rax, %r14
leaq 0xd83a(%rip), %rdi      # 0x1142b
xorl %eax, %eax
callq 0xa33c
movl $0x0, (%r14)
jmp 0x3cad
leaq 0xd7e1(%rip), %rdi      # 0x113ec
xorl %eax, %eax
callq 0xa45b
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x3cf0
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3c7d
movq %rax, %r14
leaq 0xd81c(%rip), %rdi      # 0x1144c
xorl %eax, %eax
callq 0xa33c
movl $0x0, (%r14)
jmp 0x3ca4
leaq 0xd7c0(%rip), %rdi      # 0x11407
jmp 0x3c74
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3c8d
movq %rax, %r14
leaq 0xd80f(%rip), %rdi      # 0x1146c
xorl %eax, %eax
callq 0xa33c
movl $0x0, (%r14)
jmp 0x3c9b
leaq 0xd7b7(%rip), %rdi      # 0x1142b
xorl %eax, %eax
callq 0xa45b
jmp 0x3cad
leaq 0xd7c8(%rip), %rdi      # 0x1144c
xorl %eax, %eax
callq 0xa45b
jmp 0x3ca4
leaq 0xd7d8(%rip), %rdi      # 0x1146c
xorl %eax, %eax
callq 0xa45b
movq 0x28(%rbx), %rdi
callq 0x6e4a
movq 0x20(%rbx), %rdi
callq 0x7213
movl 0x1c(%rbx), %edi
callq 0x2200
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x3cf0
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3ce2
movq %rax, %r14
leaq 0xd9da(%rip), %rdi      # 0x116ac
xorl %eax, %eax
callq 0xa33c
movl $0x0, (%r14)
jmp 0x3cf0
leaq 0xd9c3(%rip), %rdi      # 0x116ac
xorl %eax, %eax
callq 0xa45b
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq