+ char msg[100];
+ sprintf(msg, "Program has hit assertion in file %s at line %d\n",
+ file, line);
+ model->assert_user_bug(msg);
+ }
+}
+
+#ifndef CONFIG_DEBUG
+
+static int fd_user_out; /**< @brief File descriptor from which to read user program output */
+
+/**
+ * @brief Setup output redirecting
+ *
+ * Redirects user program's stdout to a pipe so that we can dump it
+ * selectively, when displaying bugs, etc.
+ * Also connects a file descriptor 'model_out' directly to stdout, for printing
+ * data when needed.
+ *
+ * The model-checker can selectively choose to print/hide the user program
+ * output.
+ * @see clear_program_output
+ * @see print_program_output
+ *
+ * Note that the user program's pipe has limited memory, so if a program will
+ * output much data, we will need to buffer it in user-space during execution.
+ * This also means that if ModelChecker decides not to print an execution, it
+ * should promptly clear the pipe.
+ *
+ * This function should only be called once.
+ */
+void redirect_output()
+{
+ /* Save stdout for later use */
+ model_out = dup(STDOUT_FILENO);
+ if (model_out < 0) {
+ perror("dup");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Redirect program output to a pipe */
+ int pipefd[2];
+ if (pipe(pipefd) < 0) {
+ perror("pipe");
+ exit(EXIT_FAILURE);
+ }
+ if (dup2(pipefd[1], STDOUT_FILENO) < 0) {
+ perror("dup2");
+ exit(EXIT_FAILURE);
+ }
+ close(pipefd[1]);
+
+ /* Save the "read" side of the pipe for use later */
+ if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) < 0) {
+ perror("fcntl");
+ exit(EXIT_FAILURE);