segfault in function when return table from IF (or any code branch)