#include <stdio.h>
#include <stdlib.h>

char *strdup_rec_do1(const char *str, int depth)
{
    char *res;
    if (*str)
        res = strdup_rec_do1(str + 1, depth + 1);
    else
        res = malloc(depth + 1);
    res[depth] = *str;
    return res;
}

char *strdup_rec_do(const char *str, int depth)
{
    char *res = *str ? strdup_rec_do(str + 1, depth + 1) : malloc(depth + 1);
    res[depth] = *str;
    return res;
}

char *strdup_rec(const char *str)
{
    return strdup_rec_do1(str, 0);
}

int main(int argc, char **argv)
{
    if (argc < 2) {
        fprintf(stderr, "Usage: %s <string>\n", argv[0]);
        return 1;
    }
    char *dup = strdup_rec(argv[1]);
    printf("%s\n%s\n", argv[1], dup);
    free(dup);
    return 0;
}
