// File: /workspace/github_c_makefile_star2_O1/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 0x3be0
movq %rdi, %rbx
movl %esi, %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x2110
cmpl $-0x1, %eax
je 0x3c03
movl 0x1c(%rbx), %edi
leaq 0x2da(%rip), %rsi       # 0x3e67
movq %rbx, %rdx
callq 0x6ecc
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x3c19
movl 0x1c(%rbx), %edi
callq 0x6b38
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x3c5c
leaq 0x2e6(%rip), %rsi       # 0x3ea0
movq %rax, %rdi
movq %rbx, %rdx
callq 0xb9bd
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x3c89
movl $0x0, 0x18(%rbx)
xorl %ebx, %ebx
jmp 0x3d30
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3c44
movq %rax, %rbx
leaq 0xd86c(%rip), %rdi      # 0x11460
xorl %eax, %eax
callq 0xa2f4
movl $0x0, (%rbx)
jmp 0x3c52
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3c80
movq %rax, %r14
leaq 0xd864(%rip), %rdi      # 0x1147b
jmp 0x3c31
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3cad
movq %rax, %r14
leaq 0xd86e(%rip), %rdi      # 0x1149f
xorl %eax, %eax
callq 0xa2f4
movl $0x0, (%r14)
jmp 0x3ced
leaq 0xd815(%rip), %rdi      # 0x11460
xorl %eax, %eax
callq 0xa413
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x3d30
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3cbd
movq %rax, %r14
leaq 0xd850(%rip), %rdi      # 0x114c0
xorl %eax, %eax
callq 0xa2f4
movl $0x0, (%r14)
jmp 0x3ce4
leaq 0xd7f4(%rip), %rdi      # 0x1147b
jmp 0x3cb4
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3ccd
movq %rax, %r14
leaq 0xd843(%rip), %rdi      # 0x114e0
xorl %eax, %eax
callq 0xa2f4
movl $0x0, (%r14)
jmp 0x3cdb
leaq 0xd7eb(%rip), %rdi      # 0x1149f
xorl %eax, %eax
callq 0xa413
jmp 0x3ced
leaq 0xd7fc(%rip), %rdi      # 0x114c0
xorl %eax, %eax
callq 0xa413
jmp 0x3ce4
leaq 0xd80c(%rip), %rdi      # 0x114e0
xorl %eax, %eax
callq 0xa413
movq 0x28(%rbx), %rdi
callq 0x6e60
movq 0x20(%rbx), %rdi
callq 0x724b
movl 0x1c(%rbx), %edi
callq 0x2200
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x3d30
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3d22
movq %rax, %r14
leaq 0xda0a(%rip), %rdi      # 0x1171c
xorl %eax, %eax
callq 0xa2f4
movl $0x0, (%r14)
jmp 0x3d30
leaq 0xd9f3(%rip), %rdi      # 0x1171c
xorl %eax, %eax
callq 0xa413
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq