// File: /workspace/github_c_makefile_star2_O0/tabemann[P]attoforth/src/runtime/inner.c
// Function: af_task_loop
void af_task_loop(af_global_t* global) {
  pthread_mutex_lock(&global->mutex);
  while(global->first_task) {
    while(global->tasks_active_count) {
      af_task_t* task = global->first_task;
      af_task_t* prev_task = NULL;
      while(task) {
	if(task->is_to_be_freed) {
	  af_task_t* old_task = task;
	  task = task->next_task;
	  if(prev_task) {
	    prev_task->next_task = task;
	  } else {
	    global->first_task = task;
	  }
	  if(global->atomic_task == old_task) {
	    global->atomic_task = NULL;
	  }
	  af_free_task(old_task);
	} else {
	  if(!global->atomic_task || global->atomic_task == task) {
	    pthread_mutex_unlock(&global->mutex);
	    pthread_mutex_lock(&global->mutex);
	    af_inner_loop(global, task);
	  }
	  prev_task = task;
	  task = task->next_task;
	}
      }
      task = global->first_task;
      prev_task = NULL;
      while(task) {
	if(task->is_to_be_freed) {
	  af_task_t* old_task = task;
	  task = task->next_task;
	  if(prev_task) {
	    prev_task->next_task = task;
	  } else {
	    global->first_task = task;
	  }
	  if(global->atomic_task == old_task) {
	    global->atomic_task = NULL;
	  }
	  af_free_task(old_task);
	} else {
	  prev_task = task;
	  task = task->next_task;
	}
      }
    }
    if(global->first_task) {
      pthread_mutex_unlock(&global->mutex);
      af_cond_wait(&global->cond);
      pthread_mutex_lock(&global->mutex);
    }
  }
  pthread_mutex_unlock(&global->mutex);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
callq 0x22d0
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x30ea
jmp 0x2f0c
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x30ae
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3008
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x2fa3
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x2f6d
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x2f78
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
cmpq -0x20(%rbp), %rax
jne 0x2f98
movq -0x8(%rbp), %rax
movq $0x0, 0x218(%rax)
movq -0x20(%rbp), %rdi
callq 0x3100
jmp 0x3003
movq -0x8(%rbp), %rax
cmpq $0x0, 0x218(%rax)
je 0x2fc2
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x2fef
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
callq 0x21e0
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
callq 0x22d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3190
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x2f2e
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x30a9
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x3090
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x305a
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x3065
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0x3085
movq -0x8(%rbp), %rax
movq $0x0, 0x218(%rax)
movq -0x28(%rbp), %rdi
callq 0x3100
jmp 0x30a4
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x301b
jmp 0x2f0c
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x30e5
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
callq 0x21e0
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
callq 0x16c70
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
callq 0x22d0
jmp 0x2efc
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
callq 0x21e0
addq $0x30, %rsp
popq %rbp
retq