#include <stdio.h>
#include <stdlib.h>
#include <tpswitch/cilk_dr.cilkh>

cilk long bin(int n) {
  cilk_begin;
  if (n == 0) cilk_return(1);
  else {
    long x, y;
    spawn_(x = spawn bin(n - 1));
    spawn_(y = spawn bin(n - 1));
    sync_;
    cilk_return(x + y);
  }
}

cilk int main(int argc, char ** argv) {
  cilk_begin;
  int n = atoi(argv[1]);
  long x;
  dr_start(0);
  spawn_(x = spawn bin(n));
  sync_;
  dr_stop();
  printf("bin(%d) = %ld\n", n, x);
  dr_dump();
  cilk_return(0);
}
