// File: /workspace/github_c_makefile_star2_O0/alexgirao[P]aimant/aimant.c
// Function: sink_write
int sink_write(struct sink *x, struct buffer *b)
{
	int n;

	/* since we are using non-blocking io, try to write directly
	 */
	assert(x->sp->child_fdin >= 0);
	assert(x->sp->child_fdin == x->fd);

#ifdef SIMULATE_PARTIAL_SINK_FEED
	if (b->pos == 0) {
		n = write(x->fd, b->buf->s, b->buf->len / 2);
	} else {
		n = write(x->fd, b->buf->s + b->pos, b->buf->len - b->pos);
	}
#else
	n = write(x->fd, b->buf->s + b->pos, b->buf->len - b->pos);
#endif
	if (n < 0) {
		int save_errno = errno;
		assert(n == -1);
		if (errno == EAGAIN) return -1;
		if (errno == EINTR) return -1;
		if (errno == EPIPE) {
			DEBUG("sink pid=%i got EPIPE", x->sp->pid);
			if (x->sp->child_fderr >= 0) {
				char buf[4096];
				int n;
				if ((n = read(x->sp->child_fderr, buf, sizeof(buf)-1)) > 0) {
					buf[n] = 0;
					DEBUG("sink pid=%i stderr=[%s]", x->sp->pid, buf);
				}
			}
			errno = save_errno;
			return -1;
		}
		DEBUG("write(), errno=%i", save_errno);
		errno = save_errno;
		perror("write()");
		exit(1);
	}
	if (n) {
		b->pos += n;
	} else {
		DEBUG_INFO("sink pid=%i got EOF", x->sp->pid);
		assert(x->got_eof == 0);
		x->got_eof = 1;
	}
	return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1030, %rsp           # imm = 0x1030
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jl 0x362f
jmp 0x364e
leaq 0xcd12(%rip), %rdi      # 0x10348
leaq 0xca1f(%rip), %rsi      # 0x1005c
movl $0x146, %edx            # imm = 0x146
leaq 0xcd16(%rip), %rcx      # 0x1035f
callq 0x21a0
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x365f
jmp 0x367e
leaq 0xcd28(%rip), %rdi      # 0x1038e
leaq 0xc9ef(%rip), %rsi      # 0x1005c
movl $0x147, %edx            # imm = 0x147
leaq 0xcce6(%rip), %rcx      # 0x1035f
callq 0x21a0
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movslq 0x28(%rax), %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x28(%rcx), %eax
movslq %eax, %rdx
callq 0x2110
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x381d
callq 0x2070
movl (%rax), %eax
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x1c(%rbp)
jne 0x36cc
jmp 0x36eb
leaq 0xcbcd(%rip), %rdi      # 0x102a0
leaq 0xc982(%rip), %rsi      # 0x1005c
movl $0x154, %edx            # imm = 0x154
leaq 0xcc79(%rip), %rcx      # 0x1035f
callq 0x21a0
callq 0x2070
cmpl $0xb, (%rax)
jne 0x3701
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x386e
callq 0x2070
cmpl $0x4, (%rax)
jne 0x3717
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x386e
callq 0x2070
cmpl $0x20, (%rax)
jne 0x37d2
jmp 0x3727
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
leaq 0xc927(%rip), %rdi      # 0x1005c
movl $0x158, %esi            # imm = 0x158
leaq 0xcc68(%rip), %rdx      # 0x103a9
movb $0x0, %al
callq 0xdfe0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jl 0x37b0
movq -0x10(%rbp), %rax
movl 0x38(%rax), %edi
leaq -0x1020(%rbp), %rsi
movl $0xfff, %edx            # imm = 0xFFF
callq 0x21f0
movl %eax, -0x1024(%rbp)
cmpl $0x0, %eax
jle 0x37ae
movslq -0x1024(%rbp), %rax
movb $0x0, -0x1020(%rbp,%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
leaq -0x1020(%rbp), %r8
leaq 0xc8c3(%rip), %rdi      # 0x1005c
movl $0x15e, %esi            # imm = 0x15E
leaq 0xcc1a(%rip), %rdx      # 0x103bf
movb $0x0, %al
callq 0xdfe0
jmp 0x37ae
jmp 0x37b0
movl -0x20(%rbp), %eax
movl %eax, -0x1028(%rbp)
callq 0x2070
movl -0x1028(%rbp), %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x386e
jmp 0x37d4
movl -0x20(%rbp), %ecx
leaq 0xc87e(%rip), %rdi      # 0x1005c
movl $0x164, %esi            # imm = 0x164
leaq 0xcc65(%rip), %rdx      # 0x1044f
movb $0x0, %al
callq 0xdfe0
movl -0x20(%rbp), %eax
movl %eax, -0x102c(%rbp)
callq 0x2070
movl -0x102c(%rbp), %ecx
movl %ecx, (%rax)
leaq 0xcc58(%rip), %rdi      # 0x10466
callq 0x2310
movl $0x1, %edi
callq 0x2350
cmpl $0x0, -0x1c(%rbp)
je 0x3832
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
jmp 0x3868
movq -0x10(%rbp), %rax
cmpl $0x0, 0x40(%rax)
jne 0x383e
jmp 0x385d
leaq 0xca91(%rip), %rdi      # 0x102d6
leaq 0xc810(%rip), %rsi      # 0x1005c
movl $0x16d, %edx            # imm = 0x16D
leaq 0xcb07(%rip), %rcx      # 0x1035f
callq 0x21a0
movq -0x10(%rbp), %rax
movl $0x1, 0x40(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1030, %rsp           # imm = 0x1030
popq %rbp
retq
nopw (%rax,%rax)