// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]spiped/tests/pushbits/main.c
// Function: chain_two
static int
chain_two(void)
{
	pthread_t thread[2];
	int in[2];
	int middle[2];
	int out[2];
	const char * msg = "ping";
	size_t msglen = strlen(msg) + 1;
	char * buf;
	ssize_t r;
	int rc;

	/* Initialize output message buffer. */
	if ((buf = malloc(msglen)) == NULL) {
		warnp("malloc");
		goto err0;
	}

	/* Create socket pairs for the input, middle, and output. */
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, in)) {
		warnp("socketpair");
		goto err1;
	}
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, middle)) {
		warnp("socketpair");
		goto err1;
	}
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, out)) {
		warnp("socketpair");
		goto err1;
	}

	/* Link the pairs with pushbits. */
	if (pushbits(middle[1], out[0], &thread[1])) {
		warnp("pushbits");
		goto err1;
	}
	if (pushbits(in[1], middle[0], &thread[0])) {
		warnp("pushbits");
		goto err2;
	}

	/* Wait for thread to start. */
	millisleep(100);

	/*
	 * Send the message; this will not block because the message is
	 * small enough that it's entirely buffered within the kernel.
	 */
	if (noeintr_write(in[0], msg, msglen) != (ssize_t)msglen) {
		warnp("noeintr_write");
		goto err3;
	}

	/* Message was sent successfully; close the input. */
	if (close(in[0])) {
		warnp("close");
		goto err3;
	}

	/* Shut down the first thread. */
	if ((rc = pthread_join(thread[0], NULL)) != 0) {
		warn0("pthread_join: %s", strerror(rc));
		goto err2;
	}

	/* Read message; assume that we'll get it all at once. */
	if ((r = read(out[1], buf, msglen)) == -1) {
		warnp("read");
		goto err2;
	}
	if ((size_t)r != msglen) {
		warn0("Message is not the expected length");
		goto err2;
	}
	if (memcmp(buf, msg, msglen) != 0) {
		warn0("failed to get the (full?) message");
		goto err2;
	}

	/* Wait for the second thread to finish, then clean up. */
	if ((rc = pthread_join(thread[1], NULL)) != 0) {
		warn0("pthread_join: %s", strerror(rc));
		goto err1;
	}
	free(buf);

	/* Clean up. */
	if (close(in[1])) {
		warnp("close");
		goto err0;
	}
	if (close(middle[0])) {
		warnp("close");
		goto err0;
	}
	if (close(middle[1])) {
		warnp("close");
		goto err0;
	}
	if (close(out[0])) {
		warnp("close");
		goto err0;
	}
	if (close(out[1])) {
		warnp("close");
		goto err0;
	}


	/* Success! */
	return (0);

err3:
	if ((rc = pthread_cancel(thread[0])) != 0)
		warn0("pthread_cancel: %s", strerror(rc));
	if ((rc = pthread_join(thread[0], NULL)) != 0)
		warn0("pthread_join: %s", strerror(rc));
err2:
	if ((rc = pthread_cancel(thread[1])) != 0)
		warn0("pthread_cancel: %s", strerror(rc));
	if ((rc = pthread_join(thread[1], NULL)) != 0)
		warn0("pthread_join: %s", strerror(rc));
err1:
	free(buf);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
leaq 0x2ee6(%rip), %rax      # 0x6235
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x20f0
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x21e0
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
jne 0x33b3
jmp 0x3379
callq 0x2080
cmpl $0x0, (%rax)
je 0x339e
leaq 0x2eb0(%rip), %rdi      # 0x623a
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x33ac
leaq 0x2e95(%rip), %rdi      # 0x623a
movb $0x0, %al
callq 0x5090
jmp 0x33ae
jmp 0x39a6
leaq -0x28(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x21b0
cmpl $0x0, %eax
je 0x3406
jmp 0x33cc
callq 0x2080
cmpl $0x0, (%rax)
je 0x33f1
leaq 0x2e64(%rip), %rdi      # 0x6241
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x33ff
leaq 0x2e49(%rip), %rdi      # 0x6241
movb $0x0, %al
callq 0x5090
jmp 0x3401
jmp 0x399d
leaq -0x30(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x21b0
cmpl $0x0, %eax
je 0x3459
jmp 0x341f
callq 0x2080
cmpl $0x0, (%rax)
je 0x3444
leaq 0x2e11(%rip), %rdi      # 0x6241
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x3452
leaq 0x2df6(%rip), %rdi      # 0x6241
movb $0x0, %al
callq 0x5090
jmp 0x3454
jmp 0x399d
leaq -0x38(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x21b0
cmpl $0x0, %eax
je 0x34ac
jmp 0x3472
callq 0x2080
cmpl $0x0, (%rax)
je 0x3497
leaq 0x2dbe(%rip), %rdi      # 0x6241
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x34a5
leaq 0x2da3(%rip), %rdi      # 0x6241
movb $0x0, %al
callq 0x5090
jmp 0x34a7
jmp 0x399d
movl -0x2c(%rbp), %edi
movl -0x38(%rbp), %esi
leaq -0x20(%rbp), %rdx
addq $0x8, %rdx
callq 0x3c80
cmpl $0x0, %eax
je 0x3500
jmp 0x34c6
callq 0x2080
cmpl $0x0, (%rax)
je 0x34eb
leaq 0x2d2b(%rip), %rdi      # 0x6202
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x34f9
leaq 0x2d10(%rip), %rdi      # 0x6202
movb $0x0, %al
callq 0x5090
jmp 0x34fb
jmp 0x399d
movl -0x24(%rbp), %edi
movl -0x30(%rbp), %esi
leaq -0x20(%rbp), %rdx
callq 0x3c80
cmpl $0x0, %eax
je 0x3550
jmp 0x3516
callq 0x2080
cmpl $0x0, (%rax)
je 0x353b
leaq 0x2cdb(%rip), %rdi      # 0x6202
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x3549
leaq 0x2cc0(%rip), %rdi      # 0x6202
movb $0x0, %al
callq 0x5090
jmp 0x354b
jmp 0x3925
movl $0x64, %edi
callq 0x3c30
movl -0x28(%rbp), %edi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x4c60
cmpq -0x48(%rbp), %rax
je 0x35ac
jmp 0x3572
callq 0x2080
cmpl $0x0, (%rax)
je 0x3597
leaq 0x2cc9(%rip), %rdi      # 0x624c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x35a5
leaq 0x2cae(%rip), %rdi      # 0x624c
movb $0x0, %al
callq 0x5090
jmp 0x35a7
jmp 0x38ad
movl -0x28(%rbp), %edi
callq 0x2140
cmpl $0x0, %eax
je 0x35f5
jmp 0x35bb
callq 0x2080
cmpl $0x0, (%rax)
je 0x35e0
leaq 0x2c50(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x35ee
leaq 0x2c35(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x5090
jmp 0x35f0
jmp 0x38ad
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2290
movl %eax, -0x5c(%rbp)
cmpl $0x0, %eax
je 0x3635
jmp 0x360c
movl -0x5c(%rbp), %edi
callq 0x22b0
movq %rax, %rsi
leaq 0x2bed(%rip), %rdi      # 0x620b
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x3925
movl -0x34(%rbp), %edi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x2160
movq %rax, -0x58(%rbp)
cmpq $-0x1, %rax
jne 0x368b
jmp 0x3651
callq 0x2080
cmpl $0x0, (%rax)
je 0x3676
leaq 0x2bf8(%rip), %rdi      # 0x625a
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x3684
leaq 0x2bdd(%rip), %rdi      # 0x625a
movb $0x0, %al
callq 0x5090
jmp 0x3686
jmp 0x3925
movq -0x58(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x36b5
jmp 0x3697
leaq 0x2bc1(%rip), %rdi      # 0x625f
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x3925
movq -0x50(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x2170
cmpl $0x0, %eax
je 0x36eb
jmp 0x36cd
leaq 0x2bae(%rip), %rdi      # 0x6282
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x3925
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2290
movl %eax, -0x5c(%rbp)
cmpl $0x0, %eax
je 0x372b
jmp 0x3702
movl -0x5c(%rbp), %edi
callq 0x22b0
movq %rax, %rsi
leaq 0x2af7(%rip), %rdi      # 0x620b
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x399d
movq -0x50(%rbp), %rdi
callq 0x2030
movl -0x24(%rbp), %edi
callq 0x2140
cmpl $0x0, %eax
je 0x377d
jmp 0x3743
callq 0x2080
cmpl $0x0, (%rax)
je 0x3768
leaq 0x2ac8(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x3776
leaq 0x2aad(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x5090
jmp 0x3778
jmp 0x39a6
movl -0x30(%rbp), %edi
callq 0x2140
cmpl $0x0, %eax
je 0x37c6
jmp 0x378c
callq 0x2080
cmpl $0x0, (%rax)
je 0x37b1
leaq 0x2a7f(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x37bf
leaq 0x2a64(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x5090
jmp 0x37c1
jmp 0x39a6
movl -0x2c(%rbp), %edi
callq 0x2140
cmpl $0x0, %eax
je 0x380f
jmp 0x37d5
callq 0x2080
cmpl $0x0, (%rax)
je 0x37fa
leaq 0x2a36(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x3808
leaq 0x2a1b(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x5090
jmp 0x380a
jmp 0x39a6
movl -0x38(%rbp), %edi
callq 0x2140
cmpl $0x0, %eax
je 0x3858
jmp 0x381e
callq 0x2080
cmpl $0x0, (%rax)
je 0x3843
leaq 0x29ed(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x3851
leaq 0x29d2(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x5090
jmp 0x3853
jmp 0x39a6
movl -0x34(%rbp), %edi
callq 0x2140
cmpl $0x0, %eax
je 0x38a1
jmp 0x3867
callq 0x2080
cmpl $0x0, (%rax)
je 0x388c
leaq 0x29a4(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x389a
leaq 0x2989(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x5090
jmp 0x389c
jmp 0x39a6
movl $0x0, -0x4(%rbp)
jmp 0x39ad
movq -0x20(%rbp), %rdi
callq 0x22d0
movl %eax, -0x5c(%rbp)
cmpl $0x0, %eax
je 0x38e6
jmp 0x38c0
movl -0x5c(%rbp), %edi
callq 0x22b0
movq %rax, %rsi
leaq 0x2950(%rip), %rdi      # 0x6222
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x38e6
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2290
movl %eax, -0x5c(%rbp)
cmpl $0x0, %eax
je 0x3923
jmp 0x38fd
movl -0x5c(%rbp), %edi
callq 0x22b0
movq %rax, %rsi
leaq 0x28fc(%rip), %rdi      # 0x620b
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x3923
jmp 0x3925
movq -0x18(%rbp), %rdi
callq 0x22d0
movl %eax, -0x5c(%rbp)
cmpl $0x0, %eax
je 0x395e
jmp 0x3938
movl -0x5c(%rbp), %edi
callq 0x22b0
movq %rax, %rsi
leaq 0x28d8(%rip), %rdi      # 0x6222
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x395e
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2290
movl %eax, -0x5c(%rbp)
cmpl $0x0, %eax
je 0x399b
jmp 0x3975
movl -0x5c(%rbp), %edi
callq 0x22b0
movq %rax, %rsi
leaq 0x2884(%rip), %rdi      # 0x620b
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x399b
jmp 0x399d
movq -0x50(%rbp), %rdi
callq 0x2030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)