text: #include "stdlib.h"
  #include "malloc.h"
  #include "stdio.h"
  #include "threading.h"
  
  int rand();
  
  int fac(int x)
  {
      int result = 1;
      while (x > 1)
      {
          result = result * x;
          x = x - 1;
      }
      return result;
  }
  
  struct tree {
      struct tree *left;
      struct tree *right;
      int value;
  };
  
  struct tree *make_tree(int depth)
  {
      if (depth == 0) {
          return 0;
      } else {
          struct tree *left = make_tree(depth - 1);
          struct tree *right = make_tree(depth - 1);
          int value = rand();
          struct tree *t = malloc(sizeof(struct tree));
          if (t == 0) abort();
          t->left = left;
          t->right = right;
          t->value = value % 2000;
          return t;
      }
  }
  
  int tree_compute_sum_facs(struct tree *tree)
  {
      if (tree == 0) {
          return 1;
      } else {
          int leftSum = tree_compute_sum_facs(tree->left);
          int rightSum = tree_compute_sum_facs(tree->right);
          int f = fac(tree->value);
          return leftSum + rightSum + f;
      }
  }
  
  struct sum_data {
      struct thread *thread;
      struct tree *tree;
      int sum;
  };
  
  void summator(struct sum_data *data)
  {
      int sum = tree_compute_sum_facs(data->tree);
      data->sum = sum;
  }
  
  struct sum_data *start_sum_thread(struct tree *tree)
  {
      struct sum_data *data = malloc(sizeof(struct sum_data));
      struct thread *t = 0;
      if (data == 0) abort();
      data->tree = tree;
      t = thread_start_joinable(summator, data);
      data->thread = t;
      return data;
  }
  
  int join_sum_thread(struct sum_data *data)
  {
      thread_join(data->thread);
      return data->sum;
  }
  
  int main()
  {
      struct tree *tree = make_tree(22);
      struct sum_data *leftData = start_sum_thread(tree->left);
      struct sum_data *rightData = start_sum_thread(tree->right);
      int sumLeft = join_sum_thread(leftData);
      int sumRight = join_sum_thread(rightData);
      int f = fac(tree->value);
      printf("%i", sumLeft + sumRight + f);
      return 0;
  }