// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]spiped/tests/pushbits/main.c
// Function: chain_one
static int
chain_one(void)
{
	pthread_t thread;
	int in[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 and output. */
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, in)) {
		warnp("socketpair");
		goto err1;
	}
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, out)) {
		warnp("socketpair");
		goto err1;
	}

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

	/* 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 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 thread to finish, then clean up. */
	if ((rc = pthread_join(thread, NULL)) != 0) {
		warn0("pthread_join: %s", strerror(rc));
		goto err1;
	}
	free(buf);

	/* Clean up. */
	if (close(in[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)
		warn0("pthread_cancel: %s", strerror(rc));
err2:
	if ((rc = pthread_join(thread, NULL)) != 0)
		warn0("pthread_join: %s", strerror(rc));
err1:
	free(buf);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
leaq 0x3376(%rip), %rax      # 0x6235
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x20f0
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x21e0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x2f23
jmp 0x2ee9
callq 0x2080
cmpl $0x0, (%rax)
je 0x2f0e
leaq 0x3340(%rip), %rdi      # 0x623a
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x2f1c
leaq 0x3325(%rip), %rdi      # 0x623a
movb $0x0, %al
callq 0x5090
jmp 0x2f1e
jmp 0x3327
leaq -0x18(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x21b0
cmpl $0x0, %eax
je 0x2f76
jmp 0x2f3c
callq 0x2080
cmpl $0x0, (%rax)
je 0x2f61
leaq 0x32f4(%rip), %rdi      # 0x6241
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x2f6f
leaq 0x32d9(%rip), %rdi      # 0x6241
movb $0x0, %al
callq 0x5090
jmp 0x2f71
jmp 0x331e
leaq -0x20(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x21b0
cmpl $0x0, %eax
je 0x2fc9
jmp 0x2f8f
callq 0x2080
cmpl $0x0, (%rax)
je 0x2fb4
leaq 0x32a1(%rip), %rdi      # 0x6241
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x2fc2
leaq 0x3286(%rip), %rdi      # 0x6241
movb $0x0, %al
callq 0x5090
jmp 0x2fc4
jmp 0x331e
movl -0x14(%rbp), %edi
movl -0x20(%rbp), %esi
leaq -0x10(%rbp), %rdx
callq 0x3c80
cmpl $0x0, %eax
je 0x3019
jmp 0x2fdf
callq 0x2080
cmpl $0x0, (%rax)
je 0x3004
leaq 0x3212(%rip), %rdi      # 0x6202
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x3012
leaq 0x31f7(%rip), %rdi      # 0x6202
movb $0x0, %al
callq 0x5090
jmp 0x3014
jmp 0x331e
movl $0x64, %edi
callq 0x3c30
movl -0x18(%rbp), %edi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x4c60
cmpq -0x30(%rbp), %rax
je 0x3075
jmp 0x303b
callq 0x2080
cmpl $0x0, (%rax)
je 0x3060
leaq 0x3200(%rip), %rdi      # 0x624c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x306e
leaq 0x31e5(%rip), %rdi      # 0x624c
movb $0x0, %al
callq 0x5090
jmp 0x3070
jmp 0x32a4
movl -0x18(%rbp), %edi
callq 0x2140
cmpl $0x0, %eax
je 0x30be
jmp 0x3084
callq 0x2080
cmpl $0x0, (%rax)
je 0x30a9
leaq 0x3187(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x30b7
leaq 0x316c(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x5090
jmp 0x30b9
jmp 0x32df
movl -0x1c(%rbp), %edi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x2160
movq %rax, -0x40(%rbp)
cmpq $-0x1, %rax
jne 0x3114
jmp 0x30da
callq 0x2080
cmpl $0x0, (%rax)
je 0x30ff
leaq 0x316f(%rip), %rdi      # 0x625a
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x310d
leaq 0x3154(%rip), %rdi      # 0x625a
movb $0x0, %al
callq 0x5090
jmp 0x310f
jmp 0x32df
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x313e
jmp 0x3120
leaq 0x3138(%rip), %rdi      # 0x625f
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x32df
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x2170
cmpl $0x0, %eax
je 0x3174
jmp 0x3156
leaq 0x3125(%rip), %rdi      # 0x6282
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x32df
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2290
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
je 0x31b4
jmp 0x318b
movl -0x44(%rbp), %edi
callq 0x22b0
movq %rax, %rsi
leaq 0x306e(%rip), %rdi      # 0x620b
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x331e
movq -0x38(%rbp), %rdi
callq 0x2030
movl -0x14(%rbp), %edi
callq 0x2140
cmpl $0x0, %eax
je 0x3206
jmp 0x31cc
callq 0x2080
cmpl $0x0, (%rax)
je 0x31f1
leaq 0x303f(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x31ff
leaq 0x3024(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x5090
jmp 0x3201
jmp 0x3327
movl -0x20(%rbp), %edi
callq 0x2140
cmpl $0x0, %eax
je 0x324f
jmp 0x3215
callq 0x2080
cmpl $0x0, (%rax)
je 0x323a
leaq 0x2ff6(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x3248
leaq 0x2fdb(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x5090
jmp 0x324a
jmp 0x3327
movl -0x1c(%rbp), %edi
callq 0x2140
cmpl $0x0, %eax
je 0x3298
jmp 0x325e
callq 0x2080
cmpl $0x0, (%rax)
je 0x3283
leaq 0x2fad(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x4e40
callq 0x2080
movl $0x0, (%rax)
jmp 0x3291
leaq 0x2f92(%rip), %rdi      # 0x621c
movb $0x0, %al
callq 0x5090
jmp 0x3293
jmp 0x3327
movl $0x0, -0x4(%rbp)
jmp 0x332e
movq -0x10(%rbp), %rdi
callq 0x22d0
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
je 0x32dd
jmp 0x32b7
movl -0x44(%rbp), %edi
callq 0x22b0
movq %rax, %rsi
leaq 0x2f59(%rip), %rdi      # 0x6222
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x32dd
jmp 0x32df
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2290
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
je 0x331c
jmp 0x32f6
movl -0x44(%rbp), %edi
callq 0x22b0
movq %rax, %rsi
leaq 0x2f03(%rip), %rdi      # 0x620b
movb $0x0, %al
callq 0x5090
callq 0x2080
movl $0x0, (%rax)
jmp 0x331c
jmp 0x331e
movq -0x38(%rbp), %rdi
callq 0x2030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)