// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x1008, %rsp           # imm = 0x1008
movl 0x30(%rdi), %eax
testl %eax, %eax
js 0x3aed
movq %rdi, %r14
movl (%rdi), %edi
cmpl %edi, %eax
jne 0x3b0c
movq %rsi, %r15
movslq 0x28(%rsi), %rax
movq 0x18(%rsi), %rsi
addq %rax, %rsi
movslq 0x20(%r15), %rdx
subq %rax, %rdx
callq 0x2120
movq %rax, %rbx
testl %ebx, %ebx
js 0x3a25
je 0x3ace
addl %ebx, 0x28(%r15)
jmp 0x3add
callq 0x2080
cmpl $-0x1, %ebx
jne 0x3b2b
movq %rax, %r15
movl (%rax), %edi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x4, %edi
je 0x3add
cmpl $0xb, %edi
je 0x3add
cmpl $0x20, %edi
jne 0x3b69
movl 0x20(%r14), %ecx
leaq 0x7659(%rip), %rdi      # 0xb0bc
leaq 0x799f(%rip), %rdx      # 0xb409
movl $0x158, %esi            # imm = 0x158
xorl %eax, %eax
callq 0x9a2c
movl 0x38(%r14), %edi
testl %edi, %edi
js 0x3ac5
leaq -0x1020(%rbp), %rsi
movl $0xfff, %edx            # imm = 0xFFF
callq 0x2200
testl %eax, %eax
jle 0x3ac5
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movb $0x0, -0x1020(%rbp,%rax)
movl 0x20(%r14), %ecx
leaq 0x7611(%rip), %rdi      # 0xb0bc
leaq 0x796d(%rip), %rdx      # 0xb41f
leaq -0x1020(%rbp), %r8
movl $0x15e, %esi            # imm = 0x15E
xorl %eax, %eax
callq 0x9a2c
movl $0x20, (%r15)
jmp 0x3add
cmpl $0x0, 0x40(%r14)
jne 0x3b4a
movl $0x1, 0x40(%r14)
movl %ebx, %eax
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x78b4(%rip), %rdi      # 0xb3a8
leaq 0x75c1(%rip), %rsi      # 0xb0bc
leaq 0x78bd(%rip), %rcx      # 0xb3bf
movl $0x146, %edx            # imm = 0x146
callq 0x21b0
leaq 0x78db(%rip), %rdi      # 0xb3ee
leaq 0x75a2(%rip), %rsi      # 0xb0bc
leaq 0x789e(%rip), %rcx      # 0xb3bf
movl $0x147, %edx            # imm = 0x147
callq 0x21b0
leaq 0x77ce(%rip), %rdi      # 0xb300
leaq 0x7583(%rip), %rsi      # 0xb0bc
leaq 0x787f(%rip), %rcx      # 0xb3bf
movl $0x154, %edx            # imm = 0x154
callq 0x21b0
leaq 0x77e5(%rip), %rdi      # 0xb336
leaq 0x7564(%rip), %rsi      # 0xb0bc
leaq 0x7860(%rip), %rcx      # 0xb3bf
movl $0x16d, %edx            # imm = 0x16D
callq 0x21b0
movq %r15, %rsi
callq 0x24b3