static int open_self_cmdline(void *cpu_env, int fd)

{

    int fd_orig = -1;

    bool word_skipped = false;



    fd_orig = open("/proc/self/cmdline", O_RDONLY);

    if (fd_orig < 0) {

        return fd_orig;

    }



    while (true) {

        ssize_t nb_read;

        char buf[128];

        char *cp_buf = buf;



        nb_read = read(fd_orig, buf, sizeof(buf));

        if (nb_read < 0) {

            int e = errno;

            fd_orig = close(fd_orig);

            errno = e;

            return -1;

        } else if (nb_read == 0) {

            break;

        }



        if (!word_skipped) {

            /* Skip the first string, which is the path to qemu-*-static

               instead of the actual command. */

            cp_buf = memchr(buf, 0, sizeof(buf));

            if (cp_buf) {

                /* Null byte found, skip one string */

                cp_buf++;

                nb_read -= cp_buf - buf;

                word_skipped = true;

            }

        }



        if (word_skipped) {

            if (write(fd, cp_buf, nb_read) != nb_read) {

                int e = errno;

                close(fd_orig);

                errno = e;

                return -1;

            }

        }

    }



    return close(fd_orig);

}

static int open_self_cmdline(void *cpu_env, int fd)

{

    int fd_orig = -1;

    bool word_skipped = false;



    fd_orig = open("/proc/self/cmdline", O_RDONLY);

    if (fd_orig < 0) {

        return fd_orig;

    }



    while (true) {

        ssize_t nb_read;

        char buf[128];

        char *cp_buf = buf;



        nb_read = read(fd_orig, buf, sizeof(buf));

        if (nb_read < 0) {

            int e = errno;

            fd_orig = close(fd_orig);

            errno = e;

            return -1;

        } else if (nb_read == 0) {

            break;

        }



        if (!word_skipped) {

            



            cp_buf = memchr(buf, 0, sizeof(buf));

            if (cp_buf) {

                

                cp_buf++;

                nb_read -= cp_buf - buf;

                word_skipped = true;

            }

        }



        if (word_skipped) {

            if (write(fd, cp_buf, nb_read) != nb_read) {

                int e = errno;

                close(fd_orig);

                errno = e;

                return -1;

            }

        }

    }



    return close(fd_orig);

}

static int FUNC_0(void *VAR_0, int VAR_1)

{

    int VAR_2 = -1;

    bool word_skipped = false;



    VAR_2 = open("/proc/self/cmdline", O_RDONLY);

    if (VAR_2 < 0) {

        return VAR_2;

    }



    while (true) {

        ssize_t nb_read;

        char VAR_3[128];

        char *VAR_4 = VAR_3;



        nb_read = read(VAR_2, VAR_3, sizeof(VAR_3));

        if (nb_read < 0) {

            int VAR_6 = errno;

            VAR_2 = close(VAR_2);

            errno = VAR_6;

            return -1;

        } else if (nb_read == 0) {

            break;

        }



        if (!word_skipped) {

            



            VAR_4 = memchr(VAR_3, 0, sizeof(VAR_3));

            if (VAR_4) {

                

                VAR_4++;

                nb_read -= VAR_4 - VAR_3;

                word_skipped = true;

            }

        }



        if (word_skipped) {

            if (write(VAR_1, VAR_4, nb_read) != nb_read) {

                int VAR_6 = errno;

                close(VAR_2);

                errno = VAR_6;

                return -1;

            }

        }

    }



    return close(VAR_2);

}

static int FUNC_0(void *VAR_0, int VAR_1)
{ int VAR_2 = -1; bool word_skipped = false; VAR_2 = open("/proc/self/cmdline", O_RDONLY); if (VAR_2 < 0) { return VAR_2; } while (true) { ssize_t nb_read; char VAR_3[128]; char *VAR_4 = VAR_3; nb_read = read(VAR_2, VAR_3, sizeof(VAR_3)); if (nb_read < 0) { int VAR_6 = errno; VAR_2 = close(VAR_2); errno = VAR_6; return -1; } else if (nb_read == 0) { break; } if (!word_skipped) { VAR_4 = memchr(VAR_3, 0, sizeof(VAR_3)); if (VAR_4) { VAR_4++; nb_read -= VAR_4 - VAR_3; word_skipped = true; } } if (word_skipped) { if (write(VAR_1, VAR_4, nb_read) != nb_read) { int VAR_6 = errno; close(VAR_2); errno = VAR_6; return -1; } } } return close(VAR_2); }