// File: /workspace/github_c_makefile_star2_O0/alexgirao[P]aimant/aimant.c
// Function: sink_flush_all_buffers
int sink_flush_all_buffers(struct sink *x, struct buffer_queue *q)
{
	int r;
	int total = 0;
	DEBUG_INFO("sink_flush_all_buffers(x=[pid=%i], q=[buffers=%i]) begin", x->sp->pid, buffer_queue_len(q));
	while (buffer_queue_len(q)) {
		int n;
		n = sink_write_from_queue(x, q);
		if (n < 0) {
			int save_errno = errno;
			assert(n == -1);
			DEBUG("sink_flush_all_buffers(x=[pid=%i]), errno=%i", x->sp->pid, save_errno);
			errno = save_errno;
			perror("sink_write_from_queue()");
			return -1;
		}
		total += n;
		if (x->got_eof) break;
		if ((r = wait_til_ready_for_write(x->fd, 5000 /* 5 secs */))) {
			int save_errno = errno;
			assert(r == -1);
			DEBUG("wait_til_ready_for_write(x->fd=%i), errno=%i", x->fd, save_errno);
			errno = save_errno;
			perror("wait_til_ready_for_write(x->fd)");
			return -1;
		}
	}
	DEBUG_INFO("sink_flush_all_buffers(x=[pid=%i,eof=%i], q=[buffers=%i]) done", x->sp->pid, x->got_eof, buffer_queue_len(q));
	return total;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3440
cmpl $0x0, %eax
je 0x3f54
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3880
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x3ea3
callq 0x2070
movl (%rax), %eax
movl %eax, -0x28(%rbp)
cmpl $-0x1, -0x24(%rbp)
jne 0x3e35
jmp 0x3e54
leaq 0xc464(%rip), %rdi      # 0x102a0
leaq 0xc219(%rip), %rsi      # 0x1005c
movl $0x209, %edx            # imm = 0x209
leaq 0xc6f0(%rip), %rcx      # 0x1053f
callq 0x21a0
jmp 0x3e56
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
movl -0x28(%rbp), %r8d
leaq 0xc1f4(%rip), %rdi      # 0x1005c
movl $0x20a, %esi            # imm = 0x20A
leaq 0xc70c(%rip), %rdx      # 0x10580
movb $0x0, %al
callq 0xdfe0
movl -0x28(%rbp), %eax
movl %eax, -0x30(%rbp)
callq 0x2070
movl -0x30(%rbp), %ecx
movl %ecx, (%rax)
leaq 0xc71b(%rip), %rdi      # 0x105ad
callq 0x2310
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3f5a
movl -0x24(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x40(%rax)
je 0x3ebb
jmp 0x3f54
movq -0x10(%rbp), %rax
movl (%rax), %edi
movl $0x1388, %esi           # imm = 0x1388
callq 0x3db0
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0x3f4f
callq 0x2070
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x1c(%rbp)
jne 0x3ee5
jmp 0x3f04
leaq 0xdc89(%rip), %rdi      # 0x11b75
leaq 0xc169(%rip), %rsi      # 0x1005c
movl $0x213, %edx            # imm = 0x213
leaq 0xc640(%rip), %rcx      # 0x1053f
callq 0x21a0
jmp 0x3f06
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movl -0x2c(%rbp), %r8d
leaq 0xc145(%rip), %rdi      # 0x1005c
movl $0x214, %esi            # imm = 0x214
leaq 0xc6a2(%rip), %rdx      # 0x105c5
movb $0x0, %al
callq 0xdfe0
movl -0x2c(%rbp), %eax
movl %eax, -0x34(%rbp)
callq 0x2070
movl -0x34(%rbp), %ecx
movl %ecx, (%rax)
leaq 0xc6b1(%rip), %rdi      # 0x105f2
callq 0x2310
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3f5a
jmp 0x3df7
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)