// File: /workspace/github_c_makefile_star2_O0/tabemann[P]attoforth/src/runtime/io.c
// Function: af_io_remove_done
void af_io_remove_done(af_io_t* io) {
  af_io_action_t* first_new_action = NULL;
  af_io_action_t* current_action = io->first_active_action;
  while(current_action) {
    af_io_action_t* next_action = current_action->next_action;
    if(current_action->is_done) {
      af_io_action_t* current_waiting_action = io->first_waiting_action;
      af_bool_t found = FALSE;
      if(current_action->type == AF_IO_TYPE_WRITE) {
	io->pending_write_count--;
      }
      if(current_action->prev_action) {
	current_action->prev_action->next_action =
	  current_action->next_action;
      } else {
	io->first_active_action = current_action->next_action;
      }
      if(current_action->next_action) {
	current_action->next_action->prev_action =
	  current_action->prev_action;
      }
      if(!current_action->to_be_destroyed) {
	current_action->prev_action = NULL;
	current_action->next_action = io->first_done_action;
	if(io->first_done_action) {
	  io->first_done_action->prev_action = current_action;
	}
	io->first_done_action = current_action;
      }
      while(current_waiting_action) {
	if(current_waiting_action->fd == current_action->fd) {
	  found = TRUE;
	  break;
	}
	current_waiting_action = current_waiting_action->next_action;
      }
      if(found) {
	if(current_waiting_action->prev_action) {
	  current_waiting_action->prev_action->next_action =
	    current_waiting_action->next_action;
	} else {
	  io->first_waiting_action = current_waiting_action->next_action;
	}
	if(current_waiting_action->next_action) {
	  current_waiting_action->next_action->prev_action =
	    current_waiting_action->prev_action;
	} else {
	  io->last_waiting_action = current_waiting_action->prev_action;
	}
	current_waiting_action->prev_action = NULL;
	current_waiting_action->next_action = io->first_active_action;
	if(current_waiting_action->next_action) {
	  current_waiting_action->next_action->prev_action =
	    current_waiting_action;
	}
	io->first_active_action = current_waiting_action;
      } else {
	io->active_action_count--;
      }
      if(current_action->task_to_wake) {
	pthread_mutex_unlock(&io->mutex);
	af_lock(io->global);
	af_wake(io->global, current_action->task_to_wake);
	if(io->handler_task) {
	  af_begin_atomic(io->global, io->handler_task);
	}
	af_unlock(io->global);
	af_cond_signal(&io->global->cond);
	pthread_mutex_lock(&io->mutex);
      } else if(io->handler_task) {
	pthread_mutex_unlock(&io->mutex);
	af_lock(io->global);
	if(io->handler_task) {
	  af_begin_atomic(io->global, io->handler_task);
	}
	af_unlock(io->global);
	af_cond_signal(&io->global->cond);
	pthread_mutex_lock(&io->mutex);
      }
      if(current_action->to_be_destroyed) {
	if(current_action->is_buffer_freeable) {
	  free(current_action->buffer);
	}
	free(current_action);
      }
    }
    current_action = next_action;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x196dd
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x78(%rax)
je 0x196d0
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x1, 0x18(%rax)
jne 0x19425
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x48(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x19444
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
jmp 0x19454
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x19471
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x194bd
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x194b1
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x68(%rax)
jmp 0x194bf
cmpq $0x0, -0x28(%rbp)
je 0x194ee
movq -0x28(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jne 0x194e0
movq $-0x1, -0x30(%rbp)
jmp 0x194ee
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x194bf
cmpq $0x0, -0x30(%rbp)
je 0x19599
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x19518
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
jmp 0x19528
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x19547
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
jmp 0x19556
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1958b
movq -0x28(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x50(%rax)
jmp 0x195a9
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x19630
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x21e0
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rsi
callq 0x3ed0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x78(%rax)
je 0x19603
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rsi
callq 0x3f20
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3350
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
addq $0x20, %rdi
callq 0x16cc0
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x22d0
jmp 0x196a2
movq -0x8(%rbp), %rax
cmpq $0x0, 0x78(%rax)
je 0x196a0
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x21e0
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x78(%rax)
je 0x19675
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rsi
callq 0x3f20
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3350
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
addq $0x20, %rdi
callq 0x16cc0
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x22d0
jmp 0x196a2
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x196ce
movq -0x18(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x196c5
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2040
movq -0x18(%rbp), %rdi
callq 0x2040
jmp 0x196d0
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x193d0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)